electron-incremental-update 0.9.0 → 0.9.1
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/{chunk-6UZHBPFT.mjs → chunk-SPZL37O5.mjs} +34 -23
- package/dist/index.js +29 -31
- package/dist/index.mjs +4 -2
- package/dist/utils.d.mts +27 -19
- package/dist/utils.d.ts +27 -19
- package/dist/utils.js +48 -35
- package/dist/utils.mjs +5 -1
- package/dist/vite.js +7 -3
- package/dist/vite.mjs +7 -3
- package/package.json +9 -5
|
@@ -3,8 +3,9 @@ import {
|
|
|
3
3
|
} from "./chunk-CMBFI77K.mjs";
|
|
4
4
|
|
|
5
5
|
// src/utils/core.ts
|
|
6
|
-
import { readFileSync } from "node:fs";
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
7
7
|
import { dirname, join } from "node:path";
|
|
8
|
+
import { release } from "node:os";
|
|
8
9
|
import { app } from "electron";
|
|
9
10
|
var DEFAULT_APP_NAME = "product";
|
|
10
11
|
var is = {
|
|
@@ -43,52 +44,60 @@ function requireNative(packageName) {
|
|
|
43
44
|
return new NoSuchNativeModuleError(packageName);
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
-
// src/utils/utils.ts
|
|
48
|
-
import { dirname as dirname2, join as join2 } from "node:path";
|
|
49
|
-
import { existsSync, mkdirSync } from "node:fs";
|
|
50
|
-
import { app as app2 } from "electron";
|
|
51
|
-
function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
52
|
-
if (!originRepoURL.startsWith("https://github.com/")) {
|
|
53
|
-
throw new Error("origin url must start with https://github.com/");
|
|
54
|
-
}
|
|
55
|
-
originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
|
|
56
|
-
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
57
|
-
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
58
|
-
return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
59
|
-
}
|
|
60
47
|
function restartApp() {
|
|
61
|
-
|
|
62
|
-
|
|
48
|
+
app.relaunch();
|
|
49
|
+
app.quit();
|
|
63
50
|
}
|
|
64
51
|
function setAppUserModelId(id) {
|
|
65
|
-
is.win &&
|
|
52
|
+
is.win && app.setAppUserModelId(is.dev ? process.execPath : id);
|
|
53
|
+
}
|
|
54
|
+
function disableHWAccForWin7() {
|
|
55
|
+
if (release().startsWith("6.1")) {
|
|
56
|
+
app.disableHardwareAcceleration();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function singleInstance() {
|
|
60
|
+
if (!app.requestSingleInstanceLock()) {
|
|
61
|
+
app.quit();
|
|
62
|
+
process.exit(0);
|
|
63
|
+
}
|
|
66
64
|
}
|
|
67
65
|
function setPortableAppDataPath(dirName = "data", create) {
|
|
68
66
|
if (!is.win) {
|
|
69
67
|
return;
|
|
70
68
|
}
|
|
71
|
-
const portablePath =
|
|
69
|
+
const portablePath = join(dirname(app.getPath("exe")), dirName);
|
|
72
70
|
let exists = existsSync(portablePath);
|
|
73
71
|
if (create && !exists) {
|
|
74
72
|
mkdirSync(portablePath);
|
|
75
73
|
exists = true;
|
|
76
74
|
}
|
|
77
75
|
if (exists) {
|
|
78
|
-
|
|
76
|
+
app.setPath("appData", portablePath);
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
79
|
function waitAppReady(timeout = 1e3) {
|
|
82
|
-
return
|
|
80
|
+
return app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
|
|
83
81
|
const _ = setTimeout(() => {
|
|
84
82
|
reject(new Error("app is not ready"));
|
|
85
83
|
}, timeout);
|
|
86
|
-
|
|
84
|
+
app.whenReady().then(() => {
|
|
87
85
|
clearTimeout(_);
|
|
88
86
|
resolve();
|
|
89
87
|
});
|
|
90
88
|
});
|
|
91
89
|
}
|
|
90
|
+
|
|
91
|
+
// src/utils/utils.ts
|
|
92
|
+
function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
93
|
+
if (!originRepoURL.startsWith("https://github.com/")) {
|
|
94
|
+
throw new Error("origin url must start with https://github.com/");
|
|
95
|
+
}
|
|
96
|
+
originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
|
|
97
|
+
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
98
|
+
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
99
|
+
return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
100
|
+
}
|
|
92
101
|
function handleUnexpectedErrors(callback) {
|
|
93
102
|
process.on("uncaughtException", callback);
|
|
94
103
|
process.on("unhandledRejection", callback);
|
|
@@ -104,10 +113,12 @@ export {
|
|
|
104
113
|
NoSuchNativeModuleError,
|
|
105
114
|
isNoSuchNativeModuleError,
|
|
106
115
|
requireNative,
|
|
107
|
-
parseGithubCdnURL,
|
|
108
116
|
restartApp,
|
|
109
117
|
setAppUserModelId,
|
|
118
|
+
disableHWAccForWin7,
|
|
119
|
+
singleInstance,
|
|
110
120
|
setPortableAppDataPath,
|
|
111
121
|
waitAppReady,
|
|
122
|
+
parseGithubCdnURL,
|
|
112
123
|
handleUnexpectedErrors
|
|
113
124
|
};
|
package/dist/index.js
CHANGED
|
@@ -25,17 +25,18 @@ __export(src_exports, {
|
|
|
25
25
|
initApp: () => initApp
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(src_exports);
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
var
|
|
28
|
+
var import_node_path2 = require("path");
|
|
29
|
+
var import_node_fs4 = require("fs");
|
|
30
|
+
var import_electron3 = require("electron");
|
|
31
31
|
|
|
32
32
|
// src/updater/index.ts
|
|
33
|
-
var
|
|
33
|
+
var import_node_fs3 = require("fs");
|
|
34
34
|
var import_promises = require("fs/promises");
|
|
35
35
|
|
|
36
36
|
// src/utils/core.ts
|
|
37
37
|
var import_node_fs = require("fs");
|
|
38
38
|
var import_node_path = require("path");
|
|
39
|
+
var import_node_os = require("os");
|
|
39
40
|
var import_electron = require("electron");
|
|
40
41
|
var DEFAULT_APP_NAME = "product";
|
|
41
42
|
var is = {
|
|
@@ -53,6 +54,17 @@ function getElectronVersion() {
|
|
|
53
54
|
function getAppVersion(name = DEFAULT_APP_NAME) {
|
|
54
55
|
return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getElectronVersion();
|
|
55
56
|
}
|
|
57
|
+
function waitAppReady(timeout = 1e3) {
|
|
58
|
+
return import_electron.app.isReady() ? Promise.resolve() : new Promise((resolve2, reject) => {
|
|
59
|
+
const _ = setTimeout(() => {
|
|
60
|
+
reject(new Error("app is not ready"));
|
|
61
|
+
}, timeout);
|
|
62
|
+
import_electron.app.whenReady().then(() => {
|
|
63
|
+
clearTimeout(_);
|
|
64
|
+
resolve2();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
56
68
|
|
|
57
69
|
// src/utils/version.ts
|
|
58
70
|
function parseVersion(version) {
|
|
@@ -100,22 +112,6 @@ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
|
100
112
|
});
|
|
101
113
|
}
|
|
102
114
|
|
|
103
|
-
// src/utils/utils.ts
|
|
104
|
-
var import_node_path2 = require("path");
|
|
105
|
-
var import_node_fs3 = require("fs");
|
|
106
|
-
var import_electron2 = require("electron");
|
|
107
|
-
function waitAppReady(timeout = 1e3) {
|
|
108
|
-
return import_electron2.app.isReady() ? Promise.resolve() : new Promise((resolve2, reject) => {
|
|
109
|
-
const _ = setTimeout(() => {
|
|
110
|
-
reject(new Error("app is not ready"));
|
|
111
|
-
}, timeout);
|
|
112
|
-
import_electron2.app.whenReady().then(() => {
|
|
113
|
-
clearTimeout(_);
|
|
114
|
-
resolve2();
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
115
|
// src/crypto.ts
|
|
120
116
|
var import_node_crypto = require("crypto");
|
|
121
117
|
function decrypt(encryptedText, key2, iv) {
|
|
@@ -169,12 +165,12 @@ var DownloadError = class extends Error {
|
|
|
169
165
|
}
|
|
170
166
|
};
|
|
171
167
|
|
|
172
|
-
// src/updater/defaultFunctions.ts
|
|
173
|
-
var
|
|
168
|
+
// src/updater/defaultFunctions/download.ts
|
|
169
|
+
var import_electron2 = require("electron");
|
|
174
170
|
var downloadJSONDefault = async (url, headers) => {
|
|
175
171
|
await waitAppReady();
|
|
176
172
|
return new Promise((resolve2, reject) => {
|
|
177
|
-
const request =
|
|
173
|
+
const request = import_electron2.net.request({
|
|
178
174
|
url,
|
|
179
175
|
method: "GET",
|
|
180
176
|
redirect: "follow"
|
|
@@ -208,7 +204,7 @@ var downloadBufferDefault = async (url, headers, total, onDownloading) => {
|
|
|
208
204
|
await waitAppReady();
|
|
209
205
|
let current = 0;
|
|
210
206
|
return new Promise((resolve2, reject) => {
|
|
211
|
-
const request =
|
|
207
|
+
const request = import_electron2.net.request({
|
|
212
208
|
url,
|
|
213
209
|
method: "GET",
|
|
214
210
|
redirect: "follow"
|
|
@@ -236,6 +232,8 @@ var downloadBufferDefault = async (url, headers, total, onDownloading) => {
|
|
|
236
232
|
request.end();
|
|
237
233
|
});
|
|
238
234
|
};
|
|
235
|
+
|
|
236
|
+
// src/updater/defaultFunctions/compareVersion.ts
|
|
239
237
|
var compareVersionDefault = (version1, version2) => {
|
|
240
238
|
const oldV = parseVersion(version1);
|
|
241
239
|
const newV = parseVersion(version2);
|
|
@@ -295,11 +293,11 @@ var IncrementalUpdater = class {
|
|
|
295
293
|
return await compare(productVersion, version);
|
|
296
294
|
}
|
|
297
295
|
async parseData(format, data) {
|
|
298
|
-
if ((0,
|
|
296
|
+
if ((0, import_node_fs3.existsSync)(this.tmpFilePath)) {
|
|
299
297
|
this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
|
|
300
298
|
await (0, import_promises.rm)(this.tmpFilePath);
|
|
301
299
|
}
|
|
302
|
-
if ((0,
|
|
300
|
+
if ((0, import_node_fs3.existsSync)(this.gzipPath)) {
|
|
303
301
|
this.logger?.warn(`remove .gz file: ${this.gzipPath}`);
|
|
304
302
|
await (0, import_promises.rm)(this.gzipPath);
|
|
305
303
|
}
|
|
@@ -423,18 +421,18 @@ function initApp(appOptions) {
|
|
|
423
421
|
} = hooks || {};
|
|
424
422
|
function handleError(msg) {
|
|
425
423
|
onStartError?.(new Error(msg));
|
|
426
|
-
|
|
424
|
+
import_electron3.app.quit();
|
|
427
425
|
}
|
|
428
426
|
async function startup(updater) {
|
|
429
427
|
try {
|
|
430
428
|
const asarPath = getProductAsarPath(updater.productName);
|
|
431
429
|
const updateAsarPath = `${asarPath}.tmp`;
|
|
432
|
-
if ((0,
|
|
430
|
+
if ((0, import_node_fs4.existsSync)(updateAsarPath)) {
|
|
433
431
|
await beforeDoUpdate?.(asarPath, updateAsarPath);
|
|
434
|
-
(0,
|
|
432
|
+
(0, import_node_fs4.renameSync)(updateAsarPath, asarPath);
|
|
435
433
|
}
|
|
436
|
-
const mainDir =
|
|
437
|
-
const entry = (0,
|
|
434
|
+
const mainDir = import_electron3.app.isPackaged ? asarPath : electronDevDistPath;
|
|
435
|
+
const entry = (0, import_node_path2.resolve)(__dirname, mainDir, mainPath);
|
|
438
436
|
await beforeStart?.(entry);
|
|
439
437
|
require(entry)(updater);
|
|
440
438
|
} catch (error) {
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
getElectronVersion,
|
|
9
9
|
getProductAsarPath,
|
|
10
10
|
waitAppReady
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-SPZL37O5.mjs";
|
|
12
12
|
import {
|
|
13
13
|
__require,
|
|
14
14
|
parseVersion,
|
|
@@ -49,7 +49,7 @@ var DownloadError = class extends Error {
|
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
// src/updater/defaultFunctions.ts
|
|
52
|
+
// src/updater/defaultFunctions/download.ts
|
|
53
53
|
import { net } from "electron";
|
|
54
54
|
var downloadJSONDefault = async (url, headers) => {
|
|
55
55
|
await waitAppReady();
|
|
@@ -116,6 +116,8 @@ var downloadBufferDefault = async (url, headers, total, onDownloading) => {
|
|
|
116
116
|
request.end();
|
|
117
117
|
});
|
|
118
118
|
};
|
|
119
|
+
|
|
120
|
+
// src/updater/defaultFunctions/compareVersion.ts
|
|
119
121
|
var compareVersionDefault = (version1, version2) => {
|
|
120
122
|
const oldV = parseVersion(version1);
|
|
121
123
|
const newV = parseVersion(version2);
|
package/dist/utils.d.mts
CHANGED
|
@@ -37,6 +37,32 @@ declare function isNoSuchNativeModuleError(e: unknown): e is NoSuchNativeModuleE
|
|
|
37
37
|
* @param packageName native package name
|
|
38
38
|
*/
|
|
39
39
|
declare function requireNative<T = any>(packageName: string): T | NoSuchNativeModuleError;
|
|
40
|
+
/**
|
|
41
|
+
* Restarts the Electron app.
|
|
42
|
+
*/
|
|
43
|
+
declare function restartApp(): void;
|
|
44
|
+
/**
|
|
45
|
+
* fix app use model id, only for Windows
|
|
46
|
+
* @param id app id
|
|
47
|
+
*/
|
|
48
|
+
declare function setAppUserModelId(id: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* disable hardware acceleration for Windows 7
|
|
51
|
+
*/
|
|
52
|
+
declare function disableHWAccForWin7(): void;
|
|
53
|
+
/**
|
|
54
|
+
* keep single electron instance
|
|
55
|
+
*/
|
|
56
|
+
declare function singleInstance(): void;
|
|
57
|
+
/**
|
|
58
|
+
* set AppData dir for portable Windows app
|
|
59
|
+
*/
|
|
60
|
+
declare function setPortableAppDataPath(dirName?: string, create?: boolean): void;
|
|
61
|
+
/**
|
|
62
|
+
* ensure app is ready.
|
|
63
|
+
* @param timeout wait timeout, @default 1000
|
|
64
|
+
*/
|
|
65
|
+
declare function waitAppReady(timeout?: number): Promise<void>;
|
|
40
66
|
|
|
41
67
|
interface Version {
|
|
42
68
|
major: number;
|
|
@@ -56,28 +82,10 @@ declare function zipFile(filePath: string, targetFilePath?: string): Promise<unk
|
|
|
56
82
|
* {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 some public CDN links}
|
|
57
83
|
*/
|
|
58
84
|
declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, relativeFilePath: string): string;
|
|
59
|
-
/**
|
|
60
|
-
* Restarts the Electron app.
|
|
61
|
-
*/
|
|
62
|
-
declare function restartApp(): void;
|
|
63
|
-
/**
|
|
64
|
-
* fix app use model id, only for Windows
|
|
65
|
-
* @param id app id
|
|
66
|
-
*/
|
|
67
|
-
declare function setAppUserModelId(id: string): void;
|
|
68
|
-
/**
|
|
69
|
-
* set AppData dir for portable Windows app
|
|
70
|
-
*/
|
|
71
|
-
declare function setPortableAppDataPath(dirName?: string, create?: boolean): void;
|
|
72
|
-
/**
|
|
73
|
-
* ensure app is ready.
|
|
74
|
-
* @param timeout wait timeout, @default 1000
|
|
75
|
-
*/
|
|
76
|
-
declare function waitAppReady(timeout?: number): Promise<void>;
|
|
77
85
|
/**
|
|
78
86
|
* handle all unhandled error
|
|
79
87
|
* @param callback callback function
|
|
80
88
|
*/
|
|
81
89
|
declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
|
|
82
90
|
|
|
83
|
-
export { DEFAULT_APP_NAME, NoSuchNativeModuleError, type Version, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, is, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, unzipFile, waitAppReady, zipFile };
|
|
91
|
+
export { DEFAULT_APP_NAME, NoSuchNativeModuleError, type Version, disableHWAccForWin7, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, is, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance, unzipFile, waitAppReady, zipFile };
|
package/dist/utils.d.ts
CHANGED
|
@@ -37,6 +37,32 @@ declare function isNoSuchNativeModuleError(e: unknown): e is NoSuchNativeModuleE
|
|
|
37
37
|
* @param packageName native package name
|
|
38
38
|
*/
|
|
39
39
|
declare function requireNative<T = any>(packageName: string): T | NoSuchNativeModuleError;
|
|
40
|
+
/**
|
|
41
|
+
* Restarts the Electron app.
|
|
42
|
+
*/
|
|
43
|
+
declare function restartApp(): void;
|
|
44
|
+
/**
|
|
45
|
+
* fix app use model id, only for Windows
|
|
46
|
+
* @param id app id
|
|
47
|
+
*/
|
|
48
|
+
declare function setAppUserModelId(id: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* disable hardware acceleration for Windows 7
|
|
51
|
+
*/
|
|
52
|
+
declare function disableHWAccForWin7(): void;
|
|
53
|
+
/**
|
|
54
|
+
* keep single electron instance
|
|
55
|
+
*/
|
|
56
|
+
declare function singleInstance(): void;
|
|
57
|
+
/**
|
|
58
|
+
* set AppData dir for portable Windows app
|
|
59
|
+
*/
|
|
60
|
+
declare function setPortableAppDataPath(dirName?: string, create?: boolean): void;
|
|
61
|
+
/**
|
|
62
|
+
* ensure app is ready.
|
|
63
|
+
* @param timeout wait timeout, @default 1000
|
|
64
|
+
*/
|
|
65
|
+
declare function waitAppReady(timeout?: number): Promise<void>;
|
|
40
66
|
|
|
41
67
|
interface Version {
|
|
42
68
|
major: number;
|
|
@@ -56,28 +82,10 @@ declare function zipFile(filePath: string, targetFilePath?: string): Promise<unk
|
|
|
56
82
|
* {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 some public CDN links}
|
|
57
83
|
*/
|
|
58
84
|
declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, relativeFilePath: string): string;
|
|
59
|
-
/**
|
|
60
|
-
* Restarts the Electron app.
|
|
61
|
-
*/
|
|
62
|
-
declare function restartApp(): void;
|
|
63
|
-
/**
|
|
64
|
-
* fix app use model id, only for Windows
|
|
65
|
-
* @param id app id
|
|
66
|
-
*/
|
|
67
|
-
declare function setAppUserModelId(id: string): void;
|
|
68
|
-
/**
|
|
69
|
-
* set AppData dir for portable Windows app
|
|
70
|
-
*/
|
|
71
|
-
declare function setPortableAppDataPath(dirName?: string, create?: boolean): void;
|
|
72
|
-
/**
|
|
73
|
-
* ensure app is ready.
|
|
74
|
-
* @param timeout wait timeout, @default 1000
|
|
75
|
-
*/
|
|
76
|
-
declare function waitAppReady(timeout?: number): Promise<void>;
|
|
77
85
|
/**
|
|
78
86
|
* handle all unhandled error
|
|
79
87
|
* @param callback callback function
|
|
80
88
|
*/
|
|
81
89
|
declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
|
|
82
90
|
|
|
83
|
-
export { DEFAULT_APP_NAME, NoSuchNativeModuleError, type Version, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, is, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, unzipFile, waitAppReady, zipFile };
|
|
91
|
+
export { DEFAULT_APP_NAME, NoSuchNativeModuleError, type Version, disableHWAccForWin7, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, is, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance, unzipFile, waitAppReady, zipFile };
|
package/dist/utils.js
CHANGED
|
@@ -22,6 +22,7 @@ var utils_exports = {};
|
|
|
22
22
|
__export(utils_exports, {
|
|
23
23
|
DEFAULT_APP_NAME: () => DEFAULT_APP_NAME,
|
|
24
24
|
NoSuchNativeModuleError: () => NoSuchNativeModuleError,
|
|
25
|
+
disableHWAccForWin7: () => disableHWAccForWin7,
|
|
25
26
|
getAppVersion: () => getAppVersion,
|
|
26
27
|
getElectronVersion: () => getElectronVersion,
|
|
27
28
|
getLocale: () => getLocale,
|
|
@@ -35,6 +36,7 @@ __export(utils_exports, {
|
|
|
35
36
|
restartApp: () => restartApp,
|
|
36
37
|
setAppUserModelId: () => setAppUserModelId,
|
|
37
38
|
setPortableAppDataPath: () => setPortableAppDataPath,
|
|
39
|
+
singleInstance: () => singleInstance,
|
|
38
40
|
unzipFile: () => unzipFile,
|
|
39
41
|
waitAppReady: () => waitAppReady,
|
|
40
42
|
zipFile: () => zipFile
|
|
@@ -44,6 +46,7 @@ module.exports = __toCommonJS(utils_exports);
|
|
|
44
46
|
// src/utils/core.ts
|
|
45
47
|
var import_node_fs = require("fs");
|
|
46
48
|
var import_node_path = require("path");
|
|
49
|
+
var import_node_os = require("os");
|
|
47
50
|
var import_electron = require("electron");
|
|
48
51
|
var DEFAULT_APP_NAME = "product";
|
|
49
52
|
var is = {
|
|
@@ -82,6 +85,49 @@ function requireNative(packageName) {
|
|
|
82
85
|
return new NoSuchNativeModuleError(packageName);
|
|
83
86
|
}
|
|
84
87
|
}
|
|
88
|
+
function restartApp() {
|
|
89
|
+
import_electron.app.relaunch();
|
|
90
|
+
import_electron.app.quit();
|
|
91
|
+
}
|
|
92
|
+
function setAppUserModelId(id) {
|
|
93
|
+
is.win && import_electron.app.setAppUserModelId(is.dev ? process.execPath : id);
|
|
94
|
+
}
|
|
95
|
+
function disableHWAccForWin7() {
|
|
96
|
+
if ((0, import_node_os.release)().startsWith("6.1")) {
|
|
97
|
+
import_electron.app.disableHardwareAcceleration();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function singleInstance() {
|
|
101
|
+
if (!import_electron.app.requestSingleInstanceLock()) {
|
|
102
|
+
import_electron.app.quit();
|
|
103
|
+
process.exit(0);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function setPortableAppDataPath(dirName = "data", create) {
|
|
107
|
+
if (!is.win) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const portablePath = (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getPath("exe")), dirName);
|
|
111
|
+
let exists = (0, import_node_fs.existsSync)(portablePath);
|
|
112
|
+
if (create && !exists) {
|
|
113
|
+
(0, import_node_fs.mkdirSync)(portablePath);
|
|
114
|
+
exists = true;
|
|
115
|
+
}
|
|
116
|
+
if (exists) {
|
|
117
|
+
import_electron.app.setPath("appData", portablePath);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function waitAppReady(timeout = 1e3) {
|
|
121
|
+
return import_electron.app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
|
|
122
|
+
const _ = setTimeout(() => {
|
|
123
|
+
reject(new Error("app is not ready"));
|
|
124
|
+
}, timeout);
|
|
125
|
+
import_electron.app.whenReady().then(() => {
|
|
126
|
+
clearTimeout(_);
|
|
127
|
+
resolve();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
85
131
|
|
|
86
132
|
// src/utils/version.ts
|
|
87
133
|
function parseVersion(version) {
|
|
@@ -145,9 +191,6 @@ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
|
145
191
|
}
|
|
146
192
|
|
|
147
193
|
// src/utils/utils.ts
|
|
148
|
-
var import_node_path2 = require("path");
|
|
149
|
-
var import_node_fs3 = require("fs");
|
|
150
|
-
var import_electron2 = require("electron");
|
|
151
194
|
function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
152
195
|
if (!originRepoURL.startsWith("https://github.com/")) {
|
|
153
196
|
throw new Error("origin url must start with https://github.com/");
|
|
@@ -157,38 +200,6 @@ function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
|
157
200
|
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
158
201
|
return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
159
202
|
}
|
|
160
|
-
function restartApp() {
|
|
161
|
-
import_electron2.app.relaunch();
|
|
162
|
-
import_electron2.app.quit();
|
|
163
|
-
}
|
|
164
|
-
function setAppUserModelId(id) {
|
|
165
|
-
is.win && import_electron2.app.setAppUserModelId(is.dev ? process.execPath : id);
|
|
166
|
-
}
|
|
167
|
-
function setPortableAppDataPath(dirName = "data", create) {
|
|
168
|
-
if (!is.win) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
const portablePath = (0, import_node_path2.join)((0, import_node_path2.dirname)(import_electron2.app.getPath("exe")), dirName);
|
|
172
|
-
let exists = (0, import_node_fs3.existsSync)(portablePath);
|
|
173
|
-
if (create && !exists) {
|
|
174
|
-
(0, import_node_fs3.mkdirSync)(portablePath);
|
|
175
|
-
exists = true;
|
|
176
|
-
}
|
|
177
|
-
if (exists) {
|
|
178
|
-
import_electron2.app.setPath("appData", portablePath);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
function waitAppReady(timeout = 1e3) {
|
|
182
|
-
return import_electron2.app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
|
|
183
|
-
const _ = setTimeout(() => {
|
|
184
|
-
reject(new Error("app is not ready"));
|
|
185
|
-
}, timeout);
|
|
186
|
-
import_electron2.app.whenReady().then(() => {
|
|
187
|
-
clearTimeout(_);
|
|
188
|
-
resolve();
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
203
|
function handleUnexpectedErrors(callback) {
|
|
193
204
|
process.on("uncaughtException", callback);
|
|
194
205
|
process.on("unhandledRejection", callback);
|
|
@@ -197,6 +208,7 @@ function handleUnexpectedErrors(callback) {
|
|
|
197
208
|
0 && (module.exports = {
|
|
198
209
|
DEFAULT_APP_NAME,
|
|
199
210
|
NoSuchNativeModuleError,
|
|
211
|
+
disableHWAccForWin7,
|
|
200
212
|
getAppVersion,
|
|
201
213
|
getElectronVersion,
|
|
202
214
|
getLocale,
|
|
@@ -210,6 +222,7 @@ function handleUnexpectedErrors(callback) {
|
|
|
210
222
|
restartApp,
|
|
211
223
|
setAppUserModelId,
|
|
212
224
|
setPortableAppDataPath,
|
|
225
|
+
singleInstance,
|
|
213
226
|
unzipFile,
|
|
214
227
|
waitAppReady,
|
|
215
228
|
zipFile
|
package/dist/utils.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_APP_NAME,
|
|
3
3
|
NoSuchNativeModuleError,
|
|
4
|
+
disableHWAccForWin7,
|
|
4
5
|
getAppVersion,
|
|
5
6
|
getElectronVersion,
|
|
6
7
|
getLocale,
|
|
@@ -13,8 +14,9 @@ import {
|
|
|
13
14
|
restartApp,
|
|
14
15
|
setAppUserModelId,
|
|
15
16
|
setPortableAppDataPath,
|
|
17
|
+
singleInstance,
|
|
16
18
|
waitAppReady
|
|
17
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-SPZL37O5.mjs";
|
|
18
20
|
import {
|
|
19
21
|
parseVersion,
|
|
20
22
|
unzipFile,
|
|
@@ -23,6 +25,7 @@ import {
|
|
|
23
25
|
export {
|
|
24
26
|
DEFAULT_APP_NAME,
|
|
25
27
|
NoSuchNativeModuleError,
|
|
28
|
+
disableHWAccForWin7,
|
|
26
29
|
getAppVersion,
|
|
27
30
|
getElectronVersion,
|
|
28
31
|
getLocale,
|
|
@@ -36,6 +39,7 @@ export {
|
|
|
36
39
|
restartApp,
|
|
37
40
|
setAppUserModelId,
|
|
38
41
|
setPortableAppDataPath,
|
|
42
|
+
singleInstance,
|
|
39
43
|
unzipFile,
|
|
40
44
|
waitAppReady,
|
|
41
45
|
zipFile
|
package/dist/vite.js
CHANGED
|
@@ -195,9 +195,13 @@ var import_node_path = require("path");
|
|
|
195
195
|
var import_selfsigned = require("selfsigned");
|
|
196
196
|
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
197
197
|
const privateKeyDir = (0, import_node_path.dirname)(privateKeyPath);
|
|
198
|
-
(0, import_node_fs3.existsSync)(privateKeyDir)
|
|
198
|
+
if (!(0, import_node_fs3.existsSync)(privateKeyDir)) {
|
|
199
|
+
(0, import_node_fs3.mkdirSync)(privateKeyDir, { recursive: true });
|
|
200
|
+
}
|
|
199
201
|
const certDir = (0, import_node_path.dirname)(certPath);
|
|
200
|
-
(0, import_node_fs3.existsSync)(certDir)
|
|
202
|
+
if (!(0, import_node_fs3.existsSync)(certDir)) {
|
|
203
|
+
(0, import_node_fs3.mkdirSync)(certDir, { recursive: true });
|
|
204
|
+
}
|
|
201
205
|
const { cert, private: privateKey } = (0, import_selfsigned.generate)(subject, {
|
|
202
206
|
keySize: keyLength,
|
|
203
207
|
algorithm: "sha256",
|
|
@@ -211,7 +215,7 @@ function writeCertToMain(entryPath, cert) {
|
|
|
211
215
|
const initRegex = /(?<=const SIGNATURE_CERT\s*=\s*)['"]{2}/m;
|
|
212
216
|
const existRegex = /(?<=const SIGNATURE_CERT\s*=\s*)(['"]-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n['"])/m;
|
|
213
217
|
const eol = file.includes("\r") ? "\r\n" : "\n";
|
|
214
|
-
const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join(`${eol}+ `);
|
|
218
|
+
const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join(`${eol} + `);
|
|
215
219
|
let replaced = file;
|
|
216
220
|
if (initRegex.test(file)) {
|
|
217
221
|
replaced = file.replace(initRegex, replacement);
|
package/dist/vite.mjs
CHANGED
|
@@ -100,9 +100,13 @@ import { dirname } from "node:path";
|
|
|
100
100
|
import { generate } from "selfsigned";
|
|
101
101
|
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
102
102
|
const privateKeyDir = dirname(privateKeyPath);
|
|
103
|
-
existsSync2(privateKeyDir)
|
|
103
|
+
if (!existsSync2(privateKeyDir)) {
|
|
104
|
+
mkdirSync(privateKeyDir, { recursive: true });
|
|
105
|
+
}
|
|
104
106
|
const certDir = dirname(certPath);
|
|
105
|
-
existsSync2(certDir)
|
|
107
|
+
if (!existsSync2(certDir)) {
|
|
108
|
+
mkdirSync(certDir, { recursive: true });
|
|
109
|
+
}
|
|
106
110
|
const { cert, private: privateKey } = generate(subject, {
|
|
107
111
|
keySize: keyLength,
|
|
108
112
|
algorithm: "sha256",
|
|
@@ -116,7 +120,7 @@ function writeCertToMain(entryPath, cert) {
|
|
|
116
120
|
const initRegex = /(?<=const SIGNATURE_CERT\s*=\s*)['"]{2}/m;
|
|
117
121
|
const existRegex = /(?<=const SIGNATURE_CERT\s*=\s*)(['"]-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n['"])/m;
|
|
118
122
|
const eol = file.includes("\r") ? "\r\n" : "\n";
|
|
119
|
-
const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join(`${eol}+ `);
|
|
123
|
+
const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join(`${eol} + `);
|
|
120
124
|
let replaced = file;
|
|
121
125
|
if (initRegex.test(file)) {
|
|
122
126
|
replaced = file.replace(initRegex, replacement);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "electron incremental update tools, powered by vite",
|
|
5
5
|
"author": "subframe7536",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"vite.js"
|
|
35
35
|
],
|
|
36
36
|
"scripts": {
|
|
37
|
+
"dev": "tsup --watch",
|
|
37
38
|
"build": "tsup && node fix-module.js",
|
|
38
39
|
"release": "pnpm test && pnpm run build && bumpp --all && npm publish",
|
|
39
40
|
"test": "vitest --run",
|
|
@@ -43,20 +44,23 @@
|
|
|
43
44
|
"access": "public",
|
|
44
45
|
"registry": "https://registry.npmjs.org/"
|
|
45
46
|
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"esbuild": "*"
|
|
49
|
+
},
|
|
46
50
|
"dependencies": {
|
|
47
51
|
"@electron/asar": "^3.2.8",
|
|
48
52
|
"ci-info": "^4.0.0",
|
|
49
53
|
"selfsigned": "^2.4.1"
|
|
50
54
|
},
|
|
51
55
|
"devDependencies": {
|
|
52
|
-
"@subframe7536/eslint-config": "^0.5.
|
|
53
|
-
"@types/node": "^20.
|
|
56
|
+
"@subframe7536/eslint-config": "^0.5.2",
|
|
57
|
+
"@types/node": "^20.10.1",
|
|
54
58
|
"bumpp": "^9.2.0",
|
|
55
|
-
"electron": "^27.1.
|
|
59
|
+
"electron": "^27.1.2",
|
|
56
60
|
"eslint": "^8.54.0",
|
|
57
61
|
"tsup": "^8.0.1",
|
|
58
62
|
"typescript": "^5.3.2",
|
|
59
|
-
"vite": "^5.0.
|
|
63
|
+
"vite": "^5.0.4",
|
|
60
64
|
"vitest": "^0.34.6"
|
|
61
65
|
}
|
|
62
66
|
}
|