(
options: BrowserWindowConstructorOptions = {},
)
| 5 | import icon from "../../../public/icons/favicon.png?asset"; |
| 6 | |
| 7 | export const createWindow = ( |
| 8 | options: BrowserWindowConstructorOptions = {}, |
| 9 | ): BrowserWindow | null => { |
| 10 | try { |
| 11 | const defaultOptions: BrowserWindowConstructorOptions = { |
| 12 | title: appName, |
| 13 | width: 1280, |
| 14 | height: 720, |
| 15 | frame: false, // 是否显示窗口边框 |
| 16 | center: true, // 窗口居中 |
| 17 | icon, // 窗口图标 |
| 18 | autoHideMenuBar: true, // 隐藏菜单栏 |
| 19 | webPreferences: { |
| 20 | preload: join(__dirname, "../preload/index.mjs"), |
| 21 | // 禁用渲染器沙盒 |
| 22 | sandbox: false, |
| 23 | // 禁用同源策略 |
| 24 | webSecurity: false, |
| 25 | // 允许 HTTP |
| 26 | allowRunningInsecureContent: true, |
| 27 | // 禁用拼写检查 |
| 28 | spellcheck: false, |
| 29 | // 启用 Node.js |
| 30 | nodeIntegration: true, |
| 31 | nodeIntegrationInWorker: true, |
| 32 | }, |
| 33 | }; |
| 34 | // 合并参数 |
| 35 | if (options.webPreferences) { |
| 36 | options.webPreferences = Object.assign( |
| 37 | {}, |
| 38 | defaultOptions.webPreferences, |
| 39 | options.webPreferences, |
| 40 | ); |
| 41 | } |
| 42 | options = Object.assign(defaultOptions, options); |
| 43 | // 创建窗口 |
| 44 | const win = new BrowserWindow(options); |
| 45 | return win; |
| 46 | } catch (error) { |
| 47 | windowsLog.error(error); |
| 48 | return null; |
| 49 | } |
| 50 | }; |
no outgoing calls
no test coverage detected