From ef7c829af78e74ed8db223d04231927b848dead4 Mon Sep 17 00:00:00 2001 From: muwoo <2424880409@qq.com> Date: Wed, 18 Aug 2021 15:03:18 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20touchbar=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/common/listener.js | 42 ++++++++++++++++++++++++++++- src/renderer/assets/common/utils.js | 5 +++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/main/common/listener.js b/src/main/common/listener.js index a832123..0431ce5 100644 --- a/src/main/common/listener.js +++ b/src/main/common/listener.js @@ -1,9 +1,11 @@ -import {app, BrowserWindow, clipboard, globalShortcut, ipcMain, Notification, screen} from "electron"; +import {app, nativeImage, BrowserWindow, clipboard, globalShortcut, ipcMain, Notification, screen, TouchBar} from "electron"; import {exec, spawn} from "child_process"; import robot from "robotjs"; import Api from "./api"; import ioHook from 'iohook'; import {throttle, commonConst} from './utils'; +import path from 'path'; +import fs from "fs"; const browsers = require("../browsers")(); const {picker, separator, superPanel} = browsers; @@ -102,6 +104,7 @@ class Listener { this.lockScreen(); this.separate(); this.initCapture(); + this.initTouchBar(mainWindow); this.superPanel(mainWindow); this.reRegisterShortCut(mainWindow); this.changeSize(mainWindow); @@ -183,6 +186,43 @@ class Listener { } } + initTouchBar(mainWindow) { + const { TouchBarButton, TouchBarGroup, TouchBarPopover } = TouchBar; + let items = []; + 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); + + return new TouchBarButton({ + icon, + backgroundColor: '#ff9fb4', + click() { + mainWindow.webContents.send('superPanel-openPlugin', { + cmd: item.features[0].cmds.filter(cmd => typeof cmd === 'string')[0], + plugin: item, + feature: item.features, + }); + } + }) + }).filter(Boolean); + const touchBarPopover = new TouchBarPopover({ + items: new TouchBar({ + items, + }), + label: '插件', + showCloseButton: true + }) + + const touchBar = new TouchBar({ + items: [touchBarPopover] + }); + mainWindow.setTouchBar(touchBar); + }); + } + initPlugin() { ipcMain.on('optionPlugin', (e, args) => { this.optionPlugin = args; diff --git a/src/renderer/assets/common/utils.js b/src/renderer/assets/common/utils.js index 8e88449..21f112f 100644 --- a/src/renderer/assets/common/utils.js +++ b/src/renderer/assets/common/utils.js @@ -130,7 +130,10 @@ function mergePlugins(plugins) { return hasOption; }) }); - + ipcRenderer && + ipcRenderer.send('pluginInit', { + plugins: target + }); return target; } 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 2/3] =?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); }); From c149694fed92f18f558f25e5a4396ed04687cebf Mon Sep 17 00:00:00 2001 From: muwoo <2424880409@qq.com> Date: Wed, 18 Aug 2021 19:29:47 +0800 Subject: [PATCH 3/3] =?UTF-8?q?ref:=20=E5=8D=87=E7=BA=A7package.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 88405a1..9e29ab5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubick2", - "version": "0.0.3-beta.3", + "version": "0.0.3-beta.4", "author": "muwoo <2424880409@qq.com>", "description": "An electron-vue project", "license": null,