various formatting, mpris patch, menubar patch

This commit is contained in:
Core 2022-03-11 05:51:35 +00:00
parent 900e011ad2
commit dfd3fe6271
No known key found for this signature in database
GPG key ID: FE9BF1B547F8F3C6
7 changed files with 151 additions and 132 deletions

View file

@ -58,8 +58,11 @@ export default class ChromecastPlugin {
function getLocation(headers: any) { function getLocation(headers: any) {
let location = null; let location = null;
if (headers["LOCATION"] != null ){location = headers["LOCATION"]} if (headers["LOCATION"] != null) {
else if (headers["Location"] != null ){location = headers["Location"]} location = headers["LOCATION"]
} else if (headers["Location"] != null) {
location = headers["Location"]
}
return location; return location;
} }

View file

@ -86,7 +86,9 @@ export default class DiscordRichPresence {
* Disconnects from Discord RPC * Disconnects from Discord RPC
*/ */
private disconnect() { private disconnect() {
if (!this._client) return; if (!this._client) {
return
}
this._client.destroy().then(() => { this._client.destroy().then(() => {
DiscordRichPresence._connection = false; DiscordRichPresence._connection = false;
@ -137,7 +139,13 @@ export default class DiscordRichPresence {
* @param {object} attributes * @param {object} attributes
*/ */
private updateActivity(attributes: any) { private updateActivity(attributes: any) {
if (!this._client) return; if (DiscordRichPresence._store.general.discord_rpc == 0) {
return
}
if (!this._client) {
this.connect(DiscordRichPresence._store.general.discord_rpc == 1 ? '911790844204437504' : '886578863147192350')
}
if (!DiscordRichPresence._connection) { if (!DiscordRichPresence._connection) {
this._client.clearActivity().catch((e: any) => console.error(`[DiscordRichPresence][clearActivity] ${e}`)); this._client.clearActivity().catch((e: any) => console.error(`[DiscordRichPresence][clearActivity] ${e}`));
@ -240,7 +248,8 @@ export default class DiscordRichPresence {
onPlaybackStateDidChange(attributes: object): void { onPlaybackStateDidChange(attributes: object): void {
if (!DiscordRichPresence._store.general.privateEnabled) { if (!DiscordRichPresence._store.general.privateEnabled) {
this._attributes = attributes this._attributes = attributes
this.updateActivity(attributes)} this.updateActivity(attributes)
}
} }
/** /**
@ -250,6 +259,7 @@ export default class DiscordRichPresence {
onNowPlayingItemDidChange(attributes: object): void { onNowPlayingItemDidChange(attributes: object): void {
if (!DiscordRichPresence._store.general.privateEnabled) { if (!DiscordRichPresence._store.general.privateEnabled) {
this._attributes = attributes this._attributes = attributes
this.updateActivity(attributes)} this.updateActivity(attributes)
}
} }
} }

View file

@ -271,7 +271,8 @@ export default class LastFMPlugin {
this._lastfm.cachedAttributes = false this._lastfm.cachedAttributes = false
} }
this.updateNowPlayingSong(attributes) this.updateNowPlayingSong(attributes)
this.scrobbleSong(attributes)} this.scrobbleSong(attributes)
}
} }
} }

View file

@ -35,7 +35,7 @@ export default class Thumbar {
* @private * @private
*/ */
private isMac: boolean = process.platform === 'darwin'; private isMac: boolean = process.platform === 'darwin';
private menubarTemplate: any = [ private _menuTemplate: any = [
{ {
label: app.getName(), label: app.getName(),
submenu: [ submenu: [
@ -85,11 +85,11 @@ export default class Thumbar {
...(this.isMac ? [ ...(this.isMac ? [
{type: 'separator'}, {type: 'separator'},
{role: 'front'}, {role: 'front'},
] : [
{}
]),
{role: 'close'}, {role: 'close'},
{type: 'separator'}, ] : [
{role: 'close'},
]),
{ {
label: 'Edit', label: 'Edit',
submenu: [ submenu: [
@ -232,7 +232,8 @@ export default class Thumbar {
*/ */
onReady(win: Electron.BrowserWindow): void { onReady(win: Electron.BrowserWindow): void {
this._win = win; this._win = win;
Menu.setApplicationMenu(Menu.buildFromTemplate(this.menubarTemplate)) const menu = Menu.buildFromTemplate(this._menuTemplate);
Menu.setApplicationMenu(menu)
} }
/** /**

View file

@ -58,7 +58,6 @@ export default class mpris {
/** /**
* Connects to MPRIS Service * Connects to MPRIS Service
*/ */
@mpris.linuxOnly
private static connect() { private static connect() {
const player = Player({ const player = Player({
@ -94,7 +93,6 @@ export default class mpris {
/** /**
* Update M.P.R.I.S Player Attributes * Update M.P.R.I.S Player Attributes
*/ */
@mpris.linuxOnly
private static updatePlayer(attributes: any) { private static updatePlayer(attributes: any) {
const MetaData = { const MetaData = {
@ -119,7 +117,6 @@ export default class mpris {
* @private * @private
* @param attributes * @param attributes
*/ */
@mpris.linuxOnly
private static updatePlayerState(attributes: any) { private static updatePlayerState(attributes: any) {
switch (attributes.status) { switch (attributes.status) {
case true: // Playing case true: // Playing
@ -139,6 +136,9 @@ export default class mpris {
* @private * @private
*/ */
private static clearState() { private static clearState() {
if (!mpris.player) {
return
}
mpris.player.metadata = {'mpris:trackid': '/org/mpris/MediaPlayer2/TrackList/NoTrack'} mpris.player.metadata = {'mpris:trackid': '/org/mpris/MediaPlayer2/TrackList/NoTrack'}
mpris.player.playbackStatus = Player.PLAYBACK_STATUS_STOPPED; mpris.player.playbackStatus = Player.PLAYBACK_STATUS_STOPPED;
} }
@ -160,6 +160,7 @@ export default class mpris {
/** /**
* Runs on app ready * Runs on app ready
*/ */
@mpris.linuxOnly
onReady(_: any): void { onReady(_: any): void {
console.debug(`[Plugin][${mpris.name}] Ready.`); console.debug(`[Plugin][${mpris.name}] Ready.`);
} }
@ -167,6 +168,7 @@ export default class mpris {
/** /**
* Renderer ready * Renderer ready
*/ */
@mpris.linuxOnly
onRendererReady(): void { onRendererReady(): void {
mpris.connect() mpris.connect()
} }
@ -174,19 +176,17 @@ export default class mpris {
/** /**
* Runs on app stop * Runs on app stop
*/ */
@mpris.linuxOnly
onBeforeQuit(): void { onBeforeQuit(): void {
console.debug(`[Plugin][${mpris.name}] Stopped.`); console.debug(`[Plugin][${mpris.name}] Stopped.`);
try {
mpris.clearState() mpris.clearState()
}catch(e) {
e = null
}
} }
/** /**
* Runs on playback State Change * Runs on playback State Change
* @param attributes Music Attributes (attributes.status = current state) * @param attributes Music Attributes (attributes.status = current state)
*/ */
@mpris.linuxOnly
onPlaybackStateDidChange(attributes: object): void { onPlaybackStateDidChange(attributes: object): void {
console.debug(`[Plugin][${mpris.name}] onPlaybackStateDidChange.`); console.debug(`[Plugin][${mpris.name}] onPlaybackStateDidChange.`);
mpris.updatePlayerState(attributes) mpris.updatePlayerState(attributes)
@ -196,6 +196,7 @@ export default class mpris {
* Runs on song change * Runs on song change
* @param attributes Music Attributes * @param attributes Music Attributes
*/ */
@mpris.linuxOnly
onNowPlayingItemDidChange(attributes: object): void { onNowPlayingItemDidChange(attributes: object): void {
console.debug(`[Plugin][${mpris.name}] onMetadataDidChange.`); console.debug(`[Plugin][${mpris.name}] onMetadataDidChange.`);
mpris.updatePlayer(attributes); mpris.updatePlayer(attributes);

View file

@ -47,7 +47,6 @@ export default class Thumbar {
/** /**
* Update the thumbnail toolbar * Update the thumbnail toolbar
*/ */
@Thumbar.windowsOnly
private updateButtons(attributes: any) { private updateButtons(attributes: any) {
console.log(attributes) console.log(attributes)
@ -102,6 +101,7 @@ export default class Thumbar {
/** /**
* Runs on app ready * Runs on app ready
*/ */
@Thumbar.windowsOnly
onReady(win: Electron.BrowserWindow): void { onReady(win: Electron.BrowserWindow): void {
this._win = win; this._win = win;
console.debug(`[Plugin][${this.name}] Ready.`); console.debug(`[Plugin][${this.name}] Ready.`);
@ -110,6 +110,7 @@ export default class Thumbar {
/** /**
* Runs on app stop * Runs on app stop
*/ */
@Thumbar.windowsOnly
onBeforeQuit(): void { onBeforeQuit(): void {
console.debug(`[Plugin][${this.name}] Stopped.`); console.debug(`[Plugin][${this.name}] Stopped.`);
} }
@ -118,6 +119,7 @@ export default class Thumbar {
* Runs on playback State Change * Runs on playback State Change
* @param attributes Music Attributes (attributes.status = current state) * @param attributes Music Attributes (attributes.status = current state)
*/ */
@Thumbar.windowsOnly
onPlaybackStateDidChange(attributes: object): void { onPlaybackStateDidChange(attributes: object): void {
this.updateButtons(attributes) this.updateButtons(attributes)
} }
@ -126,6 +128,7 @@ export default class Thumbar {
* Runs on song change * Runs on song change
* @param attributes Music Attributes * @param attributes Music Attributes
*/ */
@Thumbar.windowsOnly
onNowPlayingItemDidChange(attributes: object): void { onNowPlayingItemDidChange(attributes: object): void {
this.updateButtons(attributes) this.updateButtons(attributes)
} }