From 7827ef2c00bb8055d381ab5275e6471292141232 Mon Sep 17 00:00:00 2001 From: Hu Gang <18768366022@163.com> Date: Mon, 21 Apr 2025 15:25:10 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=9C=A8=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E4=B8=8A=E4=BD=BF=E7=94=A8electron=E7=9A=84=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E4=BB=A3=E6=9B=BF=E9=BB=98=E8=AE=A4window.open?= =?UTF-8?q?=E6=89=93=E5=BC=80=E7=9A=84=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main/common/conf.ts | 2 +- electron/main/common/platform.ts | 4 ++-- electron/main/common/product.ts | 4 +++- electron/main/window/create.ts | 36 ++++++++++++++++++++++++++++++++ electron/main/window/options.ts | 9 ++++++-- src/apis/tools.ts | 2 +- 6 files changed, 50 insertions(+), 7 deletions(-) diff --git a/electron/main/common/conf.ts b/electron/main/common/conf.ts index 5f4c99e..d5ce45f 100644 --- a/electron/main/common/conf.ts +++ b/electron/main/common/conf.ts @@ -14,7 +14,7 @@ import { productObj } from './product'; interface ICacheConf { theme: 'system' | 'light' | 'dark'; - userLocale; + userLocale: string; } export const userDataPath = getUserDataPath(productObj.name); diff --git a/electron/main/common/platform.ts b/electron/main/common/platform.ts index 7f78c8a..1d499b4 100644 --- a/electron/main/common/platform.ts +++ b/electron/main/common/platform.ts @@ -9,7 +9,7 @@ // See the Mulan PSL v2 for more details. import * as nls from './nls'; -export const LANGUAGE_DEFAULT = 'en'; +export const LANGUAGE_DEFAULT = 'zh_cn'; let _isWindows = false; let _isMacintosh = false; @@ -53,7 +53,7 @@ if (typeof nodeProcess === 'object') { _isElectron = isElectronProcess; _locale = LANGUAGE_DEFAULT; _language = LANGUAGE_DEFAULT; - const rawNlsConfig = nodeProcess.env['VSCODE_NLS_CONFIG']; + const rawNlsConfig = nodeProcess.env['EULERCOPILOT_NLS_CONFIG']; if (rawNlsConfig) { try { const nlsConfig: nls.INLSConfiguration = JSON.parse(rawNlsConfig); diff --git a/electron/main/common/product.ts b/electron/main/common/product.ts index b90384f..c414ac6 100644 --- a/electron/main/common/product.ts +++ b/electron/main/common/product.ts @@ -7,10 +7,12 @@ // IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR // PURPOSE. // See the Mulan PSL v2 for more details. +import { build } from '../../../package.json'; + export interface IProductConfiguration { readonly name: string; } export const productObj: IProductConfiguration = { - name: 'EulerCopilot', + name: build.productName, }; diff --git a/electron/main/window/create.ts b/electron/main/window/create.ts index 1bfdc4b..a2f180e 100644 --- a/electron/main/window/create.ts +++ b/electron/main/window/create.ts @@ -13,6 +13,7 @@ import { BrowserWindow, app, ipcMain, Menu } from 'electron'; import { options as allWindow } from './options'; import { updateConf } from '../common/conf'; import { isLinux } from '../common/platform'; +import { iconPath } from './options'; // 存储所有创建的窗口实例,用于全局访问 const windowInstances: Map = new Map(); @@ -49,6 +50,9 @@ export function createWindow( // 设置右键上下文菜单 setupContextMenu(win); + // 设置窗口打开处理程序 + setupWindowOpenHandler(win); + return win; } @@ -102,6 +106,38 @@ function setupContextMenu(win: BrowserWindow) { }); } +function setupWindowOpenHandler(win: BrowserWindow) { + win.webContents.setWindowOpenHandler((details: Electron.HandlerDetails) => { + if (details.url) { + const features = details.features || ''; + const width = parseInt(features.split('width=')[1] || '800', 10); + const height = parseInt(features.split('height=')[1] || '600', 10); + const x = parseInt(features.split('left=')[1] || '0', 10); + const y = parseInt(features.split('top=')[1] || '0', 10); + + return { + action: 'allow', + overrideBrowserWindowOptions: { + width, + height, + autoHideMenuBar: true, + icon: iconPath, + x, + y, + resizable: true, + webPreferences: { + preload: path.join(__dirname, 'preload.js'), + webSecurity: false, + nodeIntegration: true, + nodeIntegrationInWorker: true, + }, + }, + }; + } + return { action: 'deny' }; + }); +} + let defaultWindow: BrowserWindow | null = null; /** diff --git a/electron/main/window/options.ts b/electron/main/window/options.ts index e7049c8..356349c 100644 --- a/electron/main/window/options.ts +++ b/electron/main/window/options.ts @@ -7,7 +7,9 @@ // IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR // PURPOSE. // See the Mulan PSL v2 for more details. +import path from 'path'; import { isLinux } from '../common/platform'; +import electron from 'electron'; export interface allWindowType { [propName: string]: { @@ -46,6 +48,9 @@ const adjustWindowSize = ( return result; }; +export const iconPath = electron.app.isPackaged + ? 'dist/favicon.ico' + : path.join(__dirname, '../../public/app_favicon.ico'); export const options: allWindowType = { mainWindow: { id: 'mainWindow', @@ -59,7 +64,7 @@ export const options: allWindowType = { show: true, alwaysOnTop: false, useContentSize: true, - icon: 'dist/favicon.ico', + icon: iconPath, ...getLinuxSpecificOptions(), }), hash: '/', @@ -77,7 +82,7 @@ export const options: allWindowType = { alwaysOnTop: true, useContentSize: true, titleBarStyle: 'hidden', - icon: 'dist/favicon.ico', + icon: iconPath, ...getLinuxSpecificOptions(), }), hash: '/chat', diff --git a/src/apis/tools.ts b/src/apis/tools.ts index f7c06d6..cc7e9e6 100644 --- a/src/apis/tools.ts +++ b/src/apis/tools.ts @@ -52,7 +52,7 @@ async function toAuthorization() { const url = await store.getAuthUrl('login'); if (!url) return; const w = 1000; - const h = 700; + const h = 750; const left = (screen.width - w) / 2; const top = (screen.height - h) / 2; -- Gitee