electron-incremental-update 2.0.0-beta.1 → 2.0.0-beta.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.
@@ -1,247 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
7
-
8
- // src/utils/electron.ts
9
- import { existsSync, mkdirSync, readFileSync } from "node:fs";
10
- import { dirname, join } from "node:path";
11
- import { app } from "electron";
12
- var isDev = __EIU_IS_DEV__;
13
- var isWin = process.platform === "win32";
14
- var isMac = process.platform === "darwin";
15
- var isLinux = process.platform === "linux";
16
- function getPathFromAppNameAsar(...path) {
17
- return isDev ? "DEV.asar" : join(dirname(app.getAppPath()), `${app.name}.asar`, ...path);
18
- }
19
- function getAppVersion() {
20
- return isDev ? getEntryVersion() : readFileSync(getPathFromAppNameAsar("version"), "utf-8");
21
- }
22
- function getEntryVersion() {
23
- return app.getVersion();
24
- }
25
- function requireNative(moduleName) {
26
- return __require(join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
27
- }
28
- function restartApp() {
29
- app.relaunch();
30
- app.quit();
31
- }
32
- function setAppUserModelId(id) {
33
- isWin && app.setAppUserModelId(id ?? `org.${app.name}`);
34
- }
35
- function disableHWAccForWin7() {
36
- if (__require("node:os").release().startsWith("6.1")) {
37
- app.disableHardwareAcceleration();
38
- }
39
- }
40
- function singleInstance(window) {
41
- const result = app.requestSingleInstanceLock();
42
- result ? app.on("second-instance", () => {
43
- if (window) {
44
- window.show();
45
- if (window.isMinimized()) {
46
- window.restore();
47
- }
48
- window.focus();
49
- }
50
- }) : app.quit();
51
- return result;
52
- }
53
- function setPortableAppDataPath(dirName = "data") {
54
- const portablePath = join(dirname(app.getPath("exe")), dirName);
55
- if (!existsSync(portablePath)) {
56
- mkdirSync(portablePath);
57
- }
58
- app.setPath("appData", portablePath);
59
- }
60
- function waitAppReady(timeout = 1e3) {
61
- return app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
62
- const _ = setTimeout(() => {
63
- reject(new Error("app is not ready"));
64
- }, timeout);
65
- app.whenReady().then(() => {
66
- clearTimeout(_);
67
- resolve();
68
- });
69
- });
70
- }
71
- function loadPage(win, htmlFilePath = "index.html") {
72
- isDev ? win.loadURL(process.env.VITE_DEV_SERVER_URL + htmlFilePath) : win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
73
- }
74
- function getPathFromPreload(...paths) {
75
- return isDev ? join(app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
76
- }
77
- function getPathFromPublic(...paths) {
78
- return isDev ? join(app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
79
- }
80
- function getPathFromEntryAsar(...paths) {
81
- return join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
82
- }
83
-
84
- // src/utils/zip.ts
85
- import { existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync } from "node:fs";
86
- import { brotliCompress } from "node:zlib";
87
- async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
88
- if (!existsSync2(filePath)) {
89
- throw new Error(`path to be zipped not exist: ${filePath}`);
90
- }
91
- const buffer = readFileSync2(filePath);
92
- return new Promise((resolve, reject) => {
93
- brotliCompress(buffer, (err, buffer2) => {
94
- if (err) {
95
- reject(err);
96
- }
97
- writeFileSync(targetFilePath, buffer2);
98
- resolve(null);
99
- });
100
- });
101
- }
102
-
103
- // src/utils/unzip.ts
104
- import { existsSync as existsSync3, readFileSync as readFileSync3, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
105
- import { brotliDecompress } from "node:zlib";
106
- async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
107
- if (!existsSync3(gzipPath)) {
108
- throw new Error(`path to zipped file not exist: ${gzipPath}`);
109
- }
110
- const compressedBuffer = readFileSync3(gzipPath);
111
- return new Promise((resolve, reject) => {
112
- brotliDecompress(compressedBuffer, (err, buffer) => {
113
- rmSync(gzipPath);
114
- if (err) {
115
- reject(err);
116
- }
117
- writeFileSync2(targetFilePath, buffer);
118
- resolve(null);
119
- });
120
- });
121
- }
122
-
123
- // src/utils/version.ts
124
- function handleUnexpectedErrors(callback) {
125
- process.on("uncaughtException", callback);
126
- process.on("unhandledRejection", callback);
127
- }
128
- function parseVersion(version) {
129
- const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
130
- if (!match) {
131
- throw new TypeError(`invalid version: ${version}`);
132
- }
133
- const [major, minor, patch] = match.slice(1, 4).map(Number);
134
- const ret = {
135
- major,
136
- minor,
137
- patch,
138
- stage: "",
139
- stageVersion: -1
140
- };
141
- if (match[4]) {
142
- let [stage, _v] = match[4].split(".");
143
- ret.stage = stage;
144
- ret.stageVersion = Number(_v) || -1;
145
- }
146
- if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
147
- throw new TypeError(`invalid version: ${version}`);
148
- }
149
- return ret;
150
- }
151
- function isLowerVersionDefault(oldVer, newVer) {
152
- const oldV = parseVersion(oldVer);
153
- const newV = parseVersion(newVer);
154
- function compareStrings(str1, str2) {
155
- if (str1 === "") {
156
- return str2 !== "";
157
- } else if (str2 === "") {
158
- return true;
159
- }
160
- return str1 < str2;
161
- }
162
- for (let key of Object.keys(oldV)) {
163
- if (key === "stage" && compareStrings(oldV[key], newV[key])) {
164
- return true;
165
- } else if (oldV[key] !== newV[key]) {
166
- return oldV[key] < newV[key];
167
- }
168
- }
169
- return false;
170
- }
171
- function isUpdateJSON(json) {
172
- const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
173
- return is(json) && is(json?.beta);
174
- }
175
-
176
- // src/utils/crypto/decrypt.ts
177
- import { createDecipheriv, createVerify } from "node:crypto";
178
-
179
- // src/utils/crypto/utils.ts
180
- import { createHash } from "node:crypto";
181
- function hashString(data, length) {
182
- const hash = createHash("SHA256").update(data).digest("binary");
183
- return Buffer.from(hash).subarray(0, length);
184
- }
185
-
186
- // src/utils/crypto/decrypt.ts
187
- function decrypt(encryptedText, key, iv) {
188
- const decipher = createDecipheriv("aes-256-cbc", key, iv);
189
- let decrypted = decipher.update(encryptedText, "base64url", "utf8");
190
- decrypted += decipher.final("utf8");
191
- return decrypted;
192
- }
193
- function verifySignatureDefault(buffer, signature2, cert) {
194
- try {
195
- const [sig, version] = decrypt(signature2, hashString(cert, 32), hashString(buffer, 16)).split("%");
196
- const result = createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
197
- return result ? version : void 0;
198
- } catch (error) {
199
- return void 0;
200
- }
201
- }
202
-
203
- // src/utils/crypto/encrypt.ts
204
- import { createCipheriv, createPrivateKey, createSign } from "node:crypto";
205
- function encrypt(plainText, key, iv) {
206
- const cipher = createCipheriv("aes-256-cbc", key, iv);
207
- let encrypted = cipher.update(plainText, "utf8", "base64url");
208
- encrypted += cipher.final("base64url");
209
- return encrypted;
210
- }
211
- function signature(buffer, privateKey, cert, version) {
212
- const sig = createSign("RSA-SHA256").update(buffer).sign(createPrivateKey(privateKey), "base64");
213
- return encrypt(`${sig}%${version}`, hashString(cert, 32), hashString(buffer, 16));
214
- }
215
-
216
- export {
217
- __require,
218
- handleUnexpectedErrors,
219
- parseVersion,
220
- isLowerVersionDefault,
221
- isUpdateJSON,
222
- isDev,
223
- isWin,
224
- isMac,
225
- isLinux,
226
- getPathFromAppNameAsar,
227
- getAppVersion,
228
- getEntryVersion,
229
- requireNative,
230
- restartApp,
231
- setAppUserModelId,
232
- disableHWAccForWin7,
233
- singleInstance,
234
- setPortableAppDataPath,
235
- waitAppReady,
236
- loadPage,
237
- getPathFromPreload,
238
- getPathFromPublic,
239
- getPathFromEntryAsar,
240
- unzipFile,
241
- zipFile,
242
- hashString,
243
- decrypt,
244
- verifySignatureDefault,
245
- encrypt,
246
- signature
247
- };
@@ -1,4 +0,0 @@
1
- declare function decrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
2
- declare function verifySignatureDefault(buffer: Buffer, signature: string, cert: string): string | undefined | Promise<string | undefined>;
3
-
4
- export { decrypt as d, verifySignatureDefault as v };
@@ -1,4 +0,0 @@
1
- declare function decrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
2
- declare function verifySignatureDefault(buffer: Buffer, signature: string, cert: string): string | undefined | Promise<string | undefined>;
3
-
4
- export { decrypt as d, verifySignatureDefault as v };