From 4b13f5892bf2b1197fdb460ab4b88ccd60eeabd1 Mon Sep 17 00:00:00 2001 From: viarotel Date: Fri, 27 Oct 2023 19:18:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=9A=80=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20=E6=B7=B1=E8=89=B2=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E3=80=81=E5=9B=BD=E9=99=85=E5=8C=96=E8=AF=AD=E8=A8=80=E3=80=81?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=97=A5=E5=BF=97=E7=AD=89=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 26 +- README-CN.md | 2 +- electron/events/handles/index.js | 13 +- electron/events/handles/theme/index.js | 26 ++ electron/events/tray/index.js | 23 +- electron/events/updater/index.js | 4 +- electron/exposes/adbkit/index.js | 2 +- electron/exposes/index.js | 4 +- electron/helpers/console.js | 13 +- electron/helpers/index.js | 12 + electron/main.js | 13 +- index.html | 2 +- src/App.vue | 9 +- src/components/About/index.vue | 4 +- src/components/Device/ControlBar/index.vue | 76 +++-- src/components/Device/PairDialog/index.vue | 36 ++- src/components/Device/Remark/index.vue | 6 +- src/components/Device/index.vue | 8 +- .../Preference/LanguageSelect/index.vue | 53 ++++ src/components/Preference/index.vue | 120 ++++--- src/locales/index.js | 7 +- src/locales/languages/en_US.json | 193 +++++++++++- src/locales/languages/zh_CN.json | 93 +++--- src/main.js | 5 +- src/plugins/element-plus/index.js | 1 + src/plugins/element-plus/restyle.css | 17 +- src/store/index.js | 4 +- src/store/preference/helpers/index.js | 43 +-- src/store/preference/index.js | 71 ++--- src/store/preference/model/audio/index.js | 30 +- src/store/preference/model/common/index.js | 123 +++++--- src/store/preference/model/device/index.js | 88 +++--- src/store/preference/model/record/index.js | 42 ++- src/store/preference/model/video/index.js | 293 +++++++++--------- src/store/preference/model/window/index.js | 65 ++-- src/store/theme/index.js | 63 ++++ src/styles/css/desktop.css | 7 +- src/utils/console.js | 12 +- 38 files changed, 1056 insertions(+), 553 deletions(-) create mode 100644 electron/events/handles/theme/index.js create mode 100644 src/components/Preference/LanguageSelect/index.vue create mode 100644 src/store/theme/index.js diff --git a/.vscode/settings.json b/.vscode/settings.json index 5a1e6c7..338d9be 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -29,17 +29,31 @@ "[json]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, - "i18n-ally.localesPaths": [ - "src/locales/index.js", - "src/locales/languages" - ], - "i18n-ally.sourceLanguage": "zh", + "i18n-ally.localesPaths": ["src/locales/index.js", "src/locales/languages"], + "i18n-ally.sourceLanguage": "en", "i18n-ally.keystyle": "nested", "i18n-ally.extract.ignored": [ + "Switch", "${item.id}(${item.$name}${\r\n item.$remark ? `,${item.$remark}` : ''\r\n })", ",${item.$remark}", "${row.$remark ? `${row.$remark}-` : ''}${\r\n row.$name\r\n }-${this.$replaceIP(row.id)}-recording-${dayjs().format(\r\n 'YYYY-MM-DD-HH-mm-ss',\r\n )}.${recordFormat}", "--serial=${row.id} --window-title=${\r\n row.$remark ? `${row.$remark}-` : ''\r\n }${row.$name}-${\r\n row.id\r\n }-🎥录制中... --record=${savePath} ${this.scrcpyArgs(row.id)}", - "--serial=${row.id} --window-title=${\r\n row.$remark ? `${row.$remark}-` : ''\r\n }${row.$name}-${row.id} ${this.scrcpyArgs(row.id)}" + "--serial=${row.id} --window-title=${\r\n row.$remark ? `${row.$remark}-` : ''\r\n }${row.$name}-${row.id} ${this.scrcpyArgs(row.id)}", + "${device.$remark ? `${device.$remark}-` : ''}${\r\n device.$name\r\n }-${this.$replaceIP(device.id)}-screencap-${dayjs().format(\r\n 'YYYY-MM-DD-HH-mm-ss',\r\n )}.png", + "input keyevent KEYCODE_APP_SWITCH", + "input keyevent KEYCODE_HOME", + "input keyevent KEYCODE_BACK", + "Back", + "Notification", + "cmd statusbar expand-notifications", + "input keyevent KEYCODE_POWER", + "Crop", + "&", + "\r\n {{\r\n loading ", + "& percent\r\n ? `${$t(\"about.update.progress\")}...(${percent.toFixed(1)}%)`\r\n : $t(\"about.update\")\r\n }}\r\n ", + "\r\n Supported by\r\n\r\n ", + "Viarotel", + "\r\n\r\n v{{ version }}\r\n ", + "pair ${this.formData.host}:${this.formData.port} ${this.formData.pair}" ] } diff --git a/README-CN.md b/README-CN.md index 3335d97..25a8fc6 100644 --- a/README-CN.md +++ b/README-CN.md @@ -133,7 +133,7 @@ 7. 定制化,支持对单个设备进行独立配置 ✅ 8. 添加 macOS 及 linux 操作系统的支持 ✅ 9. 支持国际化 ✅ -10. 对深色模式的支持 🚧 +10. 对深色模式的支持 ✅ 11. 添加对游戏的增强功能,如游戏键位映射 🚧 ## 常见问题 diff --git a/electron/events/handles/index.js b/electron/events/handles/index.js index 08547dc..6af2f4e 100644 --- a/electron/events/handles/index.js +++ b/electron/events/handles/index.js @@ -1,7 +1,10 @@ import fs from 'fs-extra' import { dialog, ipcMain, shell } from 'electron' +import themeHandles from './theme/index.js' + +export default (mainWindow) => { + themeHandles(mainWindow) -export default () => { ipcMain.handle( 'show-open-dialog', async (event, { preset = '', ...options } = {}) => { @@ -11,11 +14,11 @@ export default () => { .catch(e => console.warn(e)) if (res.canceled) { - throw new Error('用户取消操作') + throw new Error('User cancel operation') } if (!res.filePaths.length) { - throw new Error('获取目录或文件路径失败') + throw new Error('Get the directory or file path failure') } const filePaths = res.filePaths @@ -48,11 +51,11 @@ export default () => { .catch(e => console.warn(e)) if (res.canceled) { - throw new Error('用户取消操作') + throw new Error('User cancel operation') } if (!res.filePath) { - throw new Error('获取文件路径失败') + throw new Error('Failure to obtain the file path') } const destinationPath = res.filePath diff --git a/electron/events/handles/theme/index.js b/electron/events/handles/theme/index.js new file mode 100644 index 0000000..c081638 --- /dev/null +++ b/electron/events/handles/theme/index.js @@ -0,0 +1,26 @@ +import { ipcMain, nativeTheme } from 'electron' + +export default (mainWindow) => { + const appTheme = { + value() { + return nativeTheme.themeSource + }, + update(value) { + nativeTheme.themeSource = value + }, + isDark() { + return nativeTheme.shouldUseDarkColors + }, + } + + Object.entries(appTheme).forEach(([key, handler]) => { + ipcMain.handle(`app-theme-${key}`, (_, value) => handler(value)) + }) + + nativeTheme.on('updated', () => { + mainWindow.webContents.send('app-theme-change', { + isDark: appTheme.isDark(), + value: appTheme.value(), + }) + }) +} diff --git a/electron/events/tray/index.js b/electron/events/tray/index.js index 4139a8e..1ed9cc3 100644 --- a/electron/events/tray/index.js +++ b/electron/events/tray/index.js @@ -1,8 +1,11 @@ import { Menu, Tray, app, dialog } from 'electron' import { trayPath } from '@electron/configs/index.js' import appStore from '@electron/helpers/store.js' +import { executeI18n } from '@electron/helpers/index.js' export default (mainWindow) => { + const t = value => executeI18n(mainWindow, value) + let tray = null const showApp = () => { @@ -38,7 +41,7 @@ export default (mainWindow) => { return true } - const closeApp = (response) => { + const closeApp = async (response) => { if (response === 0) { quitApp() return true @@ -56,20 +59,20 @@ export default (mainWindow) => { const contextMenu = Menu.buildFromTemplate([ { - label: '打开', + label: await t('common.open'), click: () => { showApp() }, }, { - label: '重启服务', + label: await t('common.restart'), click: () => { app.relaunch() quitApp() }, }, { - label: '退出', + label: await t('close.quit'), click: () => { quitApp() }, @@ -101,11 +104,15 @@ export default (mainWindow) => { const { response, checkboxChecked } = await dialog.showMessageBox({ type: 'question', - buttons: ['退出', '最小化到托盘', '取消退出'], - title: '提示', - message: '确定要退出吗?', + buttons: [ + await t('close.quit'), + await t('close.minimize'), + await t('close.quit.cancel'), + ], + title: await t('common.tips'), + message: await t('close.message'), checkboxChecked: false, - checkboxLabel: '是否记住选择?', + checkboxLabel: await t('close.remember'), }) // console.log('response', response) diff --git a/electron/events/updater/index.js b/electron/events/updater/index.js index 04ec06f..00b2245 100644 --- a/electron/events/updater/index.js +++ b/electron/events/updater/index.js @@ -4,9 +4,7 @@ import { autoUpdater } from 'electron-updater' import { devPublishPath } from '@electron/configs/index.js' export default (mainWindow) => { - // dev-start, 这里是为了在本地做应用升级测试使用,正式环境请务必删除 - // if (is.dev && process.env.ELECTRON_RENDERER_URL) { - if (is.dev && process.env.VITE_DEV_SERVER_URL) { + if (is.dev) { autoUpdater.updateConfigPath = devPublishPath Object.defineProperty(app, 'isPackaged', { get() { diff --git a/electron/exposes/adbkit/index.js b/electron/exposes/adbkit/index.js index ba274aa..49ce96c 100644 --- a/electron/exposes/adbkit/index.js +++ b/electron/exposes/adbkit/index.js @@ -113,7 +113,7 @@ const display = async (deviceId) => { value = uniq(mapValue) } catch (error) { - console.error(error?.message || error) + console.warn(error?.message || error) } console.log('display.deviceId.value', value) diff --git a/electron/exposes/index.js b/electron/exposes/index.js index 84bcf76..b796143 100644 --- a/electron/exposes/index.js +++ b/electron/exposes/index.js @@ -14,10 +14,10 @@ export default { init(expose) { expose('nodePath', path) - expose('appStore', store) - expose('appLog', log) + expose('appStore', store) + expose('electron', { ...electron(), configs, diff --git a/electron/helpers/console.js b/electron/helpers/console.js index a911e02..20712a6 100644 --- a/electron/helpers/console.js +++ b/electron/helpers/console.js @@ -1,8 +1,13 @@ import log from '@electron/helpers/log.js' +import appStore from './store.js' import { createProxy } from './index.js' -Object.assign(console, { - ...createProxy(log.functions, log.levels), - raw: console.log, -}) +const debug = appStore.get('common.debug') || false + +if (debug) { + Object.assign(console, { + ...createProxy(log.functions, log.levels), + raw: console.log, + }) +} diff --git a/electron/helpers/index.js b/electron/helpers/index.js index 4a93559..d81f5e1 100644 --- a/electron/helpers/index.js +++ b/electron/helpers/index.js @@ -42,3 +42,15 @@ export function createProxy(targetObject, methodNames) { return proxyObj }, {}) } + +export async function executeI18n(mainWindow, value) { + try { + return await mainWindow.webContents.executeJavaScript( + `window.t('${value}')`, + ) + } + catch (error) { + console.warn(error?.message || error) + return value + } +} diff --git a/electron/main.js b/electron/main.js index 8f6e934..1813646 100644 --- a/electron/main.js +++ b/electron/main.js @@ -4,7 +4,7 @@ import { electronApp, optimizer } from '@electron-toolkit/utils' // process.js 必须位于非依赖项的顶部 import './helpers/process.js' -import './helpers/store.js' +import appStore from './helpers/store.js' import log from './helpers/log.js' import './helpers/console.js' @@ -15,7 +15,16 @@ import events from './events/index.js' log.initialize({ preload: true }) -console.log('Successfully initialized the Escrcpy logging system.') +const debug = !!appStore.get('common.debug') + +log.info('Debug Status:', debug) + +if (!debug) { + log.warn( + 'Debug Tips:', + '如果需要生成并查看运行日志请在偏好设置页面启动调试功能', + ) +} // The built directory structure // diff --git a/index.html b/index.html index 59f8641..e6605a2 100644 --- a/index.html +++ b/index.html @@ -1,5 +1,5 @@ - + diff --git a/src/App.vue b/src/App.vue index 21bede1..83349a9 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,7 +4,7 @@ @@ -29,15 +29,15 @@ export default { return { tabsModel: [ { - label: this.$t('device.list'), + label: 'device.list', prop: 'Device', }, { - label: this.$t('preferences.name'), + label: 'preferences.name', prop: 'Preference', }, { - label: this.$t('about.name'), + label: 'about.name', prop: 'About', }, ], @@ -47,6 +47,7 @@ export default { } }, created() { + this.$store.theme.init() this.$store.preference.init() this.showTips() }, diff --git a/src/components/About/index.vue b/src/components/About/index.vue index ab8af5c..014f120 100644 --- a/src/components/About/index.vue +++ b/src/components/About/index.vue @@ -4,7 +4,7 @@ -
+
{{ $t("about.description") }}
@@ -68,7 +68,7 @@ export default { }) }, onUpdateError() { - this.$electron.ipcRenderer.on('update-error', async (event, ret) => { + this.$electron.ipcRenderer.on('update-error', async (_, ret) => { this.loading = false console.log('onUpdateError.ret', ret) try { diff --git a/src/components/Device/ControlBar/index.vue b/src/components/Device/ControlBar/index.vue index 2df2a6d..695830c 100644 --- a/src/components/Device/ControlBar/index.vue +++ b/src/components/Device/ControlBar/index.vue @@ -1,5 +1,5 @@ @@ -167,7 +167,7 @@ @@ -413,8 +413,8 @@ export default { { dangerouslyUseHTMLString: true, closeOnClickModal: false, - confirmButtonText: this.$t('device.wireless.connect.error.confirm'), - cancelButtonText: this.$t('device.wireless.connect.error.cancel'), + confirmButtonText: this.$t('device.wireless.pair'), + cancelButtonText: this.$t('common.cancel'), type: 'warning', }, ) diff --git a/src/components/Preference/LanguageSelect/index.vue b/src/components/Preference/LanguageSelect/index.vue new file mode 100644 index 0000000..9b08c86 --- /dev/null +++ b/src/components/Preference/LanguageSelect/index.vue @@ -0,0 +1,53 @@ + + + + + diff --git a/src/components/Preference/index.vue b/src/components/Preference/index.vue index 8b83b06..3a909aa 100644 --- a/src/components/Preference/index.vue +++ b/src/components/Preference/index.vue @@ -65,7 +65,7 @@