From e574da4aa72210ec60119ae84babda620c4a0626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E9=B8=BF=E5=AE=87?= Date: Fri, 6 Jun 2025 11:09:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=E8=B0=83=E6=95=B4=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E6=98=BE=E7=A4=BA=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史鸿宇 --- electron/main/window/create.ts | 10 +++++- electron/main/window/index.ts | 63 --------------------------------- electron/main/window/options.ts | 2 +- electron/main/window/welcome.ts | 4 +-- 4 files changed, 12 insertions(+), 67 deletions(-) diff --git a/electron/main/window/create.ts b/electron/main/window/create.ts index 728e8f1..9e69dd4 100644 --- a/electron/main/window/create.ts +++ b/electron/main/window/create.ts @@ -171,9 +171,17 @@ export function createDefaultWindow(): BrowserWindow { defaultWindow = createWindow(defaultWindowOptions, hash, 'mainWindow'); - // 设置窗口标题 + // 开发模式下可以打开开发者工具 + if (process.env.NODE_ENV === 'development') { + defaultWindow.webContents.openDevTools({ mode: 'detach' }); + } + + // 设置窗口标题并显示窗口 defaultWindow.webContents.on('did-finish-load', () => { defaultWindow?.setTitle('openEuler 智能化解决方案'); + if (defaultWindow && !defaultWindow.isDestroyed()) { + defaultWindow.show(); + } }); return defaultWindow; diff --git a/electron/main/window/index.ts b/electron/main/window/index.ts index db024dc..cb1dea8 100644 --- a/electron/main/window/index.ts +++ b/electron/main/window/index.ts @@ -8,7 +8,6 @@ // PURPOSE. // See the Mulan PSL v2 for more details. -import { app, BrowserWindow, ipcMain } from 'electron'; import { createDefaultWindow, createChatWindow } from './create'; import { createTray } from './tray'; // 导入createTray函数 import { @@ -32,65 +31,3 @@ export { checkAndShowWelcomeIfNeeded, completeWelcomeFlow, }; - -// 存储所有窗口引用 -const allWindows: BrowserWindow[] = []; - -export function createWindows() { - // 创建默认窗口 - const defaultWindow = createDefaultWindow(); - allWindows.push(defaultWindow); - - // 添加窗口最大化状态变化事件监听 - defaultWindow.on('maximize', () => { - if (defaultWindow.webContents) { - defaultWindow.webContents.send('window-maximized-change', true); - } - }); - - defaultWindow.on('unmaximize', () => { - if (defaultWindow.webContents) { - defaultWindow.webContents.send('window-maximized-change', false); - } - }); - - // 窗口关闭时退出应用 - defaultWindow.on('closed', () => { - app.quit(); - }); - - // 聊天窗口 - const chatWindow = createChatWindow(); - allWindows.push(chatWindow); - - // 添加聊天窗口最大化状态变化事件监听 - chatWindow.on('maximize', () => { - if (chatWindow.webContents) { - chatWindow.webContents.send('window-maximized-change', true); - } - }); - - chatWindow.on('unmaximize', () => { - if (chatWindow.webContents) { - chatWindow.webContents.send('window-maximized-change', false); - } - }); - - // 添加IPC处理程序,用于查询窗口是否最大化 - ipcMain.handle('window-is-maximized', (event) => { - const win = BrowserWindow.fromWebContents(event.sender); - if (win) { - return win.isMaximized(); - } - return false; - }); -} - -export function destroyWindows() { - // 关闭所有窗口 - allWindows.forEach((window) => { - if (!window.isDestroyed()) { - window.close(); - } - }); -} diff --git a/electron/main/window/options.ts b/electron/main/window/options.ts index 3bfe367..78423d3 100644 --- a/electron/main/window/options.ts +++ b/electron/main/window/options.ts @@ -56,7 +56,7 @@ export const options: allWindowType = { minHeight: 810, titleBarStyle: 'hidden', resizable: true, - show: true, + show: false, alwaysOnTop: false, useContentSize: true, ...getLinuxSpecificOptions(), diff --git a/electron/main/window/welcome.ts b/electron/main/window/welcome.ts index 6818244..9b69caa 100644 --- a/electron/main/window/welcome.ts +++ b/electron/main/window/welcome.ts @@ -37,8 +37,8 @@ export function createWelcomeWindow(): BrowserWindow { resizable: false, maximizable: false, minimizable: false, - modal: true, - alwaysOnTop: true, + alwaysOnTop: false, + frame: false, title: '欢迎使用', webPreferences: { nodeIntegration: false, -- Gitee From e36711d72a5306de9a829bd1b0b1ebdf2aab2c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E9=B8=BF=E5=AE=87?= Date: Fri, 6 Jun 2025 11:09:32 +0800 Subject: [PATCH 2/2] refactor: clean code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史鸿宇 --- electron/main/index.ts | 10 +++++----- electron/preload/index.ts | 13 +++++++------ electron/preload/types.d.ts | 8 ++++---- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index 2d38e46..8da22e9 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -204,12 +204,12 @@ async function startup() { } // 触发窗口隐藏事件 chatWindow.webContents.send('clean:storage'); - // 清除localStorage中的conversationId + // 清除 localStorage 中的 conversationId win.webContents.executeJavaScript(` - localStorage.removeItem('conversationId'); - true; - `); + localStorage.removeItem('conversationId'); + true; + `); event.preventDefault(); chatWindow.hide(); }); -} \ No newline at end of file +} diff --git a/electron/preload/index.ts b/electron/preload/index.ts index 09e0047..be19068 100644 --- a/electron/preload/index.ts +++ b/electron/preload/index.ts @@ -84,6 +84,7 @@ const globals = { return ''; } }, + /** * 验证服务器连接(统一接口) */ @@ -121,15 +122,15 @@ const globals = { // 实用工具 utils: utilsAPI, - // chat事件 - chat:{ - /** + // 快捷聊天 + chat: { + /** * 清理数据 */ - onCleanStorage(callback):void { - safeIPC.on('clean:storage', (_event, value) => callback(value)) + onCleanStorage(callback): void { + safeIPC.on('clean:storage', (_event, value) => callback(value)); }, - } + }, }; // 暴露 API 到渲染进程 diff --git a/electron/preload/types.d.ts b/electron/preload/types.d.ts index 1808ef7..eb849c0 100644 --- a/electron/preload/types.d.ts +++ b/electron/preload/types.d.ts @@ -35,7 +35,6 @@ export interface DesktopAppAPI { setProxyUrl(url: string): Promise; getProxyUrl(): Promise; validateServer(url: string): Promise; - onCleanStorage(fun: () => void):void; }; // 窗口控制 @@ -70,9 +69,10 @@ export interface DesktopAppAPI { delay(ms: number): Promise; }; - chat:{ - onCleanStorage(fun: () => void):void; - } + // 快捷聊天 + chat: { + onCleanStorage(fun: () => void): void; + }; } export interface DesktopAppWelcomeAPI { -- Gitee