Environment: windowsx64,node 14x version electron 12x version
import { app, BrowserWindow, Tray, Menu } from 'electron' /** * Set `__static` path to static files in production * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html * / / / solve the X version problem of cross-domain unsuccessful online (delete) app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors'); if (process.env.NODE_ENV ! == 'development') { global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')} var appTray = null; let mainWindow const winURL = process.env.NODE_ENV === 'development' ? `http://localhost:9080` : `file://${__dirname}/index.html` function createWindow () { /** * Initial window options */ mainWindow = new BrowserWindow({height: 750, width: 1200, center: true, // Whether to appear in the middle of the screen useContentSize: true, Frame :true,// When set to false to create a frameless window resizable:true,// Whether the window can be resized autoHideMenuBar:true,// Whether to hide the menu bar backgroundColor:'# FFF ',// The window background color is a hexadecimal value titleBarStyle:'hidden',// the window titleBarStyle webPreferences: {nodeIntegration: True, / / whether to enable nodes integrated nodeIntegrationInWorker: true, / / whether the Web work device is enabled in the Node integration contextIsolation: False,//electron adds this line for version 12x devTools:true,// enable devTools // webSecurity: Whether true / / disable the same-origin policy online (delete)}}) mainWindow. LoadURL (winURL) / / mainWindow. WebContents. OpenDevTools (); Mainwindow. on('closed', If (process.platform === 'win32'){var trayMenuTemplate = [{if(process.platform === 'win32'){ Label: 'open', click: () = > {mainWindow. Show (); the mainWindow. WebContents. Send (' changeWin ', 1);}}, {label: 'exit', click: () => {app.quit(); app.quit();}}]; appTray = process.env.NODE_ENV === 'development'? new Tray('build/icons/icon.ico'):new Tray(`${__dirname}/static/images/icon.ico`); // icon contextMenu const contextMenu = menu. buildFromTemplate(trayMenuTemplate); // Set the hover prompt for the tray icon apptray.setTooltip (' client file '); // set the contextMenu for this icon, apptray.setcontextmenu (contextMenu); Apptray. on('click',function(){mainwindow.show (); mainWindow.webContents.send('changeWin',1); }); // Right click Apptray. on('right-click', () => {Apptray. popUpContextMenu(trayMenuTemplate); }); }; }; app.on('ready', createWindow) app.on('window-all-closed', () => { if (process.platform ! == 'darwin') { app.quit() } }) app.on('activate', () = > {the if (mainWindow = = = null) {createWindow ()}}) / / limiting application can open a const gotTheLock = app. RequestSingleInstanceLock (); if (! gotTheLock) { app.quit() } else { app.on('second-instance', (event, commandLine, If (mainWindow) {if (MainWindow.isNotifyicon ()){// Add icon in conclusion mainWindow.restore() mainWindow.focus() mainWindow.show() } } }) }; /** * Auto Updater * * Uncomment the following code below and install `electron-updater` to * support auto updating. Code Signing with a valid certificate is required. * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-builder.html#auto-updating */ /* import { autoUpdater } from 'electron-updater' autoUpdater.on('update-downloaded', () => { autoUpdater.quitAndInstall() }) app.on('ready', () => { if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdates() }) */Copy the code