From eb6d61ea5afd9446c76fd68aa088f1328bd86bca Mon Sep 17 00:00:00 2001 From: vapormusic Date: Wed, 19 Jan 2022 09:53:24 +0700 Subject: [PATCH] fix win context on plugins, change titlebar plugin to use object call instead of ipc --- src/main/base/plugins.ts | 2 +- src/main/base/win.ts | 9 --------- src/main/index.ts | 7 ++++--- src/main/plugins/Extras/sendSongToTitlebar.ts | 8 ++++++-- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/main/base/plugins.ts b/src/main/base/plugins.ts index 9cb5e3ee..be87e89f 100644 --- a/src/main/base/plugins.ts +++ b/src/main/base/plugins.ts @@ -42,7 +42,7 @@ export default class PluginHandler { } }); } - + console.log('loaded plugins:', JSON.stringify(plugins)) return plugins; } diff --git a/src/main/base/win.ts b/src/main/base/win.ts index b22d1a21..b7d351c0 100644 --- a/src/main/base/win.ts +++ b/src/main/base/win.ts @@ -393,15 +393,6 @@ export class Win { this.win.webContents.setZoomFactor(parseFloat(scale)); }); - - // Titlebar #147 - Implemented as plugin - electron.ipcMain.on('set-titlebar', (e, titlebar) => { - this.win.title = `${titlebar} - Cider` - }) - electron.ipcMain.on('reset-titlebar', () => { - this.win.title = `Cider` - }) - /* ********************************************************************************************* * Window Events * **********************************************************************************************/ diff --git a/src/main/index.ts b/src/main/index.ts index 8ff3ed38..16f5a160 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -11,7 +11,6 @@ import {AppEvents} from "./base/app"; import PluginHandler from "./base/plugins"; // const test = new PluginHandler(); -let win: Promise | null = null; const config = new ConfigStore(); const App = new AppEvents(config.store); const Cider = new Win(electron.app, config.store) @@ -31,8 +30,10 @@ electron.app.on('ready', () => { } electron.components.whenReady().then(() => { - win = Cider.createWindow(); - plug.callPlugins('onReady', win); + Cider.createWindow().then((win) => { + plug.callPlugins('onReady', win); + }) + }) diff --git a/src/main/plugins/Extras/sendSongToTitlebar.ts b/src/main/plugins/Extras/sendSongToTitlebar.ts index 579c8e4e..9f384268 100644 --- a/src/main/plugins/Extras/sendSongToTitlebar.ts +++ b/src/main/plugins/Extras/sendSongToTitlebar.ts @@ -11,11 +11,15 @@ export default class sendSongToTitlebar { /** * Runs on plugin load (Currently run on application start) */ + private _win: any; + private _app: any; constructor() {} /** * Runs on app ready */ - onReady(): void {} + onReady(win: any): void { + this._win = win; + } /** * Runs on app stop */ @@ -25,7 +29,7 @@ export default class sendSongToTitlebar { * @param attributes Music Attributes (attributes.state = current state) */ onPlaybackStateDidChange(attributes: any): void { - electron.ipcRenderer.send('set-titlebar', attributes.name) + this._win.setTitle(`${(attributes != null && attributes.name != null && attributes.name.length > 0) ? (attributes.name + " - ") : ''}Cider`) } /** * Runs on song change