const {app, BrowserWindow} = require('electron')
const electron = require('electron')
const path = require('path');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow = null
const Menu = electron.Menu
const Tray = electron.Tray
var appTray = null;
function createWindow () {
??Menu.setApplicationMenu(null)
? // Create the browser window.
? mainWindow = new BrowserWindow({width: 936, height: 526 ,
? ? ? ? resizable: false,})//resizable恒序,設(shè)置窗口是否可伸縮
? // and load the index.html of the app.
? mainWindow.loadFile('zhushou/index.html')//加載HTML頁(yè)面
? mainWindow.setClosable(false)//設(shè)置窗口關(guān)閉按鈕是否可用
? mainWindow.flashFrame(true)//設(shè)置窗口閃爍
? mainWindow.setSkipTaskbar(true)//設(shè)置任務(wù)欄是否顯示
? // Open the DevTools.
? mainWindow.webContents.openDevTools()//增加開發(fā)者工具
? //系統(tǒng)托盤圖標(biāo)目錄
? trayIcon = path.join(__dirname, 'res');//res是選取的目錄
? appTray = new Tray(path.join(trayIcon, 'favicon.ico'));//res.ico是res目錄下的ico文件
? //設(shè)置此托盤圖標(biāo)的懸停提示內(nèi)容
? appTray.setToolTip('這里是提示信息');
? //單擊右下角小圖標(biāo)顯示應(yīng)用
? appTray.on('click',function(){
? ? mainWindow.show();
? })
}
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
? if (process.platform !== 'darwin') {
? ? app.quit()
? }
})
app.on('activate', function () {
? // On OS X 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 (mainWindow === null) {
? ? createWindow()
? }
? //Electron單實(shí)例
const shouldQuit = app.makeSingleInstance(
? (commandLine, workingDirectory) => {
? ? ? if (mainWindow) {
? ? ? ? ? if (mainWindow.isMinimized()){
? ? ? ? ? ? ? mainWindow.restore();
? ? ? ? ? };
? ? ? mainWindow.focus();
? };
? });
? if (shouldQuit) {
? ? app.quit();
? ? return;//沒有這句話,會(huì)報(bào)錯(cuò)!
? };
})