This repository has been archived by the owner on Dec 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
152 lines (135 loc) · 3.75 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
150
151
152
const { shell, app, BrowserWindow, Menu } = require('electron');
const path = require('path');
const contextMenu = require('electron-context-menu');
const fs = require('fs');
const package = require('./package.json');
var appData = {};
contextMenu({
labels: {
copy: '复制',
cut: '剪切',
paste: '粘贴',
},
showSelectAll: false,
showSearchWithGoogle: false,
showInspectElement: false,
prepend: (defaultActions, parameters, browserWindow) => [
{
label: '刷新',
// Only show it when right-clicking images
click: () => {
browserWindow.webContents.reload();
}
},
],
})
fs.readFile(path.join(__dirname, 'appData.json'), 'utf-8', (err, data) => {
if (err) {
console.log(err);
app.quit();
}
try {
appData = JSON.parse(data);
}
catch (err) {
console.log(err);
app.quit();
}
app.setAboutPanelOptions({
applicationName: appData.title,
applicationVersion: 'v' + package.version,
copyright: appData.copyright,
authors: appData.authors,
})
})
const template = [
{
label: '菜单',
submenu: [
{
label: '刷新',
role: 'reload'
},
{
label: '强制刷新',
role: 'forceReload'
},
{
label: '切换全屏',
role: 'togglefullscreen'
},
{
label: '退出',
role: 'quit'
}
]
},
{
label: '应用信息',
submenu: [
{
label: '当前版本:v' + package.version
},
{
label: '从gitee更新',
click: () => {
shell.openExternal(appData.gitee);
}
},
{
label: '从github更新',
click: () => {
shell.openExternal(appData.github);
}
},
{
type: 'separator'
},
{
label: '关于',
role: 'about'
}
]
}
];
const createMainWindow = () => {
const mainWindow = new BrowserWindow({
show: false,
icon: path.join(__dirname, 'logo.ico'),
title: appData.title,
titleBarStyle: 'hiddenInset',
useContentSize: true,
webPreferences: {
// preload: path.join(__dirname, 'preload.js'),
devTools: false,
}
})
mainWindow.maximize();
mainWindow.webContents.setWindowOpenHandler((edata) => {
shell.openExternal(edata.url);
return { action: "deny" };
});
mainWindow.loadFile('index.html');
mainWindow.once('ready-to-show', () => {
mainWindow.show();
})
};
app.whenReady().then(() => {
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
createMainWindow();
// 在 macOS 系统内, 如果没有已开启的应用窗口
// 点击托盘图标时通常会重新创建一个新窗口
app.on('activate', () => {
// 在 macOS 系统内, 如果没有已开启的应用窗口
// 点击托盘图标时通常会重新创建一个新窗口
if (BrowserWindow.getAllWindows().length === 0) createMainWindow()
});
});
// 除了 macOS 外,当所有窗口都被关闭的时候退出程序。 因此, 通常
// 对应用程序和它们的菜单栏来说应该时刻保持激活状态,
// 直到用户使用 Cmd + Q 明确退出
app.on('window-all-closed', () => {
if (process.platform !== 'darwin')
app.quit();
});