From b0f42aa474686649fc7eb4736329539530a3b85a Mon Sep 17 00:00:00 2001 From: viarotel Date: Mon, 9 Sep 2024 18:58:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fixed=20the=20problem=20o?= =?UTF-8?q?f=20minimizing=20the=20visibility=20of=20tray=20icons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/helpers/index.js | 12 +++++++----- electron/helpers/process.js | 4 +++- electron/main.js | 24 ++++++++++-------------- eslint.config.js | 2 ++ package.json | 20 ++++++++++---------- src/App.vue | 3 +-- 6 files changed, 33 insertions(+), 32 deletions(-) diff --git a/electron/helpers/index.js b/electron/helpers/index.js index d81f5e19..9068ed7a 100644 --- a/electron/helpers/index.js +++ b/electron/helpers/index.js @@ -2,12 +2,14 @@ import { resolve } from 'node:path' import { contextBridge } from 'electron' import { cloneDeep } from 'lodash-es' -export const isPackaged = process.env.IS_PACKAGED === 'true' +export const isPackaged = ['true'].includes(process.env.IS_PACKAGED) -export const extraResolve = (value) => { - return isPackaged - ? resolve(process.resourcesPath, `extra/${value}`) - : resolve(`electron/resources/extra/${value}`) +export const extraResolve = (filePath) => { + const basePath = isPackaged ? process.resourcesPath : 'electron/resources' + + const value = resolve(basePath, 'extra', filePath) + + return value } export const buildResolve = value => diff --git a/electron/helpers/process.js b/electron/helpers/process.js index 77b00482..d0a5ed8b 100644 --- a/electron/helpers/process.js +++ b/electron/helpers/process.js @@ -8,8 +8,10 @@ if (process.platform === 'darwin') { fixPath() } -process.env.IS_PACKAGED = JSON.stringify(app.isPackaged) +process.env.IS_PACKAGED = String(app.isPackaged) process.env.DESKTOP_PATH = app.getPath('desktop') process.env.CWD = process.cwd() + +export const isPackaged = ['true'].includes(process.env.IS_PACKAGED) diff --git a/electron/main.js b/electron/main.js index 4442a739..e3e30182 100644 --- a/electron/main.js +++ b/electron/main.js @@ -6,17 +6,15 @@ import remote from '@electron/remote/main' import { electronApp, optimizer } from '@electron-toolkit/utils' import { app, BrowserWindow, shell } from 'electron' import contextMenu from 'electron-context-menu' - -import { icnsLogoPath, icoLogoPath, logoPath } from './configs/index.js' -import events from './events/index.js' - +/** process.js 必须位于非依赖项的顶部 */ +import { isPackaged } from './helpers/process.js' import log from './helpers/log.js' +import './helpers/console.js' import appStore from './helpers/store.js' -// process.js 必须位于非依赖项的顶部 -import './helpers/process.js' +import { icnsLogoPath, icoLogoPath, logoPath } from './configs/index.js' -import './helpers/console.js' +import events from './events/index.js' const require = createRequire(import.meta.url) const __dirname = path.dirname(fileURLToPath(import.meta.url)) @@ -28,7 +26,7 @@ const debug = !!appStore.get('common.debug') if (!debug) { log.warn( 'Debug Tips:', - 'If you need to generate and view the running log, please start the debugging function on the preference setting page', + 'If you need to generate and view the running log, please start the debugging function on the preference setting page' ) } @@ -37,7 +35,7 @@ contextMenu({ showSelectAll: false, showSearchWithGoogle: false, showSaveImageAs: true, - showInspectElement: !app.isPackaged, + showInspectElement: !isPackaged, }) // The built directory structure @@ -61,14 +59,13 @@ function createWindow() { if (process.platform === 'win32') { icon = icoLogoPath - } - else if (process.platform === 'darwin') { + } else if (process.platform === 'darwin') { icon = icnsLogoPath } mainWindow = new BrowserWindow({ // 这里设置的图标仅在开发模式生效,打包后将使用应用程序图标 - ...(!app.isPackaged + ...(!isPackaged ? { icon, } @@ -101,8 +98,7 @@ function createWindow() { if (VITE_DEV_SERVER_URL) { mainWindow.loadURL(VITE_DEV_SERVER_URL) - } - else { + } else { mainWindow.loadFile(path.join(process.env.DIST, 'index.html')) } diff --git a/eslint.config.js b/eslint.config.js index bcb5b0af..cef1e1d1 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -16,6 +16,7 @@ export default antfu( 'dist', 'dist-electron', 'dist-release', + 'electron/main.js', ], }, { @@ -47,6 +48,7 @@ export default antfu( 'no-new': 'off', 'prefer-promise-reject-errors': 'off', 'no-unused-expressions': 'off', + 'sort-imports': 'off', 'vue/html-self-closing': 'off', 'vue/block-order': 'off', diff --git a/package.json b/package.json index 75d47a61..5c775088 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "electron-in-page-search": "1.3.2", "nanoid": "5.0.7", "pinia-plugin-persistedstate": "3.2.1", - "vue": "3.4.26" + "vue": "3.4.21" }, "devDependencies": { "@antfu/eslint-config": "3.3.2", @@ -34,17 +34,17 @@ "@electron-toolkit/utils": "3.0.0", "@electron/remote": "2.1.2", "@intlify/unplugin-vue-i18n": "4.0.0", - "@unocss/reset": "0.59.4", - "@unocss/transformer-directives": "0.59.4", + "@unocss/reset": "0.62.3", + "@unocss/transformer-directives": "0.62.3", "@viarotel-org/unocss-preset-shades": "0.8.2", "@vitejs/plugin-vue": "5.0.4", "@vueuse/core": "10.9.0", "dayjs": "1.11.11", - "electron": "30.0.3", + "electron": "29.1.1", "electron-builder": "24.13.3", - "electron-context-menu": "4.0.0", + "electron-context-menu": "4.0.4", "electron-find-in-page": "1.0.8", - "electron-log": "5.1.2", + "electron-log": "5.2.0", "electron-store": "9.0.0", "electron-updater": "6.1.8", "element-plus": "2.8.2", @@ -57,10 +57,10 @@ "postcss": "8.4.38", "postcss-nested": "6.0.1", "postcss-scss": "4.0.9", - "unocss": "0.59.4", - "unplugin-auto-import": "0.17.5", - "unplugin-vue-components": "0.27.0", - "vite": "5.2.11", + "unocss": "0.62.3", + "unplugin-auto-import": "0.18.2", + "unplugin-vue-components": "0.27.4", + "vite": "5.1.5", "vite-plugin-electron": "0.28.7", "vite-plugin-electron-renderer": "0.14.5", "vite-svg-loader": "5.1.0", diff --git a/src/App.vue b/src/App.vue index 6b942cd0..68785cd3 100644 --- a/src/App.vue +++ b/src/App.vue @@ -41,12 +41,11 @@ import { i18n } from '$/locales/index.js' import localeModel from '$/plugins/element-plus/locale.js' import { usePreferenceStore } from '$/store/preference/index.js' + import { useThemeStore } from '$/store/theme/index.js' import { ElMessageBox } from 'element-plus' - import About from './components/About/index.vue' import Device from './components/Device/index.vue' - import Preference from './components/Preference/index.vue' import Quick from './components/Quick/index.vue'