From 8c4ce170b7545b88599d79e555c7bdec2b0e1048 Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Tue, 23 Jul 2024 15:56:27 +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 | 13 ++++++++++--- preload.js | 4 ++++ src/render.d.ts | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index b8d0d61..dc5d2b0 100644 --- a/main.js +++ b/main.js @@ -17,15 +17,13 @@ class AppWindow extends BrowserWindow { }, show: false, frame: false, - icon: '', - icon: '', backgroundColor: '#00000000', transparent: true, }; const finalConfig = { ...basicConfig, ...config }; super(finalConfig); const env = process.argv.find((arg) => arg.startsWith('--env='))?.split('=')[1]; - if (env) { + if (env === 'development') { // 开发 this.loadURL('http://localhost:3000'); } else { @@ -181,5 +179,14 @@ app.on('ready', () => { const y = Math.round((display.workArea.height - mainWindow.getSize()[1]) / 2); mainWindow.setPosition(x, y); }); + + // 打开新页面 + ipcMain.handle('openNewPage', (event, url) => { + const env = process.argv.find((arg) => arg.startsWith('--env='))?.split('=')[1]; + const winURL = env === 'development' + ? `http://localhost:3000` + : path.resolve(__dirname, './dist/index.html') + }); + }); diff --git a/preload.js b/preload.js index 9622aec..5cd0e57 100644 --- a/preload.js +++ b/preload.js @@ -20,5 +20,9 @@ window.electron = { // 加入房间通知 joinNotification: (user) => { ipcRenderer.invoke('joinNotification', user) + }, + // 打开新页面 + openNewPage: (url) => { + ipcRenderer.invoke('openNewPage', url) } } \ No newline at end of file diff --git a/src/render.d.ts b/src/render.d.ts index 49c45ae..5b7ada1 100644 --- a/src/render.d.ts +++ b/src/render.d.ts @@ -4,6 +4,7 @@ export interface IElectronAPI { setViewStatus: (status: 'quit' | 'maximize' | 'minimize' | 'unmaximize') => void; getIsMaximized: () => Promise; setWriteText: (text: string) => void; + openNewPage: (url: string) => void; joinNotification: (data: { name: string, body: string }) => void } declare global {