diff --git a/src/native/sysproxy/index.js b/src/native/sysproxy/index.js --- a/src/native/sysproxy/index.js +++ b/src/native/sysproxy/index.js @@ -70,6 +70,12 @@ function getResourcesPath() { try { const { app } = require('electron') const appPath = app.getAppPath() + // A shared system Electron keeps process.resourcesPath in Electron's own + // store path. The directory containing app.asar is the app resource path. + if (appPath.endsWith('.asar') && existsSync(join(dirname(appPath), 'sidecar'))) { + return dirname(appPath) + } + if (existsSync(join(appPath, 'extra', 'sidecar'))) { return appPath } diff --git a/src/main/utils/dirs.ts b/src/main/utils/dirs.ts --- a/src/main/utils/dirs.ts +++ b/src/main/utils/dirs.ts @@ -62,13 +62,16 @@ export function workDir(): string { } +export function isDevelopment(): boolean { + return is.dev && !app.getAppPath().endsWith('asar') +} + export function resourcesDir(): string { - if (is.dev) { + const appPath = app.getAppPath() + if (appPath.endsWith('asar')) { + return path.dirname(appPath) + } else if (isDevelopment()) { return path.join(__dirname, '../../extra') } else { - if (app.getAppPath().endsWith('asar')) { - return process.resourcesPath - } else { - return path.join(app.getAppPath(), 'resources') - } + return path.join(appPath, 'resources') } } diff --git a/src/main/window.ts b/src/main/window.ts --- a/src/main/window.ts +++ b/src/main/window.ts @@ -1,11 +1,10 @@ import { join } from 'path' import { readFileSync, writeFileSync } from 'fs' import { BrowserWindow, Menu, screen, shell } from 'electron' -import { is } from '@electron-toolkit/utils' import icon from '../../resources/icon.png?asset' import { getAppConfig } from './config' import { quitWithoutCore, stopCore } from './core/manager' import { triggerSysProxy } from './sys/sysproxy' import { hideDockIcon, showDockIcon } from './resolve/tray' -import { dataDir } from './utils/dirs' +import { dataDir, isDevelopment } from './utils/dirs' import { mainWindowLogger } from './utils/logger' @@ -172,10 +171,10 @@ export async function createMainWindow(silentStart = false): Promise { }) - if (is.dev) { + if (isDevelopment()) { mainWindow.webContents.openDevTools() } - if (is.dev && process.env['ELECTRON_RENDERER_URL']) { + if (isDevelopment() && process.env['ELECTRON_RENDERER_URL']) { mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL']) } else { mainWindow.loadFile(join(__dirname, '../renderer/index.html')) @@ -199,7 +198,7 @@ function setupWindowEvents(window: BrowserWindow, config: WindowConfig): void { } // 开发模式下始终显示窗口 - if (!silentStart || is.dev) { + if (!silentStart || isDevelopment()) { clearQuitTimeout() window.show() window.focusOnWebView() diff --git a/src/main/resolve/floatingWindow.ts b/src/main/resolve/floatingWindow.ts --- a/src/main/resolve/floatingWindow.ts +++ b/src/main/resolve/floatingWindow.ts @@ -1,8 +1,8 @@ import { join } from 'path' -import { is } from '@electron-toolkit/utils' import { BrowserWindow, ipcMain } from 'electron' import windowStateKeeper from 'electron-window-state' import { getAppConfig, patchAppConfig } from '../config' +import { isDevelopment } from '../utils/dirs' import { floatingWindowLogger } from '../utils/logger' import { applyTheme } from './theme' import { buildContextMenu, showTrayIcon } from './tray' @@ -86,11 +86,11 @@ async function createFloatingWindow(): Promise { // 加载页面 const url = - is.dev && process.env['ELECTRON_RENDERER_URL'] + isDevelopment() && process.env['ELECTRON_RENDERER_URL'] ? `${process.env['ELECTRON_RENDERER_URL']}/floating.html` : join(__dirname, '../renderer/floating.html') - is.dev ? await floatingWindow.loadURL(url) : await floatingWindow.loadFile(url) + isDevelopment() ? await floatingWindow.loadURL(url) : await floatingWindow.loadFile(url) } catch (error) { logError('Failed to create floating window', error) floatingWindow = null