From 5eb72ed2ce588da1964aa0720ce4b90e153af7c3 Mon Sep 17 00:00:00 2001 From: muwoo <2424880409@qq.com> Date: Wed, 18 Aug 2021 19:28:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20touchbar=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/common/listener.js | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/common/listener.js b/src/main/common/listener.js index 0431ce5..6640d79 100644 --- a/src/main/common/listener.js +++ b/src/main/common/listener.js @@ -189,12 +189,13 @@ class Listener { initTouchBar(mainWindow) { const { TouchBarButton, TouchBarGroup, TouchBarPopover } = TouchBar; let items = []; + let system = []; ipcMain.on('pluginInit', (e, args) => { this.optionPlugin = args; items = args.plugins.map((item) => { const iconPath = path.join(item.sourceFile, '../', item.logo); if (!fs.existsSync(iconPath)) return false; - const icon = nativeImage.createFromPath(iconPath); + const icon = nativeImage.createFromPath(iconPath).resize({width: 20, height: 20}); return new TouchBarButton({ icon, @@ -203,21 +204,39 @@ class Listener { mainWindow.webContents.send('superPanel-openPlugin', { cmd: item.features[0].cmds.filter(cmd => typeof cmd === 'string')[0], plugin: item, - feature: item.features, + feature: item.features[0], }); } }) }).filter(Boolean); - const touchBarPopover = new TouchBarPopover({ + + system = args.plugins.map((item) => { + if(item.type === 'system') { + return new TouchBarButton({ + icon: nativeImage.createFromDataURL(item.logo).resize({width: 20, height: 20}), + backgroundColor: '#ff9fb4', + click() { + mainWindow.webContents.send('superPanel-openPlugin', { + cmd: item.features[0].cmds.filter(cmd => typeof cmd === 'string')[0], + plugin: item, + feature: item.features[0], + }); + } + }); + } + return false; + }).filter(Boolean); + + const plugin = new TouchBarPopover({ items: new TouchBar({ items, }), - label: '插件', + label: '已安装插件', showCloseButton: true - }) + }); const touchBar = new TouchBar({ - items: [touchBarPopover] + items: [plugin, ...system] }); mainWindow.setTouchBar(touchBar); });