-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
149 lines (125 loc) · 3.9 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// 导入electron的app和BrowserWindow模块
const { app, BrowserWindow, ipcMain, Menu } = require("electron");
// 需在当前文件内开头引入 Node.js 的 'path' 模块
const path = require("path");
const createWindow = () => {
Menu.setApplicationMenu(null);
const win = new BrowserWindow({
show: false,
backgroundColor: "#1d2427",
width: 1200,
height: 800,
minWidth: 600,
minHeight: 300,
center: true,
title: "旺旺集团一站式服务平台",
icon: path.join(__dirname, "./icon.ico"),
titleBarStyle: "hiddenInset",
titleBarOverlay: {
color: "#2f3241",
symbolColor: "#74b1be",
height: 60,
},
darkTheme: true,
hasShadow: true,
roundedCorners: true,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
nodeIntegration: true,
contextIsolation: false,
},
}); // 创建一个新的窗口
win.once("ready-to-show", () => {
win.show();
});
ipcMain.handle("ping", () => "pong");
// win.loadFile("index.html"); // 加载index.html文件
win.loadURL("http://app.shinyinfo.com.cn:31888/");
// win.loadURL('https://www.baidu.com/')
// 打开开发工具
// win.webContents.openDevTools();
};
app.whenReady().then(() => {
createWindow();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
}); // 当electron完成初始化并准备创建浏览器窗口时调用此方法
// 关闭所有窗口时退出应用
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
// 开机自启
app.setLoginItemSettings({
openAtLogin: true,
openAsHidden: true,
});
// 自动更新
require('update-electron-app')()
function setupUpdates() {
// We delay this work by 10s to ensure that the
// app doesn't have to worry about updating during launch
setTimeout(() => {
const updateApp = require('update-electron-app');
updateApp({
updateInterval: '5 minutes',
});
}, 10000);
}
if(require('electron-squirrel-startup')) return;
// this should be placed at top of main.js to handle setup events quickly
if (handleSquirrelEvent()) {
// squirrel event handled and app will exit in 1000ms, so don't do anything else
return;
}
function handleSquirrelEvent() {
if (process.argv.length === 1) {
return false;
}
const ChildProcess = require('child_process');
const path = require('path');
const appFolder = path.resolve(process.execPath, '..');
const rootAtomFolder = path.resolve(appFolder, '..');
const updateDotExe = path.resolve(path.join(rootAtomFolder, 'Update.exe'));
const exeName = path.basename(process.execPath);
const spawn = function(command, args) {
let spawnedProcess, error;
try {
spawnedProcess = ChildProcess.spawn(command, args, {detached: true});
} catch (error) {}
return spawnedProcess;
};
const spawnUpdate = function(args) {
return spawn(updateDotExe, args);
};
const squirrelEvent = process.argv[1];
switch (squirrelEvent) {
case '--squirrel-install':
case '--squirrel-updated':
// Optionally do things such as:
// - Add your .exe to the PATH
// - Write to the registry for things like file associations and
// explorer context menus
// Install desktop and start menu shortcuts
spawnUpdate(['--createShortcut', exeName]);
setTimeout(app.quit, 1000);
return true;
case '--squirrel-uninstall':
// Undo anything you did in the --squirrel-install and
// --squirrel-updated handlers
// Remove desktop and start menu shortcuts
spawnUpdate(['--removeShortcut', exeName]);
setTimeout(app.quit, 1000);
return true;
case '--squirrel-obsolete':
// This is called on the outgoing version of your app before
// we update to the new version - it's the opposite of
// --squirrel-updated
app.quit();
return true;
}
};