| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- const { app, BrowserWindow} = require('electron')
- const WinState = require('electron-win-state').default
- const path = require('path')
- const createWindow = () => {
- const winState = new WinState({
- defaultWidth: 1000,
- defaultHeight:800
- })
- const win = new BrowserWindow({
- ...winState.winOptions,
- webPreferences:{
- // 新版 electron 必须关闭沙盒模式才能使用 clipboard
- sandbox: false,
- preload: path.resolve(__dirname, './preload/index.js')
- },
- show: false
- })
- win.loadURL('http://localhost:5173')
- win.webContents.openDevTools()
- winState.manage(win)
- // 等页面加载渲染完后,才显示窗口,避免刚启动时看到页面空白
- win.on('ready-to-show', () => {
- win.show()
- })
- }
- app.whenReady().then(() => {
- createWindow()
- // darwin系统关闭窗口但是它还在后台运行
- // 所以检测APP是否在活动,如果还在就重新创建
- app.on('activate', () => {
- if (BrowserWindow.getAllWindows().length ===0){
- createWindow()
- }
- })
- })
- app.on('window-all-closed', () => {
- app.quit()
- })
|