-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
133 lines (130 loc) · 4.39 KB
/
Copy pathmain.js
File metadata and controls
133 lines (130 loc) · 4.39 KB
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
import { app, BrowserWindow, Menu, dialog, shell } from 'electron';
import * as path from 'path';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import log from 'electron-log';
import electronUpdater from 'electron-updater';
const { autoUpdater } = electronUpdater;
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
let mainWindow;
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'info';
autoUpdater.logger.transports.console.level = 'info';
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
enableRemoteModule: false,
nodeIntegration: false
}
});
mainWindow.loadFile(path.join(__dirname, 'dist/index.html'));
const menu = Menu.buildFromTemplate([
{
label: '文件',
submenu: [
{ role: 'quit', label: '退出' }
]
},
{
label: '编辑',
submenu: [
{ role: 'undo', label: '撤销' },
{ role: 'redo', label: '重做' },
{ type: 'separator' },
{ role: 'cut', label: '剪切' },
{ role: 'copy', label: '复制' },
{ role: 'paste', label: '粘贴' },
{ role: 'selectAll', label: '全选' }
]
},
{
label: '帮助',
submenu: [
{
label: '关于',
click: () => {
const appVersion = app.getVersion();
dialog.showMessageBox({
type: 'info',
title: '关于此应用',
message: `版本:${appVersion}\n谢谢关注。`,
detail: '联系方式:zzchun12826@gmail.com\n微信号:zzchun12826',
buttons: ['确定']
});
}
},
{
label: '检查更新',
click: () => {
autoUpdater.setFeedURL('https://mirror.ghproxy.com/https://github.com/jianzhichun/useflow-release/releases/latest/download/');
autoUpdater.checkForUpdates();
}
}
]
}
]);
Menu.setApplicationMenu(menu);
autoUpdater.on('update-available', (info) => {
dialog.showMessageBox({
type: 'info',
title: '更新可用',
message: '有新版本可用,您现在要更新吗?',
buttons: ['立即更新', '稍后'],
defaultId: 0,
cancelId: 1,
}).then((result) => {
if (result.response === 0) {
autoUpdater.downloadUpdate();
}
})
});
autoUpdater.on('download-progress', (progressObj) => {
const percent = Math.round(progressObj.percent);
mainWindow.webContents.send('update-progress', { percent });
});
autoUpdater.on('update-downloaded', (info) => {
if (process.platform === 'darwin') {
dialog.showMessageBox({
type: 'info',
title: '更新安装包下载完成',
message: '打开下载目录?',
buttons: ['打开', '稍后'],
defaultId: 0,
cancelId: 1,
}).then((result) => {
if (result.response === 0) {
const downloadDir = path.dirname(info.downloadedFile);
shell.showItemInFolder(downloadDir);
}
});
} else {
autoUpdater.quitAndInstall();
}
});
autoUpdater.on('update-not-available', (info) => {
dialog.showMessageBox({
type: 'info',
title: '没有可用更新',
message: '当前版本已是最新版本。'
});
});
autoUpdater.on('error', (err) => {
log.error('更新错误:', err);
});
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});