electron-version-deployer-cli 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +1 -1
- package/dist/main.d.ts +2 -1
- package/dist/{main.cjs.js → main.js} +15 -16
- package/dist/templates/newVersionDialog.html +148 -140
- package/package.json +4 -2
- package/dist/main.es.js +0 -306
package/dist/cli.cjs
CHANGED
|
@@ -493,4 +493,4 @@ async function installPrebuilt(configs) {
|
|
|
493
493
|
}
|
|
494
494
|
commander.program.description(
|
|
495
495
|
"Electron 版本部署 CLI,简化你的 Electron 软件更新,让一切变得简单。"
|
|
496
|
-
).helpOption("-h, --help", "使用帮助").version("0.0.
|
|
496
|
+
).helpOption("-h, --help", "使用帮助").version("0.0.3", "-V, --version", "显示版本号").parse(process.argv);
|
package/dist/main.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ export declare enum EVDEventEnum {
|
|
|
2
2
|
OPEN_LINK = "evd-open-link",
|
|
3
3
|
UPDATE = "evd-update-now",
|
|
4
4
|
SKIP = "evd-skip",
|
|
5
|
-
GET_CHANGELOGS = "evd-get-change-logs"
|
|
5
|
+
GET_CHANGELOGS = "evd-get-change-logs",
|
|
6
|
+
GET_LOGO = "evd-get-logo"
|
|
6
7
|
}
|
|
7
8
|
type EVDInitPropsType = {
|
|
8
9
|
netlifyUrl: string;
|
|
@@ -74,6 +74,7 @@ var EVDEventEnum = /* @__PURE__ */ ((EVDEventEnum2) => {
|
|
|
74
74
|
EVDEventEnum2["UPDATE"] = "evd-update-now";
|
|
75
75
|
EVDEventEnum2["SKIP"] = "evd-skip";
|
|
76
76
|
EVDEventEnum2["GET_CHANGELOGS"] = "evd-get-change-logs";
|
|
77
|
+
EVDEventEnum2["GET_LOGO"] = "evd-get-logo";
|
|
77
78
|
return EVDEventEnum2;
|
|
78
79
|
})(EVDEventEnum || {});
|
|
79
80
|
let globalArgs = null;
|
|
@@ -167,7 +168,7 @@ async function showNewVersionDialog() {
|
|
|
167
168
|
});
|
|
168
169
|
}
|
|
169
170
|
async function installNewVersion() {
|
|
170
|
-
const { netlifyUrl } = getConfigs();
|
|
171
|
+
const { netlifyUrl, onError } = getConfigs();
|
|
171
172
|
const remoteJSON = await fetchRemotePkgJSON(netlifyUrl);
|
|
172
173
|
const needInstallFullSize = compareObjectsIsEqual(
|
|
173
174
|
remoteJSON.dependencies,
|
|
@@ -176,21 +177,7 @@ async function installNewVersion() {
|
|
|
176
177
|
try {
|
|
177
178
|
await installPkg(needInstallFullSize ? "fullCode.zip" : "logicCode.zip");
|
|
178
179
|
} catch (error) {
|
|
179
|
-
|
|
180
|
-
node_path.join(electron.app.getPath("userData"), "evd-runtime-error.txt"),
|
|
181
|
-
`
|
|
182
|
-
${(/* @__PURE__ */ new Date()).toString()}
|
|
183
|
-
|
|
184
|
-
${error.toString()}
|
|
185
|
-
|
|
186
|
-
-- stack
|
|
187
|
-
|
|
188
|
-
${error.stack}
|
|
189
|
-
|
|
190
|
-
----------------------------------------------------------------
|
|
191
|
-
|
|
192
|
-
`
|
|
193
|
-
);
|
|
180
|
+
onError(error);
|
|
194
181
|
}
|
|
195
182
|
}
|
|
196
183
|
async function installPkg(zipFile) {
|
|
@@ -223,6 +210,7 @@ async function installPkg(zipFile) {
|
|
|
223
210
|
await new Promise((res) => setTimeout(res, 1e3));
|
|
224
211
|
}
|
|
225
212
|
function bindEvent(promptWindow) {
|
|
213
|
+
const { logo } = getConfigs();
|
|
226
214
|
electron.ipcMain.on("evd-open-link", (_, link) => {
|
|
227
215
|
electron.shell.openExternal(link);
|
|
228
216
|
});
|
|
@@ -237,6 +225,9 @@ function bindEvent(promptWindow) {
|
|
|
237
225
|
electron.app.exit();
|
|
238
226
|
});
|
|
239
227
|
});
|
|
228
|
+
electron.ipcMain.handle("evd-get-logo", () => {
|
|
229
|
+
return logo;
|
|
230
|
+
});
|
|
240
231
|
electron.ipcMain.handle("evd-get-change-logs", async () => {
|
|
241
232
|
const { netlifyUrl } = getConfigs();
|
|
242
233
|
return await fetchRemoteChangelogJSON(netlifyUrl);
|
|
@@ -255,6 +246,14 @@ function cleanup(promptWindow) {
|
|
|
255
246
|
"evd-update-now"
|
|
256
247
|
/* UPDATE */
|
|
257
248
|
);
|
|
249
|
+
electron.ipcMain.removeHandler(
|
|
250
|
+
"evd-get-change-logs"
|
|
251
|
+
/* GET_CHANGELOGS */
|
|
252
|
+
);
|
|
253
|
+
electron.ipcMain.removeHandler(
|
|
254
|
+
"evd-get-logo"
|
|
255
|
+
/* GET_LOGO */
|
|
256
|
+
);
|
|
258
257
|
promptWindow == null ? void 0 : promptWindow.focus();
|
|
259
258
|
if (promptWindow) {
|
|
260
259
|
promptWindow.destroy();
|
|
@@ -1,163 +1,171 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="zh">
|
|
3
|
-
<head>
|
|
3
|
+
<head>
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
name="viewport"
|
|
7
|
+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
|
|
8
8
|
/>
|
|
9
9
|
<link
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
rel="icon"
|
|
11
|
+
type="image/png"
|
|
12
|
+
sizes="32x32"
|
|
13
|
+
href="https://chat.openai.com/favicon-32x32.png"
|
|
14
14
|
/>
|
|
15
15
|
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
|
16
16
|
<title>有可用的更新 (4.3.5)</title>
|
|
17
17
|
<style>
|
|
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
|
-
|
|
18
|
+
* {
|
|
19
|
+
margin: 0;
|
|
20
|
+
padding: 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
body {
|
|
24
|
+
font-family: -apple-system, Helvetica, Arial, sans-serif,
|
|
25
|
+
"Microsoft YaHei", "ST Heiti";
|
|
26
|
+
color: #333;
|
|
27
|
+
padding: 20px;
|
|
28
|
+
background-color: #f5f5f5;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.title {
|
|
32
|
+
font-size: 18px;
|
|
33
|
+
font-weight: bold;
|
|
34
|
+
margin-bottom: 10px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.content {
|
|
38
|
+
margin-top: 8px;
|
|
39
|
+
margin-bottom: 12px;
|
|
40
|
+
margin-left: -20px;
|
|
41
|
+
margin-right: -20px;
|
|
42
|
+
height: 200px;
|
|
43
|
+
overflow: auto;
|
|
44
|
+
padding: 0 20px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.content ul {
|
|
48
|
+
padding-left: 20px;
|
|
49
|
+
margin-top: 5px;
|
|
50
|
+
margin-bottom: 10px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.content ul li {
|
|
54
|
+
margin-bottom: 4px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.buttons-box {
|
|
58
|
+
display: flex;
|
|
59
|
+
justify-content: flex-end;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.buttons-box button {
|
|
63
|
+
padding: 10px 20px;
|
|
64
|
+
font-size: 14px;
|
|
65
|
+
font-weight: bold;
|
|
66
|
+
border-radius: 5px;
|
|
67
|
+
border: none;
|
|
68
|
+
cursor: pointer;
|
|
69
|
+
margin-left: 12px;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.buttons-box button:first-child {
|
|
73
|
+
background-color: #007bff;
|
|
74
|
+
color: #fff;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.buttons-box button:last-child {
|
|
78
|
+
background-color: #ccc;
|
|
79
|
+
color: #333;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.buttons-box button:first-child:hover {
|
|
83
|
+
background-color: #0056b3;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.buttons-box button:last-child:hover {
|
|
87
|
+
background-color: #b3b3b3;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.title-bar {
|
|
91
|
+
display: flex;
|
|
92
|
+
flex-direction: row;
|
|
93
|
+
justify-content: flex-start;
|
|
94
|
+
align-items: center;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.title-bar img {
|
|
98
|
+
margin-right: 8px;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.loading-box {
|
|
102
|
+
position: fixed;
|
|
103
|
+
left: 0;
|
|
104
|
+
top: 0;
|
|
105
|
+
bottom: 0;
|
|
106
|
+
right: 0;
|
|
107
|
+
background: rgba(255, 255, 255, 0.9);
|
|
108
|
+
font-size: 18px;
|
|
109
|
+
flex-direction: row;
|
|
110
|
+
align-items: center;
|
|
111
|
+
justify-content: center;
|
|
112
|
+
display: none;
|
|
113
|
+
font-weight: bold;
|
|
114
|
+
}
|
|
115
|
+
</style>
|
|
116
|
+
</head>
|
|
117
|
+
<body>
|
|
118
|
+
<div class="loading-box">软件更新中……</div>
|
|
119
|
+
<div class="title-bar">
|
|
120
|
+
<img src="" width="28" class="logo" style="display: none" />
|
|
121
|
+
<span>有可用的新版本:</span>
|
|
122
|
+
</div>
|
|
123
|
+
<div class="content">具体更新内容请查看 Changelogs</div>
|
|
124
|
+
<div class="buttons-box">
|
|
125
|
+
<button id="updateBtn">现在更新</button>
|
|
126
|
+
<button id="skipBtn">稍后再提醒我</button>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<script>
|
|
130
|
+
const { ipcRenderer } = require("electron");
|
|
131
|
+
|
|
132
|
+
document.querySelector("#updateBtn").addEventListener("click", () => {
|
|
133
|
+
ipcRenderer.send("evd-update-now");
|
|
134
|
+
document.querySelector(".loading-box").style.display = "flex";
|
|
135
|
+
});
|
|
81
136
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
137
|
+
document.querySelector("#skipBtn").addEventListener("click", () => {
|
|
138
|
+
ipcRenderer.send("evd-skip");
|
|
139
|
+
});
|
|
85
140
|
|
|
86
|
-
|
|
87
|
-
|
|
141
|
+
ipcRenderer.invoke("evd-get-logo").then((link) => {
|
|
142
|
+
if (link) {
|
|
143
|
+
const imgRef = document.querySelector(".logo");
|
|
144
|
+
imgRef.src = link;
|
|
145
|
+
imgRef.style.display = "inline-block";
|
|
88
146
|
}
|
|
147
|
+
});
|
|
89
148
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
justify-content: flex-start;
|
|
94
|
-
align-items: center;
|
|
95
|
-
}
|
|
149
|
+
ipcRenderer.invoke("evd-get-change-logs").then((data) => {
|
|
150
|
+
// 如果没有数据就不渲染
|
|
151
|
+
if (!data) return;
|
|
96
152
|
|
|
97
|
-
|
|
98
|
-
margin-right: 8px;
|
|
99
|
-
}
|
|
153
|
+
const contentRef = document.querySelector(".content");
|
|
100
154
|
|
|
101
|
-
.
|
|
102
|
-
position: fixed;
|
|
103
|
-
left: 0;
|
|
104
|
-
top: 0;
|
|
105
|
-
bottom: 0;
|
|
106
|
-
right: 0;
|
|
107
|
-
background: rgba(255, 255, 255, 0.9);
|
|
108
|
-
font-size: 18px;
|
|
109
|
-
flex-direction: row;
|
|
110
|
-
align-items: center;
|
|
111
|
-
justify-content: center;
|
|
112
|
-
display: none;
|
|
113
|
-
font-weight: bold;
|
|
114
|
-
}
|
|
115
|
-
</style>
|
|
116
|
-
</head>
|
|
117
|
-
<body>
|
|
118
|
-
<div class="loading-box">软件更新中……</div>
|
|
119
|
-
<div class="title-bar">
|
|
120
|
-
<img src="https://chat.openai.com/favicon-32x32.png" width="28" alt="" />
|
|
121
|
-
<span>有可用的新版本:</span>
|
|
122
|
-
</div>
|
|
123
|
-
<div class="content">具体更新内容请查看 Changelogs</div>
|
|
124
|
-
<div class="buttons-box">
|
|
125
|
-
<button id="updateBtn">现在更新</button>
|
|
126
|
-
<button id="skipBtn">稍后再提醒我</button>
|
|
127
|
-
</div>
|
|
128
|
-
|
|
129
|
-
<script>
|
|
130
|
-
const { ipcRenderer } = require("electron");
|
|
131
|
-
|
|
132
|
-
document.querySelector("#updateBtn").addEventListener("click", () => {
|
|
133
|
-
ipcRenderer.send("evd-update-now");
|
|
134
|
-
document.querySelector(".loading-box").style.display = "flex";
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
document.querySelector("#skipBtn").addEventListener("click", () => {
|
|
138
|
-
ipcRenderer.send("evd-skip");
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
ipcRenderer.invoke("evd-get-change-logs").then((data) => {
|
|
142
|
-
// 如果没有数据就不渲染
|
|
143
|
-
if (!data) return;
|
|
144
|
-
|
|
145
|
-
const contentRef = document.querySelector(".content");
|
|
146
|
-
|
|
147
|
-
contentRef.innerHTML = `
|
|
155
|
+
contentRef.innerHTML = `
|
|
148
156
|
<p class="title">${data.title}</p>
|
|
149
157
|
${data.changes}
|
|
150
158
|
`;
|
|
151
159
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
160
|
+
// 监听所有 A 链接点击
|
|
161
|
+
Array.from(document.querySelectorAll("a")).map((a) => {
|
|
162
|
+
a.addEventListener("click", (ev) => {
|
|
163
|
+
ev.preventDefault();
|
|
156
164
|
|
|
157
|
-
|
|
165
|
+
ipcRenderer.send("evd-open-link", ev.target.href);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
158
168
|
});
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
</script>
|
|
162
|
-
</body>
|
|
169
|
+
</script>
|
|
170
|
+
</body>
|
|
163
171
|
</html>
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-version-deployer-cli",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"main": "./dist/index.cjs.js",
|
|
7
7
|
"module": "./dist/index.es.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"serve": "esno ./watch.ts",
|
|
10
|
-
"build": "MODE=production esno ./watch.ts && tsc -p ./tsconfig.dist.json -emitDeclarationOnly && tsc-alias -p ./tsconfig.dist.json"
|
|
10
|
+
"build": "MODE=production esno ./watch.ts && tsc -p ./tsconfig.dist.json -emitDeclarationOnly && tsc-alias -p ./tsconfig.dist.json",
|
|
11
|
+
"format": "npx prettier --write \"**/*.{js,mjs,cjs,ts,tsx,jsx,json,html}\"",
|
|
12
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
11
13
|
},
|
|
12
14
|
"bin": {
|
|
13
15
|
"evd": "./dist/cli.cjs"
|
package/dist/main.es.js
DELETED
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
import { app, BrowserWindow, ipcMain, shell } from "electron";
|
|
2
|
-
import { format } from "node:url";
|
|
3
|
-
import { join, basename } from "node:path";
|
|
4
|
-
import { get } from "node:https";
|
|
5
|
-
import { readFileSync, appendFileSync, existsSync, rmSync, mkdirSync, createWriteStream, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
6
|
-
import extract from "extract-zip";
|
|
7
|
-
function fetchRemoteChangelogJSON(remote_url) {
|
|
8
|
-
return new Promise((res, rej) => {
|
|
9
|
-
get(`${remote_url}/changelog.json`, (_res) => {
|
|
10
|
-
let data = "";
|
|
11
|
-
_res.on("data", (chunk) => {
|
|
12
|
-
data += chunk;
|
|
13
|
-
});
|
|
14
|
-
_res.on("end", () => {
|
|
15
|
-
try {
|
|
16
|
-
res(JSON.parse(data));
|
|
17
|
-
} catch (e) {
|
|
18
|
-
res(null);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}).on("error", (err) => {
|
|
22
|
-
rej(`获取 changelog.json 失败:` + err.toString());
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
function fetchRemotePkgJSON(remote_url) {
|
|
27
|
-
return new Promise((res, rej) => {
|
|
28
|
-
get(`${remote_url}/package.json`, (_res) => {
|
|
29
|
-
let data = "";
|
|
30
|
-
_res.on("data", (chunk) => {
|
|
31
|
-
data += chunk;
|
|
32
|
-
});
|
|
33
|
-
_res.on("end", () => {
|
|
34
|
-
try {
|
|
35
|
-
res(JSON.parse(data));
|
|
36
|
-
} catch (e) {
|
|
37
|
-
res(null);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}).on("error", (err) => {
|
|
41
|
-
rej(`自动更新检查请求失败:` + err.toString());
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
function versionToNum(a) {
|
|
46
|
-
let c = a.split(".");
|
|
47
|
-
let num_place = ["", "0", "00", "000", "0000"], r = num_place.reverse();
|
|
48
|
-
for (let i = 0; i < c.length; i++) {
|
|
49
|
-
let len = c[i].length;
|
|
50
|
-
c[i] = r[len] + c[i];
|
|
51
|
-
}
|
|
52
|
-
let res = c.join("");
|
|
53
|
-
return res;
|
|
54
|
-
}
|
|
55
|
-
function compareObjectsIsEqual(obj1, obj2) {
|
|
56
|
-
const keys1 = Object.keys(obj1);
|
|
57
|
-
const keys2 = Object.keys(obj2);
|
|
58
|
-
if (keys1.length !== keys2.length) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
for (let key of keys1) {
|
|
62
|
-
if (obj1[key] !== obj2[key]) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
const CLI_NAME = "electron-version-deployer-cli";
|
|
69
|
-
const id = `${Date.now()}-${Math.random()}`;
|
|
70
|
-
var EVDEventEnum = /* @__PURE__ */ ((EVDEventEnum2) => {
|
|
71
|
-
EVDEventEnum2["OPEN_LINK"] = "evd-open-link";
|
|
72
|
-
EVDEventEnum2["UPDATE"] = "evd-update-now";
|
|
73
|
-
EVDEventEnum2["SKIP"] = "evd-skip";
|
|
74
|
-
EVDEventEnum2["GET_CHANGELOGS"] = "evd-get-change-logs";
|
|
75
|
-
return EVDEventEnum2;
|
|
76
|
-
})(EVDEventEnum || {});
|
|
77
|
-
let globalArgs = null;
|
|
78
|
-
let cacheCurrentPkgJSON = null;
|
|
79
|
-
function EVDInit(props) {
|
|
80
|
-
globalArgs = props;
|
|
81
|
-
const { detectionFrequency, detectAtStart, onError } = getConfigs();
|
|
82
|
-
setInterval(async () => {
|
|
83
|
-
try {
|
|
84
|
-
await EVDCheckUpdate();
|
|
85
|
-
} catch (e) {
|
|
86
|
-
onError(e);
|
|
87
|
-
}
|
|
88
|
-
}, 1e3 * detectionFrequency);
|
|
89
|
-
if (!detectAtStart)
|
|
90
|
-
return;
|
|
91
|
-
setTimeout(async () => {
|
|
92
|
-
try {
|
|
93
|
-
await EVDCheckUpdate();
|
|
94
|
-
} catch (e) {
|
|
95
|
-
onError(e);
|
|
96
|
-
}
|
|
97
|
-
}, 1e3 * 2);
|
|
98
|
-
const appPath = app.getAppPath();
|
|
99
|
-
cacheCurrentPkgJSON = JSON.parse(
|
|
100
|
-
readFileSync(join(appPath, "package.json"), "utf-8")
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
async function EVDCheckUpdate() {
|
|
104
|
-
const { netlifyUrl } = getConfigs();
|
|
105
|
-
const { version } = cacheCurrentPkgJSON;
|
|
106
|
-
const remoteJSON = await fetchRemotePkgJSON(netlifyUrl);
|
|
107
|
-
if (!remoteJSON)
|
|
108
|
-
throw new Error(`${netlifyUrl}package.json 文件不存在`);
|
|
109
|
-
const localVersion = versionToNum(version);
|
|
110
|
-
const remoteVersion = versionToNum(remoteJSON.version);
|
|
111
|
-
if (remoteVersion > localVersion) {
|
|
112
|
-
await showNewVersionDialog();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
async function showNewVersionDialog() {
|
|
116
|
-
const { windowHeight, windowWidth, onError } = getConfigs();
|
|
117
|
-
app.whenReady().then(async () => {
|
|
118
|
-
try {
|
|
119
|
-
let promptWindow = new BrowserWindow({
|
|
120
|
-
frame: true,
|
|
121
|
-
width: windowWidth,
|
|
122
|
-
height: windowHeight,
|
|
123
|
-
minWidth: windowWidth,
|
|
124
|
-
minHeight: windowHeight,
|
|
125
|
-
resizable: false,
|
|
126
|
-
minimizable: true,
|
|
127
|
-
fullscreenable: false,
|
|
128
|
-
maximizable: false,
|
|
129
|
-
skipTaskbar: true,
|
|
130
|
-
alwaysOnTop: true,
|
|
131
|
-
useContentSize: false,
|
|
132
|
-
title: "有可用的更新",
|
|
133
|
-
webPreferences: {
|
|
134
|
-
nodeIntegration: true,
|
|
135
|
-
contextIsolation: false
|
|
136
|
-
},
|
|
137
|
-
show: false
|
|
138
|
-
});
|
|
139
|
-
promptWindow.setMenu(null);
|
|
140
|
-
promptWindow.setMenuBarVisibility(false);
|
|
141
|
-
const promptUrl = format({
|
|
142
|
-
protocol: "file",
|
|
143
|
-
slashes: true,
|
|
144
|
-
pathname: join(
|
|
145
|
-
app.getAppPath(),
|
|
146
|
-
"node_modules",
|
|
147
|
-
CLI_NAME,
|
|
148
|
-
"dist",
|
|
149
|
-
"templates",
|
|
150
|
-
"newVersionDialog.html"
|
|
151
|
-
),
|
|
152
|
-
hash: id
|
|
153
|
-
});
|
|
154
|
-
promptWindow.loadURL(promptUrl);
|
|
155
|
-
promptWindow.once("ready-to-show", () => {
|
|
156
|
-
promptWindow.show();
|
|
157
|
-
});
|
|
158
|
-
promptWindow.once("close", () => {
|
|
159
|
-
cleanup(promptWindow);
|
|
160
|
-
});
|
|
161
|
-
bindEvent(promptWindow);
|
|
162
|
-
} catch (e) {
|
|
163
|
-
onError(e);
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
async function installNewVersion() {
|
|
168
|
-
const { netlifyUrl } = getConfigs();
|
|
169
|
-
const remoteJSON = await fetchRemotePkgJSON(netlifyUrl);
|
|
170
|
-
const needInstallFullSize = compareObjectsIsEqual(
|
|
171
|
-
remoteJSON.dependencies,
|
|
172
|
-
cacheCurrentPkgJSON.dependencies
|
|
173
|
-
);
|
|
174
|
-
try {
|
|
175
|
-
await installPkg(needInstallFullSize ? "fullCode.zip" : "logicCode.zip");
|
|
176
|
-
} catch (error) {
|
|
177
|
-
appendFileSync(
|
|
178
|
-
join(app.getPath("userData"), "evd-runtime-error.txt"),
|
|
179
|
-
`
|
|
180
|
-
${(/* @__PURE__ */ new Date()).toString()}
|
|
181
|
-
|
|
182
|
-
${error.toString()}
|
|
183
|
-
|
|
184
|
-
-- stack
|
|
185
|
-
|
|
186
|
-
${error.stack}
|
|
187
|
-
|
|
188
|
-
----------------------------------------------------------------
|
|
189
|
-
|
|
190
|
-
`
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
async function installPkg(zipFile) {
|
|
195
|
-
const { netlifyUrl } = getConfigs();
|
|
196
|
-
const appPath = app.getAppPath();
|
|
197
|
-
const unzipPath = join(appPath, "evdUnzip");
|
|
198
|
-
if (existsSync(unzipPath)) {
|
|
199
|
-
rmSync(unzipPath, {
|
|
200
|
-
force: true,
|
|
201
|
-
maxRetries: 3,
|
|
202
|
-
recursive: true
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
mkdirSync(unzipPath);
|
|
206
|
-
const tmpZipFilePath = createWriteStream(unzipPath + ".zip");
|
|
207
|
-
await new Promise(
|
|
208
|
-
(res, rej) => get(`${netlifyUrl}/${zipFile}`, (response) => {
|
|
209
|
-
response.pipe(tmpZipFilePath).on("finish", () => {
|
|
210
|
-
res();
|
|
211
|
-
}).on("error", (err) => {
|
|
212
|
-
rej(err);
|
|
213
|
-
});
|
|
214
|
-
}).on("error", (err) => {
|
|
215
|
-
rej(err);
|
|
216
|
-
})
|
|
217
|
-
);
|
|
218
|
-
await extract(unzipPath + ".zip", { dir: unzipPath });
|
|
219
|
-
await new Promise((res) => setTimeout(res, 1e3));
|
|
220
|
-
copyFolderRecursiveSync(unzipPath, appPath);
|
|
221
|
-
await new Promise((res) => setTimeout(res, 1e3));
|
|
222
|
-
}
|
|
223
|
-
function bindEvent(promptWindow) {
|
|
224
|
-
ipcMain.on("evd-open-link", (_, link) => {
|
|
225
|
-
shell.openExternal(link);
|
|
226
|
-
});
|
|
227
|
-
ipcMain.on("evd-skip", (_) => {
|
|
228
|
-
promptWindow.close();
|
|
229
|
-
});
|
|
230
|
-
ipcMain.on("evd-update-now", (_) => {
|
|
231
|
-
installNewVersion().then(() => {
|
|
232
|
-
console.log(222);
|
|
233
|
-
promptWindow.close();
|
|
234
|
-
app.relaunch();
|
|
235
|
-
app.exit();
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
ipcMain.handle("evd-get-change-logs", async () => {
|
|
239
|
-
const { netlifyUrl } = getConfigs();
|
|
240
|
-
return await fetchRemoteChangelogJSON(netlifyUrl);
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
function cleanup(promptWindow) {
|
|
244
|
-
ipcMain.removeAllListeners(
|
|
245
|
-
"evd-open-link"
|
|
246
|
-
/* OPEN_LINK */
|
|
247
|
-
);
|
|
248
|
-
ipcMain.removeAllListeners(
|
|
249
|
-
"evd-skip"
|
|
250
|
-
/* SKIP */
|
|
251
|
-
);
|
|
252
|
-
ipcMain.removeAllListeners(
|
|
253
|
-
"evd-update-now"
|
|
254
|
-
/* UPDATE */
|
|
255
|
-
);
|
|
256
|
-
promptWindow == null ? void 0 : promptWindow.focus();
|
|
257
|
-
if (promptWindow) {
|
|
258
|
-
promptWindow.destroy();
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
function getConfigs() {
|
|
262
|
-
if (!globalArgs)
|
|
263
|
-
throw new Error("必须先执行 EVDInit 后才能继续运行!");
|
|
264
|
-
return {
|
|
265
|
-
...{
|
|
266
|
-
onError: () => {
|
|
267
|
-
},
|
|
268
|
-
windowHeight: 360,
|
|
269
|
-
windowWidth: 400,
|
|
270
|
-
logo: void 0,
|
|
271
|
-
// 默认六小时检测一次
|
|
272
|
-
detectionFrequency: 60 * 60 * 6,
|
|
273
|
-
detectAtStart: true
|
|
274
|
-
},
|
|
275
|
-
...globalArgs
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
function copyFileSync(source, target) {
|
|
279
|
-
let targetFile = target;
|
|
280
|
-
if (existsSync(target)) {
|
|
281
|
-
if (statSync(target).isDirectory()) {
|
|
282
|
-
targetFile = join(target, basename(source));
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
writeFileSync(targetFile, readFileSync(source));
|
|
286
|
-
}
|
|
287
|
-
function copyFolderRecursiveSync(source, target) {
|
|
288
|
-
if (!existsSync(target)) {
|
|
289
|
-
mkdirSync(target);
|
|
290
|
-
}
|
|
291
|
-
const files = readdirSync(source);
|
|
292
|
-
files.forEach((file) => {
|
|
293
|
-
const sourcePath = join(source, file);
|
|
294
|
-
const targetPath = join(target, file);
|
|
295
|
-
if (statSync(sourcePath).isDirectory()) {
|
|
296
|
-
copyFolderRecursiveSync(sourcePath, targetPath);
|
|
297
|
-
} else {
|
|
298
|
-
copyFileSync(sourcePath, targetPath);
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
export {
|
|
303
|
-
EVDCheckUpdate,
|
|
304
|
-
EVDEventEnum,
|
|
305
|
-
EVDInit
|
|
306
|
-
};
|