perf: ⬆️ Optimize the performance of the floating control bar

This commit is contained in:
viarotel 2024-09-16 15:33:24 +08:00
parent 790e70349a
commit a1c60ecd78
19 changed files with 31 additions and 30 deletions

View File

@ -68,12 +68,6 @@ import { ElMessage } from 'element-plus'
const themeStore = useThemeStore()
const deviceStore = useDeviceStore()
themeStore.init()
onMounted(() => {
window.electron.ipcRenderer.send('control-mounted')
})
const locale = computed(() => {
const i18nLocale = i18n.global.locale.value
@ -84,31 +78,37 @@ const locale = computed(() => {
const deviceInfo = ref({})
window.electron.ipcRenderer.on('device-change', (event, data) => {
deviceInfo.value = data
})
window.electron.ipcRenderer.on('language-change', (event, data) => {
i18n.global.locale.value = data
})
window.electron.ipcRenderer.on('theme-change', (event, data) => {
themeStore.update(data)
})
const deviceList = ref([])
function handleClose() {
window.electron.ipcRenderer.send('hide-active-window')
}
const deviceList = ref([])
async function switchDevice(e) {
e.preventDefault()
const data = await deviceStore.getList()
window.electron.ipcRenderer.invoke('open-control-device-menu', data)
window.electron.ipcRenderer.send('open-control-device-menu', data)
}
onMounted(() => {
window.electron.ipcRenderer.send('control-mounted')
themeStore.init()
window.electron.ipcRenderer.on('device-change', (event, data) => {
deviceInfo.value = data
})
window.electron.ipcRenderer.on('language-change', (event, data) => {
i18n.global.locale.value = data
})
window.electron.ipcRenderer.on('theme-change', (event, data) => {
themeStore.update(data)
})
})
</script>
<style lang="postcss">

View File

@ -2,7 +2,7 @@ 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) => {
ipcMain.on('open-control-device-menu', (event, deviceList) => {
const template = deviceList.map((item) => {
let label = item.$remark || item.$name

View File

@ -1,7 +1,7 @@
import { BrowserWindow, ipcMain, Menu } from 'electron'
export default function (controlWindow) {
ipcMain.handle('open-device-gnirehtet-menu', openDeviceGnirehtetMenu)
ipcMain.on('open-device-gnirehtet-menu', openDeviceGnirehtetMenu)
function openDeviceGnirehtetMenu(event, args = {}) {
const { options = [] } = args

View File

@ -1,7 +1,7 @@
import { BrowserWindow, ipcMain, Menu } from 'electron'
export default function (controlWindow) {
ipcMain.handle('open-device-rotation-menu', openDeviceRotationMenu)
ipcMain.on('open-device-rotation-menu', openDeviceRotationMenu)
function openDeviceRotationMenu(event, args = {}) {
const { options = [] } = args

View File

@ -1,7 +1,7 @@
import { BrowserWindow, ipcMain, Menu } from 'electron'
export default function (controlWindow) {
ipcMain.handle('open-device-volume-menu', openDeviceVolumeMenu)
ipcMain.on('open-device-volume-menu', openDeviceVolumeMenu)
function openDeviceVolumeMenu(event, args = {}) {
const { options = [] } = args

View File

@ -12,8 +12,8 @@ export function initControlWindow(mainWindow) {
icon: getLogoPath(),
width: 500,
minWidth: 500,
height: 30,
maxHeight: 30,
height: 28,
maxHeight: 28,
frame: false,
show: false,
autoHideMenuBar: true,

View File

@ -34,8 +34,8 @@ export default (mainWindow) => {
controlWindow = initControlWindow(mainWindow)
ipcMain.on('control-mounted', () => {
onControlMounted(controlWindow)
openControlWindow(controlWindow, data)
onControlMounted(controlWindow)
})
})
}

View File

@ -69,7 +69,7 @@ export default {
},
]
window.electron.ipcRenderer.invoke('open-device-gnirehtet-menu', {
window.electron.ipcRenderer.send('open-device-gnirehtet-menu', {
options,
})
},

View File

@ -82,7 +82,7 @@ export default {
const options = toRaw(this.options)
window.electron.ipcRenderer.invoke('open-device-rotation-menu', {
window.electron.ipcRenderer.send('open-device-rotation-menu', {
options,
})
},

View File

@ -1,6 +1,7 @@
<template>
<el-dropdown :disabled="loading" @command="handleCommand">
<slot :loading />
<template #dropdown>
<el-dropdown-menu>
<template v-if="!loading">

View File

@ -76,7 +76,7 @@ export default {
const options = toRaw(this.options)
window.electron.ipcRenderer.invoke('open-device-volume-menu', {
window.electron.ipcRenderer.send('open-device-volume-menu', {
options,
})
},