kim131 před 4 roky
rodič
revize
b4b1138d18
1 změnil soubory, kde provedl 19 přidání a 13 odebrání
  1. +19
    -13
      src/main/index.js

+ 19
- 13
src/main/index.js Zobrazit soubor

@@ -1,5 +1,5 @@
// Modules to control application life and create native browser window // Modules to control application life and create native browser window
const { app, BrowserWindow, protocol, ipcMain, dialog, nativeImage } = require('electron')
const { app, BrowserWindow, protocol, ipcMain, dialog, nativeImage, Menu, Tray } = require('electron')
const path = require('path') const path = require('path')


const gotTheLock = app.requestSingleInstanceLock(); const gotTheLock = app.requestSingleInstanceLock();
@@ -10,18 +10,22 @@ if (!gotTheLock) {
} }


let mainWindow; let mainWindow;
let tray = null;
function createWindow() { function createWindow() {
// Create the browser window. // Create the browser window.
mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
width: 1080,
height: 600,
minWidth: 400,
frame: false,
width: 1200,
height: 930,
minWidth: 1200,
minHeight: 930,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
// javascript: true, // javascript: true,
// plugins: true, // plugins: true,
preload: path.join(__dirname, './', 'preload.js'), preload: path.join(__dirname, './', 'preload.js'),
}, },
icon: path.join(__dirname, 'logo.ico'),
// frame: false, // frame: false,
}) })
// and load the index.html of the app. // and load the index.html of the app.
@@ -34,8 +38,10 @@ function createWindow() {
mainWindow.setMenuBarVisibility(false); mainWindow.setMenuBarVisibility(false);
// Open the DevTools. // Open the DevTools.
// mainWindow.webContents.openDevTools() // mainWindow.webContents.openDevTools()
mainWindow.maximize();
//mainWindow.maximize();


// 返回应用默认的session对象
// const ses = mainWindow.webContents.session;
// 当窗口已经关闭的时候触发 // 当窗口已经关闭的时候触发
mainWindow.on('closed', (event) => { mainWindow.on('closed', (event) => {
mainWindow = null; mainWindow = null;
@@ -47,16 +53,16 @@ function createWindow() {
event.preventDefault(); event.preventDefault();
}); });


mainWindow.on('show', () => {
tray.setHighlightMode('always')
})
mainWindow.on('hide', () => {
tray.setHighlightMode('never')
})
// mainWindow.on('show', () => {
// tray.setHighlightMode('always')
// })
// mainWindow.on('hide', () => {
// tray.setHighlightMode('never')
// })


// 创建系统通知区菜单 // 创建系统通知区菜单
tray = new Tray(path.join(__dirname, 'file_word.png'));
const contextMenu = Menu.buildFromTemplate([
tray = new Tray(path.join(__dirname, 'logo.ico'));
const contextMenu = Menu.buildFromTemplate([
{label: '最大化', click: () => { mainWindow.maximize()}}, {label: '最大化', click: () => { mainWindow.maximize()}},
{label: '最小化', click: () => {mainWindow.minimize()}}, {label: '最小化', click: () => {mainWindow.minimize()}},
{label: '还原', click: () => {mainWindow.restore()}}, {label: '还原', click: () => {mainWindow.restore()}},


Načítá se…
Zrušit
Uložit