From 790e70349ac8b938a77cbde3560c410c8fc2a05b Mon Sep 17 00:00:00 2001 From: viarotel Date: Fri, 13 Sep 2024 19:38:29 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=F0=9F=9A=80=20Extended=20floating=20co?= =?UTF-8?q?ntrol=20bar=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- control/App.vue | 4 +- control/electron/events/devices/index.js | 24 +++++++ control/electron/events/gnirehtet/index.js | 21 ++++++ control/electron/events/index.js | 4 ++ control/electron/events/rotation/index.js | 24 +++++++ control/electron/events/volume/index.js | 21 ++++++ control/electron/main.js | 65 +++++++------------ electron/exposes/scrcpy/index.js | 4 +- jsconfig.json | 2 +- .../components/ControlBar/Gnirehtet/index.vue | 60 +++++++++++++++-- .../components/ControlBar/Rotation/index.vue | 49 ++++++++++---- .../{MirrorGroup => Synergy}/index.vue | 45 +++++++++---- .../components/ControlBar/Volume/index.vue | 50 +++++++++++--- .../Device/components/ControlBar/index.vue | 45 +++++++------ src/utils/device/index.js | 2 +- 15 files changed, 313 insertions(+), 107 deletions(-) create mode 100644 control/electron/events/devices/index.js create mode 100644 control/electron/events/gnirehtet/index.js create mode 100644 control/electron/events/index.js create mode 100644 control/electron/events/rotation/index.js create mode 100644 control/electron/events/volume/index.js rename src/components/Device/components/ControlBar/{MirrorGroup => Synergy}/index.vue (66%) diff --git a/control/App.vue b/control/App.vue index 9059f415..b53a17de 100644 --- a/control/App.vue +++ b/control/App.vue @@ -25,7 +25,7 @@ type="primary" text class="!px-2 !h-full" - icon="Switch" + icon="ArrowDown" @click="switchDevice" > {{ deviceInfo.$remark || deviceInfo.$name }} @@ -107,7 +107,7 @@ async function switchDevice(e) { const data = await deviceStore.getList() - window.electron.ipcRenderer.send('show-device-list', data) + window.electron.ipcRenderer.invoke('open-control-device-menu', data) } diff --git a/control/electron/events/devices/index.js b/control/electron/events/devices/index.js new file mode 100644 index 00000000..bac45646 --- /dev/null +++ b/control/electron/events/devices/index.js @@ -0,0 +1,24 @@ +import { BrowserWindow, ipcMain, Menu } from 'electron' +import { openControlWindow } from '$control/electron/helpers/index.js' + +export default function (controlWindow) { + ipcMain.handle('open-control-device-menu', (event, deviceList) => { + const template = deviceList.map((item) => { + let label = item.$remark || item.$name + + if (item.$wifi) { + label += ` (WIFI)` + } + + return { + label, + click: () => { + openControlWindow(controlWindow, item) + }, + } + }) + + const menu = Menu.buildFromTemplate(template) + menu.popup(BrowserWindow.fromWebContents(event.sender)) + }) +} diff --git a/control/electron/events/gnirehtet/index.js b/control/electron/events/gnirehtet/index.js new file mode 100644 index 00000000..91b5eb80 --- /dev/null +++ b/control/electron/events/gnirehtet/index.js @@ -0,0 +1,21 @@ +import { BrowserWindow, ipcMain, Menu } from 'electron' + +export default function (controlWindow) { + ipcMain.handle('open-device-gnirehtet-menu', openDeviceGnirehtetMenu) + + function openDeviceGnirehtetMenu(event, args = {}) { + const { options = [] } = args + + const template = options.map((item) => { + return { + label: item.label, + click() { + controlWindow.webContents.send(item.value) + }, + } + }) + + const menu = Menu.buildFromTemplate(template) + menu.popup(BrowserWindow.fromWebContents(event.sender)) + } +} diff --git a/control/electron/events/index.js b/control/electron/events/index.js new file mode 100644 index 00000000..63255b20 --- /dev/null +++ b/control/electron/events/index.js @@ -0,0 +1,4 @@ +export { default as devices } from './devices/index.js' +export { default as gnirehtet } from './gnirehtet/index.js' +export { default as rotation } from './rotation/index.js' +export { default as volume } from './volume/index.js' diff --git a/control/electron/events/rotation/index.js b/control/electron/events/rotation/index.js new file mode 100644 index 00000000..668a3962 --- /dev/null +++ b/control/electron/events/rotation/index.js @@ -0,0 +1,24 @@ +import { BrowserWindow, ipcMain, Menu } from 'electron' + +export default function (controlWindow) { + ipcMain.handle('open-device-rotation-menu', openDeviceRotationMenu) + + function openDeviceRotationMenu(event, args = {}) { + const { options = [] } = args + + const template = options.map((item) => { + return { + label: item.label, + click: () => { + controlWindow.webContents.send( + 'execute-device-rotation-shell', + item.value, + ) + }, + } + }) + + const menu = Menu.buildFromTemplate(template) + menu.popup(BrowserWindow.fromWebContents(event.sender)) + } +} diff --git a/control/electron/events/volume/index.js b/control/electron/events/volume/index.js new file mode 100644 index 00000000..26548fe0 --- /dev/null +++ b/control/electron/events/volume/index.js @@ -0,0 +1,21 @@ +import { BrowserWindow, ipcMain, Menu } from 'electron' + +export default function (controlWindow) { + ipcMain.handle('open-device-volume-menu', openDeviceVolumeMenu) + + function openDeviceVolumeMenu(event, args = {}) { + const { options = [] } = args + + const template = options.map((item) => { + return { + label: item.label, + click() { + controlWindow.webContents.send('execute-device-volume-shell', item.value) + }, + } + }) + + const menu = Menu.buildFromTemplate(template) + menu.popup(BrowserWindow.fromWebContents(event.sender)) + } +} diff --git a/control/electron/main.js b/control/electron/main.js index 943a0d48..283ffe0f 100644 --- a/control/electron/main.js +++ b/control/electron/main.js @@ -1,56 +1,41 @@ -import { BrowserWindow, ipcMain, Menu } from 'electron' +import { BrowserWindow, ipcMain } from 'electron' import { initControlWindow, openControlWindow } from './helpers/index.js' +import { devices, gnirehtet, rotation, volume } from './events/index.js' + +function onControlMounted(controlWindow) { + ipcMain.on('language-change', (event, data) => { + controlWindow.webContents.send('language-change', data) + }) + + ipcMain.on('theme-change', (event, data) => { + controlWindow.webContents.send('theme-change', data) + }) + + rotation(controlWindow) + devices(controlWindow) + volume(controlWindow) + gnirehtet(controlWindow) +} + export default (mainWindow) => { let controlWindow - ipcMain.on('open-control-window', (event, data) => { + ipcMain.handle('open-control-window', (event, data) => { controlWindow = BrowserWindow.getAllWindows().find( win => win.customId === 'control', ) - if (!controlWindow) { - controlWindow = initControlWindow(mainWindow) - - ipcMain.on('control-mounted', () => { - openControlWindow(controlWindow, data) - }) - - return false - } - - openControlWindow(controlWindow, data) - }) - - ipcMain.on('language-change', (event, data) => { if (controlWindow) { - controlWindow.webContents.send('language-change', data) - } - }) - - ipcMain.on('theme-change', (event, data) => { - if (controlWindow) { - controlWindow.webContents.send('theme-change', data) + openControlWindow(controlWindow, data) + return false } - }) - - ipcMain.on('show-device-list', (event, deviceList) => { - const template = deviceList.map((item) => { - let label = item.$remark || item.$name - if (item.$wifi) { - label += ` (WIFI)` - } + controlWindow = initControlWindow(mainWindow) - return { - label, - click: () => { - openControlWindow(controlWindow, item) - }, - } + ipcMain.on('control-mounted', () => { + onControlMounted(controlWindow) + openControlWindow(controlWindow, data) }) - - const menu = Menu.buildFromTemplate(template) - menu.popup(BrowserWindow.fromWebContents(event.sender)) }) } diff --git a/electron/exposes/scrcpy/index.js b/electron/exposes/scrcpy/index.js index e8a47757..9a10cd32 100644 --- a/electron/exposes/scrcpy/index.js +++ b/electron/exposes/scrcpy/index.js @@ -119,14 +119,14 @@ const record = async ( ) } -const mirrorGroup = async (serial, { open = 1, ...options } = {}) => { +const mirrorGroup = async (serial, { openNum = 1, ...options } = {}) => { const overlayDisplay = appStore.get(`scrcpy.${replaceIP(serial)}.--display-overlay`) || appStore.get('scrcpy.global.--display-overlay') || '1080x1920/320,secure' const command = `settings put global overlay_display_devices "${[ - ...Array.from({ length: open }).keys(), + ...Array.from({ length: openNum }).keys(), ] .map(() => overlayDisplay) .join(';')}"` diff --git a/jsconfig.json b/jsconfig.json index 22a7e491..93eaf924 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -10,5 +10,5 @@ } }, "exclude": ["node_modules", "dist", "dist-electron", "dist-release"], - "include": ["src", "electron"] + "include": ["src", "electron", "control"] } diff --git a/src/components/Device/components/ControlBar/Gnirehtet/index.vue b/src/components/Device/components/ControlBar/Gnirehtet/index.vue index 4881bd1a..867b9e18 100644 --- a/src/components/Device/components/ControlBar/Gnirehtet/index.vue +++ b/src/components/Device/components/ControlBar/Gnirehtet/index.vue @@ -1,6 +1,11 @@