import { app, shell, BrowserWindow, nativeImage } from 'electron' import * as path from 'path' import { electronApp, optimizer, is } from '@electron-toolkit/utils' // logo const logoIcon = nativeImage.createFromPath(path.join(__dirname, '../../public/icon/icon.jpg')) console.log(process.versions.node) // 主窗口 let mainWindow function createWindow() { mainWindow = new BrowserWindow({ // fullscreen: true, // fullscreenable: true, width: 800, height: 800, show: false, autoHideMenuBar: true, icon: logoIcon, webPreferences: { preload: path.resolve(__dirname, '../preload/index.js'), sandbox: false } }) mainWindow.on('ready-to-show', () => { mainWindow.show() // mainWindow.webContents.openDevTools() }) mainWindow.webContents.setWindowOpenHandler((details) => { shell.openExternal(details.url) return { action: 'deny' } }) // mainWindow.loadURL('http://localhost:5173/') mainWindow.on('close', () => { app.exit() }) if (is.dev && process.env['ELECTRON_RENDERER_URL']) { mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL']) } else { mainWindow.loadFile(path.join(__dirname, '../renderer/index.html')) } } app.whenReady().then(() => { electronApp.setAppUserModelId('com.electron') // Default open or close DevTools by F12 in development // and ignore CommandOrControl + R in production. // see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils app.on('browser-window-created', (_, window) => { optimizer.watchWindowShortcuts(window) }) createWindow() app.on('activate', function () { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) createWindow() }) }) app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required'); // Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits // explicitly with Cmd + Q. app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() } }) // In this file you can include the rest of your app"s specific main process // code. You can also put them in separate files and require them here.