From caba67da14a9ec100f9e9318e600b21ab286e116 Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Mon, 24 Feb 2025 17:41:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 26 +++++++++++--------------- preload.js | 6 +++--- src/App.tsx | 2 +- src/render.d.ts | 2 +- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/main.js b/main.js index 0dfd420..24d2362 100644 --- a/main.js +++ b/main.js @@ -24,10 +24,9 @@ app.allowRendererProcessReuse = false; let mainWindow = null; let childWindow = {} let isMaximized = false; -let env; +let env = 'development'; //development production let regKey; let connection = null; -let envStr; let startNumber = 0; let buildStatus = false; //true 打包开发版本 false 本地开发 powerSaveBlocker.start('prevent-display-sleep') @@ -53,15 +52,13 @@ class AppWindow extends BrowserWindow { const finalConfig = { ...basicConfig, ...config }; super(finalConfig); if (env === 'development') { - // 开发 if (buildStatus) { - this.loadFile(path.resolve(__dirname, './dist/index.html')); + this.loadURL('http://192.168.2.9:8827/'); } else { this.loadURL('http://localhost:3000'); } } else { - // 测试 | 生产 - this.loadFile(path.resolve(__dirname, './dist/index.html')); + this.loadFile(path.resolve(__dirname, './dist/index.html')) } this.once('ready-to-show', () => { this.show(); @@ -73,10 +70,10 @@ function quit() { } let tray; function createTray() { - const iconPath = `${__dirname}/src/assets/${updateJs.getIcon(envStr)}.png`; + const iconPath = `${__dirname}/src/assets/${updateJs.getIcon(env)}.png`; const trayIcon = nativeImage.createFromPath(iconPath); tray = new Tray(trayIcon); - tray.setToolTip(updateJs.getTitle(envStr)); + tray.setToolTip(updateJs.getTitle(env)); tray.on('click', () => { mainWindow.webContents.send('isOpenWindows'); }); @@ -103,7 +100,6 @@ app.on('ready', () => { uploadToServer: false, ignoreSystemCrashHandler: false }) - env = process.argv.find((arg) => arg.startsWith('--env='))?.split('=')[1]; if (env === 'development') { Object.defineProperty(app, 'isPackaged', { get() { @@ -149,8 +145,7 @@ app.on('ready', () => { isMaximized = true; } }); - ipcMain.handle('setEnv', (event, str) => { - envStr = str; + ipcMain.handle('startLoad', (event) => { if (startNumber === 0) { updateHandle() // 检查更新 setInterval(() => { @@ -616,10 +611,11 @@ app.on('ready', () => { width: config.width, height: config.height, }) - if (envStr === 'development') { + if (env === 'development') { // 开发 if (buildStatus) { - child.loadURL(`file://${path.join(__dirname, './dist/index.html')}#/${config.key}`); + child.loadURL(`http://192.168.2.9:8827/#/${config.key}`); + // child.loadURL(`file://${path.join(__dirname, './dist/index.html')}#/${config.key}`); } else { child.loadURL(config.url) } @@ -734,7 +730,7 @@ function updateHandle() { updateAva: '检测到新版本,正在下载……', updateNotAva: '已经是最新版本,不用更新' } - autoUpdater.setFeedURL(updateJs.getUpdateUrl(envStr)) + autoUpdater.setFeedURL(updateJs.getUpdateUrl(env)) autoUpdater.autoDownload = false // 不自动下载安装包 autoUpdater.autoInstallOnAppQuit = false // 不自动安装 autoUpdater.on('error', function (error) { @@ -821,7 +817,7 @@ function mainWindowCenter() { const startSignalr = async (user) => { connection = new signalR.HubConnectionBuilder() - .withUrl(`${envStr === 'development' ? 'http://192.168.2.9:5192' : 'https://meeting-api.23544.com/pc'}/session-manage`, { + .withUrl(`${env === 'development' ? 'http://192.168.2.9:5192' : 'https://meeting-api.23544.com/pc'}/session-manage`, { skipNegotiation: true, transport: signalR.HttpTransportType.WebSockets, accessTokenFactory: () => user.token diff --git a/preload.js b/preload.js index 19e9075..f3b9293 100644 --- a/preload.js +++ b/preload.js @@ -87,9 +87,9 @@ window.electron = { isOpenWindows: (callback) => { ipcRenderer.on('isOpenWindows', callback) }, - // 设置环境变量 - setEnv: (str) => { - ipcRenderer.invoke('setEnv', str) + // 首次加载 + startLoad: () => { + ipcRenderer.invoke('startLoad') }, // 更新 updateHandle: () => { diff --git a/src/App.tsx b/src/App.tsx index f976b78..ad92c1e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -58,7 +58,6 @@ const App: React.FC = () => { } }) } - window.electron.setEnv(import.meta.env.VITE_ENV); if (userInfo && !userInfo.isAnonymous) { if (loginInfo && loginInfo.isAutoLogin) { GetCheckOnline(loginInfo.account).then(req => { @@ -105,6 +104,7 @@ const App: React.FC = () => { }; }, []); useEffect(() => { + window.electron.startLoad(); window.electron.downFile(async (_e: any, data: any) => { const response = await fetch(data.filePath); const arrayBuffer = await response.arrayBuffer(); diff --git a/src/render.d.ts b/src/render.d.ts index 0aeefea..109b8e8 100644 --- a/src/render.d.ts +++ b/src/render.d.ts @@ -24,7 +24,7 @@ export interface IElectronAPI { downFile: (callBack: Function) => void; quitAndInstall: (callBack: Function) => void; isOpenWindows: (callBack: Function) => void; - setEnv: (str: string) => any; + startLoad: () => any; updateHandle: () => any; getVersion: () => Promise; isVisible: () => Promise;