This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
84 lines (72 loc) · 2.16 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
/**
* main.js
* Author: cmlin
*/
const path = require('path');
const electron = require('electron');
const http = require('http');
const BrowserWindow = electron.BrowserWindow;
const Tray = electron.Tray;
const Menu = electron.Menu;
const app = electron.app;
const debug = false;
let mainWindow = null;
let appIcon = null;
let configName = "config.json";
app.setName('复旦校园网自动连接工具');
function initialize() {
function createWindow() {
var windowOptions = {
width: 600,
height: 400,
maximizable: false,
center: true,
resizable: false,
useContentSize: true,
title: app.getName()
};
mainWindow = new BrowserWindow(windowOptions);
mainWindow.setMenu(null);
mainWindow.loadURL(path.join('file://', __dirname, '/index.html'));
if (debug) {
mainWindow.webContents.openDevTools();
}
mainWindow.on('closed', function () {
mainWindow = null;
});
mainWindow.on('close', function(e) {
mainWindow.hide();
e.preventDefault();
});
}
function createTray() {
const iconName = 'windows-icon.png';
const iconPath = path.join(__dirname, iconName);
appIcon = new Tray(iconPath);
appIcon.setToolTip('复旦校园网自动连接工具');
appIcon.on('click', () => {
mainWindow.isVisible() ? mainWindow.hide() : mainWindow.show()
});
const trayMenu = Menu.buildFromTemplate([
{label: '显示', click: function() { mainWindow.show(); }},
{label: '退出', click: function() { mainWindow.destroy(); appIcon.destroy(); }}
]);
appIcon.setContextMenu(trayMenu);
}
app.on('ready', function () {
createWindow();
createTray();
});
app.on('window-all-closed', function () {
if (appIcon) appIcon.destroy();
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', function () {
if (mainWindow === null) {
createWindow();
}
});
}
initialize();