diff --git a/src/main/base/plugins.ts b/src/main/base/plugins.ts index c3d11233..7ccfcefa 100644 --- a/src/main/base/plugins.ts +++ b/src/main/base/plugins.ts @@ -44,7 +44,7 @@ export class Plugins { if (plugins[file] || plugin.name in plugins) { console.log(`[${plugin.name}] Plugin already loaded / Duplicate Class Name`); } else { - plugins[file] = new plugin(electron.app, utils.getStore()); + plugins[file] = new plugin(utils); } } }); @@ -61,7 +61,7 @@ export class Plugins { if (plugins[file] || plugin in plugins) { console.log(`[${plugin.name}] Plugin already loaded / Duplicate Class Name`); } else { - plugins[file] = new plugin(electron.app, utils.getStore()); + plugins[file] = new plugin(utils); } } else { const plugin = require(path.join(this.userPluginsPath, file)); @@ -69,7 +69,7 @@ export class Plugins { if (plugins[file] || plugin in plugins) { console.log(`[${plugin.name}] Plugin already loaded / Duplicate Class Name`); } else { - plugins[file] = new plugin(electron.app, utils.getStore()); + plugins[file] = new plugin(utils); } } } diff --git a/src/main/base/utils.ts b/src/main/base/utils.ts index 103f772f..900e0531 100644 --- a/src/main/base/utils.ts +++ b/src/main/base/utils.ts @@ -33,6 +33,14 @@ export class utils { return this.paths[name]; } + /** + * Get the app + * @returns {Electron.App} + */ + static getApp(): Electron.App { + return app; + } + /** * Fetches the i18n locale for the given language. * @param language {string} The language to fetch the locale for. diff --git a/src/main/plugins/chromecast.ts b/src/main/plugins/chromecast.ts index 4bdb6113..72ac9dcb 100644 --- a/src/main/plugins/chromecast.ts +++ b/src/main/plugins/chromecast.ts @@ -289,10 +289,9 @@ export default class ChromecastPlugin { /** * Runs on plugin load (Currently run on application start) */ - constructor(app: any, store: any) { - this._app = app; - this._store = store - + constructor(utils: { getApp: () => any; getStore: () => any; }) { + this._app = utils.getApp(); + this._store = utils.getStore() } /** diff --git a/src/main/plugins/discordrpc.ts b/src/main/plugins/discordrpc.ts index 8997770f..e7c5ef92 100644 --- a/src/main/plugins/discordrpc.ts +++ b/src/main/plugins/discordrpc.ts @@ -193,10 +193,10 @@ export default class DiscordRichPresence { /** * Runs on plugin load (Currently run on application start) */ - constructor(app: any, store: any) { - DiscordRichPresence._store = store + constructor(utils: { getStore: () => any; getApp: () => any; }) { + DiscordRichPresence._store = utils.getStore(); console.debug(`[Plugin][${this.name}] Loading Complete.`); - this._app = app; + this._app = utils.getApp(); } /** diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index 2ac0a000..b161042e 100644 --- a/src/main/plugins/lastfm.ts +++ b/src/main/plugins/lastfm.ts @@ -207,10 +207,10 @@ export default class LastFMPlugin { /** * Runs on plugin load (Currently run on application start) */ - constructor(app: any, store: any) { - this._app = app; - this._store = store - electron.app.on('second-instance', (_e: any, argv: any) => { + constructor(utils: { getApp: () => any; getStore: () => any; }) { + this._app = utils.getApp(); + this._store = utils.getStore() + utils.getApp().on('second-instance', (_e: any, argv: any) => { // Checks if first instance is authorized and if second instance has protocol args argv.forEach((value: any) => { if (value.includes('auth')) { diff --git a/src/main/plugins/menubar.ts b/src/main/plugins/menubar.ts index ea070645..259b2c2d 100644 --- a/src/main/plugins/menubar.ts +++ b/src/main/plugins/menubar.ts @@ -214,9 +214,9 @@ export default class Thumbar { /** * Runs on plugin load (Currently run on application start) */ - constructor(app: any, store: any) { - this._app = app; - this._store = store + constructor(utils: { getApp: () => any; getStore: () => any; }) { + this._app = utils.getApp(); + this._store = utils.getStore(); console.debug(`[Plugin][${this.name}] Loading Complete.`); } diff --git a/src/main/plugins/mpris.ts b/src/main/plugins/mpris.ts index a29b3524..506636f6 100644 --- a/src/main/plugins/mpris.ts +++ b/src/main/plugins/mpris.ts @@ -7,6 +7,7 @@ export default class MPRIS { */ private _win: any; private _app: any; + private static utils: any; /** * Base Plugin Details (Eventually implemented into a GUI in settings) @@ -37,10 +38,8 @@ export default class MPRIS { * @param type - pausePlay, nextTrack, PreviousTrack * @private */ - private runMediaEvent(type: string) { - if (this._win) { - this._win.webContents.executeJavaScript(`MusicKitInterop.${type}()`).catch(console.error) - } + private static runMediaEvent(type: string) { + MPRIS.utils.getWindow().webContents.executeJavaScript(`MusicKitInterop.${type}()`).catch(console.error) } /** @@ -88,7 +87,7 @@ export default class MPRIS { for (const [key, value] of Object.entries(this.mprisEvents)) { this.mpris.on(key, () => { - this.runMediaEvent(value) + MPRIS.runMediaEvent(value) }); } } @@ -113,8 +112,7 @@ export default class MPRIS { return } - this.mpris.metadata = MetaData - + this.mpris.metadata = MetaData; } /** @@ -155,8 +153,9 @@ export default class MPRIS { /** * Runs on plugin load (Currently run on application start) */ - constructor(app: any, _store: any) { - this._app = app; + constructor(utils: { getApp: () => any; }) { + MPRIS.utils = utils + this._app = utils.getApp(); console.debug(`[Plugin][${this.name}] Loading Complete.`); } @@ -176,7 +175,7 @@ export default class MPRIS { console.debug(`[Plugin][${this.name}] Stopped.`); try { this.clearState() - }catch(e) { + } catch (e) { console.error(e) } } diff --git a/src/main/plugins/thumbar.ts b/src/main/plugins/thumbar.ts index 2ba1f1a9..cc7ba952 100644 --- a/src/main/plugins/thumbar.ts +++ b/src/main/plugins/thumbar.ts @@ -94,8 +94,8 @@ export default class Thumbar { /** * Runs on plugin load (Currently run on application start) */ - constructor(app: any, _store: any) { - this._app = app; + constructor(utils: { getApp: () => any; }) { + this._app = utils.getApp(); console.debug(`[Plugin][${this.name}] Loading Complete.`); } diff --git a/src/preload/cider-preload.js b/src/preload/cider-preload.js index 6a8d2358..8f105ca8 100644 --- a/src/preload/cider-preload.js +++ b/src/preload/cider-preload.js @@ -136,17 +136,18 @@ const MusicKitInterop = { }, next: () => { - try { - app.prevButtonBackIndicator = false; - } catch (e) { } - if (MusicKit.getInstance().queue.nextPlayableItemIndex != -1 && MusicKit.getInstance().queue.nextPlayableItemIndex != null) - MusicKit.getInstance().changeToMediaAtIndex(MusicKit.getInstance().queue.nextPlayableItemIndex); - // MusicKit.getInstance().skipToNextItem().then(r => console.log(`[MusicKitInterop.next] Skipping to Next ${r}`)); + // try { + // app.prevButtonBackIndicator = false; + // } catch (e) { } + // if (MusicKit.getInstance().queue.nextPlayableItemIndex != -1 && MusicKit.getInstance().queue.nextPlayableItemIndex != null) + // MusicKit.getInstance().changeToMediaAtIndex(MusicKit.getInstance().queue.nextPlayableItemIndex); + MusicKit.getInstance().skipToNextItem().then(r => console.log(`[MusicKitInterop.next] Skipping to Next ${r}`)); }, previous: () => { - if (MusicKit.getInstance().queue.previousPlayableItemIndex != -1 && MusicKit.getInstance().queue.previousPlayableItemIndex != null) - MusicKit.getInstance().changeToMediaAtIndex(MusicKit.getInstance().queue.previousPlayableItemIndex); + // if (MusicKit.getInstance().queue.previousPlayableItemIndex != -1 && MusicKit.getInstance().queue.previousPlayableItemIndex != null) + // MusicKit.getInstance().changeToMediaAtIndex(MusicKit.getInstance().queue.previousPlayableItemIndex); + MusicKit.getInstance().skipToPreviousItem().then(r => console.log(`[MusicKitInterop.previous] Skipping to Previous ${r}`)); } }