diff --git a/electron/main/index.ts b/electron/main/index.ts index 2d38e46d06536ea28adfe951d93fa98b7a16af2a..8da22e98cf96c42b331514417bd6262e9cf3b3f0 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/main/window/create.ts b/electron/main/window/create.ts index 728e8f12c5b348bbf8c0cd3445ae17e0d3f27102..9e69dd48c6d0030fed9a85a45a847653e3b8417c 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 db024dc5116442702ca07677fdcecbb19a654717..cb1dea897d020182ff395cc8693a65d44ab4ce0c 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 3bfe3679133a13cf6426d8af52ac691b345a802b..78423d34724bb78f478dd350561ebcb3913221d0 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 68182443959fe888060409e1453fb771a8c53846..9b69caa49072c1ea24a93c23b4c2bbc157b6aae8 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, diff --git a/electron/preload/index.ts b/electron/preload/index.ts index 09e0047e26ca24f3849520e34fbd774cb4d97daf..be190682ee4a2c14a4e7952be88f162aa97dc661 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 1808ef78f88f35e8e00100aa131bf77029c68c72..eb849c0fc423bf8defcf958f23b316c9a349a1e3 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 {