electron-incremental-update 1.3.0 → 2.0.0-beta.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/README.md +6 -2
- package/dist/chunk-RSLOPAIZ.js +247 -0
- package/dist/decrypt-BNBcodiO.d.cts +4 -0
- package/dist/decrypt-BNBcodiO.d.ts +4 -0
- package/dist/index.cjs +108 -261
- package/dist/index.d.cts +68 -161
- package/dist/index.d.ts +68 -161
- package/dist/index.js +76 -195
- package/dist/provider.cjs +227 -0
- package/dist/provider.d.cts +37 -0
- package/dist/provider.d.ts +37 -0
- package/dist/provider.js +98 -0
- package/dist/types-DxPmQmaq.d.cts +61 -0
- package/dist/types-seJf3Wbc.d.ts +61 -0
- package/dist/utils.cjs +139 -115
- package/dist/utils.d.cts +31 -76
- package/dist/utils.d.ts +31 -76
- package/dist/utils.js +35 -11
- package/dist/{pure-GoN_3MEj.d.cts → version-CffZWDhZ.d.cts} +8 -7
- package/dist/{pure-GoN_3MEj.d.ts → version-CffZWDhZ.d.ts} +8 -7
- package/dist/vite.js +70 -117
- package/package.json +12 -6
- package/provider.d.ts +1 -0
- package/provider.js +1 -0
- package/dist/chunk-7ET4GMTZ.js +0 -236
- package/dist/chunk-CXHA5TF7.js +0 -236
- package/dist/chunk-HWUYTDEF.js +0 -236
- package/dist/chunk-RQCTJY4L.js +0 -236
- package/dist/chunk-SBPTSLG7.js +0 -235
- package/dist/vite.d.ts +0 -372
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { i as isLowerVersionDefault, U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.js';
|
|
2
|
+
import { v as verifySignatureDefault } from './decrypt-BNBcodiO.js';
|
|
3
|
+
import { U as URLHandler, I as IProvider, D as DownloadingInfo, O as OnDownloading } from './types-seJf3Wbc.js';
|
|
4
|
+
import '@subframe7536/type-utils';
|
|
5
|
+
|
|
6
|
+
interface GitHubProviderOptions {
|
|
7
|
+
/**
|
|
8
|
+
* github repo root url
|
|
9
|
+
* @example 'https://github.com/electron/electron'
|
|
10
|
+
*/
|
|
11
|
+
url: string;
|
|
12
|
+
extraHeaders?: Record<string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* custom url handler
|
|
15
|
+
*
|
|
16
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDN links}
|
|
17
|
+
*/
|
|
18
|
+
urlHandler?: URLHandler;
|
|
19
|
+
}
|
|
20
|
+
declare class GitHubProvider implements IProvider {
|
|
21
|
+
private ua;
|
|
22
|
+
name: string;
|
|
23
|
+
urlHandler?: URLHandler;
|
|
24
|
+
private url;
|
|
25
|
+
private extraHeaders?;
|
|
26
|
+
constructor(options: GitHubProviderOptions);
|
|
27
|
+
private parseURL;
|
|
28
|
+
isLowerVersion: typeof isLowerVersionDefault;
|
|
29
|
+
verifySignaure: typeof verifySignatureDefault;
|
|
30
|
+
downloadJSON(versionPath: string): Promise<UpdateJSON>;
|
|
31
|
+
downloadBuffer(name: string, { version, size }: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare function downloadUpdateJSONDefault(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
|
|
35
|
+
declare function downloadAsarBufferDefault(url: string, headers: Record<string, any>, total: number, onDownloading?: OnDownloading): Promise<Buffer>;
|
|
36
|
+
|
|
37
|
+
export { DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, downloadAsarBufferDefault, downloadUpdateJSONDefault };
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isLowerVersionDefault,
|
|
3
|
+
isUpdateJSON,
|
|
4
|
+
verifySignatureDefault,
|
|
5
|
+
waitAppReady
|
|
6
|
+
} from "./chunk-RSLOPAIZ.js";
|
|
7
|
+
|
|
8
|
+
// src/provider/download.ts
|
|
9
|
+
import { net } from "electron";
|
|
10
|
+
async function downlaodFn(url, headers, onResponse) {
|
|
11
|
+
await waitAppReady();
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const request = net.request({ url, method: "GET", redirect: "follow" });
|
|
14
|
+
Object.keys(headers).forEach((key) => request.setHeader(key, headers[key]));
|
|
15
|
+
request.on("response", (resp) => {
|
|
16
|
+
resp.on("aborted", () => reject(new Error("aborted")));
|
|
17
|
+
resp.on("error", () => reject(new Error("download error")));
|
|
18
|
+
onResponse(resp, resolve, reject);
|
|
19
|
+
});
|
|
20
|
+
request.on("error", reject);
|
|
21
|
+
request.end();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function downloadUpdateJSONDefault(url, headers) {
|
|
25
|
+
return await downlaodFn(url, headers, (resp, resolve, reject) => {
|
|
26
|
+
let data = "";
|
|
27
|
+
resp.on("data", (chunk) => data += chunk);
|
|
28
|
+
resp.on("end", () => {
|
|
29
|
+
try {
|
|
30
|
+
const json = JSON.parse(data);
|
|
31
|
+
if (isUpdateJSON(json)) {
|
|
32
|
+
resolve(json);
|
|
33
|
+
} else {
|
|
34
|
+
throw Error;
|
|
35
|
+
}
|
|
36
|
+
} catch (ignore) {
|
|
37
|
+
reject(new Error("invalid update json"));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async function downloadAsarBufferDefault(url, headers, total, onDownloading) {
|
|
43
|
+
let current = 0;
|
|
44
|
+
return await downlaodFn(url, headers, (resp, resolve) => {
|
|
45
|
+
let data = [];
|
|
46
|
+
resp.on("data", (chunk) => {
|
|
47
|
+
current += chunk.length;
|
|
48
|
+
onDownloading?.({ percent: `${+(current / total).toFixed(2) * 100}%`, total, current });
|
|
49
|
+
data.push(chunk);
|
|
50
|
+
});
|
|
51
|
+
resp.on("end", () => resolve(Buffer.concat(data)));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/provider/github.ts
|
|
56
|
+
var GitHubProvider = class {
|
|
57
|
+
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
|
|
58
|
+
name = "GithubProvider";
|
|
59
|
+
urlHandler;
|
|
60
|
+
url;
|
|
61
|
+
extraHeaders;
|
|
62
|
+
constructor(options) {
|
|
63
|
+
this.url = new URL(options.url);
|
|
64
|
+
this.extraHeaders = options.extraHeaders;
|
|
65
|
+
this.urlHandler = options.urlHandler;
|
|
66
|
+
if (this.url.host !== "github.com") {
|
|
67
|
+
throw new Error(`${this.name}: invalid github url: ${options.url}`);
|
|
68
|
+
}
|
|
69
|
+
if (!this.url.pathname.endsWith("/")) {
|
|
70
|
+
this.url.pathname += "/";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
parseURL(isDownloadAsar, path) {
|
|
74
|
+
const url = this.url.href + path;
|
|
75
|
+
return this.urlHandler ? this.urlHandler(url, isDownloadAsar) : url;
|
|
76
|
+
}
|
|
77
|
+
isLowerVersion = isLowerVersionDefault;
|
|
78
|
+
verifySignaure = verifySignatureDefault;
|
|
79
|
+
async downloadJSON(versionPath) {
|
|
80
|
+
return await downloadUpdateJSONDefault(
|
|
81
|
+
this.parseURL(false, `HEAD/${versionPath}`),
|
|
82
|
+
{ userAgent: this.ua, accept: "application/json", ...this.extraHeaders }
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
async downloadBuffer(name, { version, size }, onDownloading) {
|
|
86
|
+
return await downloadAsarBufferDefault(
|
|
87
|
+
this.parseURL(true, `releases/download/v${version}/${name}-${version}.asar.gz`),
|
|
88
|
+
{ userAgent: this.ua, accept: "application/octet-stream", ...this.extraHeaders },
|
|
89
|
+
size,
|
|
90
|
+
onDownloading
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
export {
|
|
95
|
+
GitHubProvider,
|
|
96
|
+
downloadAsarBufferDefault,
|
|
97
|
+
downloadUpdateJSONDefault
|
|
98
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Promisable } from '@subframe7536/type-utils';
|
|
2
|
+
import { U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.cjs';
|
|
3
|
+
|
|
4
|
+
type URLHandler = (url: string, isDownloadAsar: boolean) => string;
|
|
5
|
+
type OnDownloading = (progress: DownloadingInfo) => void;
|
|
6
|
+
interface DownloadingInfo {
|
|
7
|
+
/**
|
|
8
|
+
* downloaded percent, 0% - 100%
|
|
9
|
+
*/
|
|
10
|
+
percent: `${number}%`;
|
|
11
|
+
/**
|
|
12
|
+
* total size
|
|
13
|
+
*/
|
|
14
|
+
total: number;
|
|
15
|
+
/**
|
|
16
|
+
* downloaded size
|
|
17
|
+
*/
|
|
18
|
+
current: number;
|
|
19
|
+
}
|
|
20
|
+
interface IProvider {
|
|
21
|
+
/**
|
|
22
|
+
* provider name
|
|
23
|
+
*/
|
|
24
|
+
name: string;
|
|
25
|
+
/**
|
|
26
|
+
* custom url handler
|
|
27
|
+
*
|
|
28
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDN links}
|
|
29
|
+
*/
|
|
30
|
+
urlHandler?: URLHandler;
|
|
31
|
+
onDownloading?: OnDownloading;
|
|
32
|
+
/**
|
|
33
|
+
* download update json
|
|
34
|
+
* @param versionPath parsed version path
|
|
35
|
+
*/
|
|
36
|
+
downloadJSON: (versionPath: string) => Promise<UpdateJSON>;
|
|
37
|
+
/**
|
|
38
|
+
* download update asar
|
|
39
|
+
* @param name app name
|
|
40
|
+
* @param updateInfo existing update info
|
|
41
|
+
* @param onDownloading hook for on downloading
|
|
42
|
+
*/
|
|
43
|
+
downloadBuffer: (name: string, updateInfo: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void) => Promise<Buffer>;
|
|
44
|
+
/**
|
|
45
|
+
* compare version
|
|
46
|
+
* @param oldVer old version string
|
|
47
|
+
* @param newVer new version string
|
|
48
|
+
* @returns if version1 < version2
|
|
49
|
+
*/
|
|
50
|
+
isLowerVersion: (oldVer: string, newVer: string) => Promisable<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* verify asar signature
|
|
53
|
+
* @param buffer file buffer
|
|
54
|
+
* @param signature signature
|
|
55
|
+
* @param cert certificate
|
|
56
|
+
* @returns if signature is valid, returns the version, otherwise returns `undefined`
|
|
57
|
+
*/
|
|
58
|
+
verifySignaure: (buffer: Buffer, signature: string, cert: string) => Promisable<string | undefined>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type { DownloadingInfo as D, IProvider as I, OnDownloading as O, URLHandler as U };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Promisable } from '@subframe7536/type-utils';
|
|
2
|
+
import { U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.js';
|
|
3
|
+
|
|
4
|
+
type URLHandler = (url: string, isDownloadAsar: boolean) => string;
|
|
5
|
+
type OnDownloading = (progress: DownloadingInfo) => void;
|
|
6
|
+
interface DownloadingInfo {
|
|
7
|
+
/**
|
|
8
|
+
* downloaded percent, 0% - 100%
|
|
9
|
+
*/
|
|
10
|
+
percent: `${number}%`;
|
|
11
|
+
/**
|
|
12
|
+
* total size
|
|
13
|
+
*/
|
|
14
|
+
total: number;
|
|
15
|
+
/**
|
|
16
|
+
* downloaded size
|
|
17
|
+
*/
|
|
18
|
+
current: number;
|
|
19
|
+
}
|
|
20
|
+
interface IProvider {
|
|
21
|
+
/**
|
|
22
|
+
* provider name
|
|
23
|
+
*/
|
|
24
|
+
name: string;
|
|
25
|
+
/**
|
|
26
|
+
* custom url handler
|
|
27
|
+
*
|
|
28
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDN links}
|
|
29
|
+
*/
|
|
30
|
+
urlHandler?: URLHandler;
|
|
31
|
+
onDownloading?: OnDownloading;
|
|
32
|
+
/**
|
|
33
|
+
* download update json
|
|
34
|
+
* @param versionPath parsed version path
|
|
35
|
+
*/
|
|
36
|
+
downloadJSON: (versionPath: string) => Promise<UpdateJSON>;
|
|
37
|
+
/**
|
|
38
|
+
* download update asar
|
|
39
|
+
* @param name app name
|
|
40
|
+
* @param updateInfo existing update info
|
|
41
|
+
* @param onDownloading hook for on downloading
|
|
42
|
+
*/
|
|
43
|
+
downloadBuffer: (name: string, updateInfo: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void) => Promise<Buffer>;
|
|
44
|
+
/**
|
|
45
|
+
* compare version
|
|
46
|
+
* @param oldVer old version string
|
|
47
|
+
* @param newVer new version string
|
|
48
|
+
* @returns if version1 < version2
|
|
49
|
+
*/
|
|
50
|
+
isLowerVersion: (oldVer: string, newVer: string) => Promisable<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* verify asar signature
|
|
53
|
+
* @param buffer file buffer
|
|
54
|
+
* @param signature signature
|
|
55
|
+
* @param cert certificate
|
|
56
|
+
* @returns if signature is valid, returns the version, otherwise returns `undefined`
|
|
57
|
+
*/
|
|
58
|
+
verifySignaure: (buffer: Buffer, signature: string, cert: string) => Promisable<string | undefined>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type { DownloadingInfo as D, IProvider as I, OnDownloading as O, URLHandler as U };
|
package/dist/utils.cjs
CHANGED
|
@@ -20,21 +20,33 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/utils/index.ts
|
|
21
21
|
var utils_exports = {};
|
|
22
22
|
__export(utils_exports, {
|
|
23
|
+
decrypt: () => decrypt,
|
|
23
24
|
disableHWAccForWin7: () => disableHWAccForWin7,
|
|
25
|
+
encrypt: () => encrypt,
|
|
26
|
+
getAppVersion: () => getAppVersion,
|
|
27
|
+
getEntryVersion: () => getEntryVersion,
|
|
24
28
|
getPathFromAppNameAsar: () => getPathFromAppNameAsar,
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
getPathFromEntryAsar: () => getPathFromEntryAsar,
|
|
30
|
+
getPathFromPreload: () => getPathFromPreload,
|
|
31
|
+
getPathFromPublic: () => getPathFromPublic,
|
|
27
32
|
handleUnexpectedErrors: () => handleUnexpectedErrors,
|
|
28
|
-
|
|
33
|
+
hashString: () => hashString,
|
|
34
|
+
isDev: () => isDev,
|
|
35
|
+
isLinux: () => isLinux,
|
|
36
|
+
isLowerVersionDefault: () => isLowerVersionDefault,
|
|
37
|
+
isMac: () => isMac,
|
|
29
38
|
isUpdateJSON: () => isUpdateJSON,
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
isWin: () => isWin,
|
|
40
|
+
loadPage: () => loadPage,
|
|
32
41
|
parseVersion: () => parseVersion,
|
|
42
|
+
requireNative: () => requireNative,
|
|
33
43
|
restartApp: () => restartApp,
|
|
34
44
|
setAppUserModelId: () => setAppUserModelId,
|
|
35
45
|
setPortableAppDataPath: () => setPortableAppDataPath,
|
|
46
|
+
signature: () => signature,
|
|
36
47
|
singleInstance: () => singleInstance,
|
|
37
48
|
unzipFile: () => unzipFile,
|
|
49
|
+
verifySignatureDefault: () => verifySignatureDefault,
|
|
38
50
|
waitAppReady: () => waitAppReady,
|
|
39
51
|
zipFile: () => zipFile
|
|
40
52
|
});
|
|
@@ -43,46 +55,32 @@ module.exports = __toCommonJS(utils_exports);
|
|
|
43
55
|
// src/utils/electron.ts
|
|
44
56
|
var import_node_fs = require("fs");
|
|
45
57
|
var import_node_path = require("path");
|
|
46
|
-
var import_node_os = require("os");
|
|
47
58
|
var import_electron = require("electron");
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
linux: process.platform === "linux"
|
|
53
|
-
};
|
|
59
|
+
var isDev = __EIU_IS_DEV__;
|
|
60
|
+
var isWin = process.platform === "win32";
|
|
61
|
+
var isMac = process.platform === "darwin";
|
|
62
|
+
var isLinux = process.platform === "linux";
|
|
54
63
|
function getPathFromAppNameAsar(...path) {
|
|
55
|
-
return
|
|
64
|
+
return isDev ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${import_electron.app.name}.asar`, ...path);
|
|
56
65
|
}
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
appVersion: is.dev ? import_electron.app.getVersion() : (0, import_node_fs.readFileSync)(getPathFromAppNameAsar("version"), "utf-8"),
|
|
61
|
-
entryVersion: import_electron.app.getVersion(),
|
|
62
|
-
electronVersion: process.versions.electron,
|
|
63
|
-
nodeVersion: process.versions.node,
|
|
64
|
-
systemVersion: `${platform} ${(0, import_node_os.release)()}`
|
|
65
|
-
};
|
|
66
|
+
function getAppVersion() {
|
|
67
|
+
return isDev ? getEntryVersion() : (0, import_node_fs.readFileSync)(getPathFromAppNameAsar("version"), "utf-8");
|
|
66
68
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
} catch (error) {
|
|
73
|
-
console.error("fail to load module", error);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
69
|
+
function getEntryVersion() {
|
|
70
|
+
return import_electron.app.getVersion();
|
|
71
|
+
}
|
|
72
|
+
function requireNative(moduleName) {
|
|
73
|
+
return require((0, import_node_path.join)(import_electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
|
|
76
74
|
}
|
|
77
75
|
function restartApp() {
|
|
78
76
|
import_electron.app.relaunch();
|
|
79
77
|
import_electron.app.quit();
|
|
80
78
|
}
|
|
81
79
|
function setAppUserModelId(id) {
|
|
82
|
-
import_electron.app.setAppUserModelId(
|
|
80
|
+
isWin && import_electron.app.setAppUserModelId(id ?? `org.${import_electron.app.name}`);
|
|
83
81
|
}
|
|
84
82
|
function disableHWAccForWin7() {
|
|
85
|
-
if ((
|
|
83
|
+
if (require("os").release().startsWith("6.1")) {
|
|
86
84
|
import_electron.app.disableHardwareAcceleration();
|
|
87
85
|
}
|
|
88
86
|
}
|
|
@@ -117,105 +115,59 @@ function waitAppReady(timeout = 1e3) {
|
|
|
117
115
|
});
|
|
118
116
|
});
|
|
119
117
|
}
|
|
120
|
-
function
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
* ```ts
|
|
132
|
-
* devServerURL && win.loadURL(devServerURL)
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
devServerURL,
|
|
136
|
-
/**
|
|
137
|
-
* @example
|
|
138
|
-
* ```ts
|
|
139
|
-
* win.loadFile(indexHTMLPath)
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
|
-
indexHTMLPath,
|
|
143
|
-
/**
|
|
144
|
-
* get path inside entry asar
|
|
145
|
-
* @param paths joined path
|
|
146
|
-
*/
|
|
147
|
-
getPathFromEntryAsar(...paths) {
|
|
148
|
-
return (0, import_node_path.join)(import_electron.app.getAppPath(), entryDirName, ...paths);
|
|
149
|
-
},
|
|
150
|
-
/**
|
|
151
|
-
* get path inside `${electron.app.name}.asar/main`
|
|
152
|
-
* @param paths joined path
|
|
153
|
-
*/
|
|
154
|
-
getPathFromMain(...paths) {
|
|
155
|
-
return (0, import_node_path.join)(mainDirPath, ...paths);
|
|
156
|
-
},
|
|
157
|
-
/**
|
|
158
|
-
* get path inside `${electron.app.name}.asar/preload`
|
|
159
|
-
* @param paths joined path
|
|
160
|
-
*/
|
|
161
|
-
getPathFromPreload(...paths) {
|
|
162
|
-
return (0, import_node_path.join)(preloadDirPath, ...paths);
|
|
163
|
-
},
|
|
164
|
-
/**
|
|
165
|
-
* get path inside public dir
|
|
166
|
-
* @param paths joined path
|
|
167
|
-
*/
|
|
168
|
-
getPathFromPublic(...paths) {
|
|
169
|
-
return (0, import_node_path.join)(publicDirPath, ...paths);
|
|
170
|
-
}
|
|
171
|
-
};
|
|
118
|
+
function loadPage(win, htmlFilePath = "index.html") {
|
|
119
|
+
isDev ? win.loadURL(process.env.VITE_DEV_SERVER_URL + htmlFilePath) : win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
|
|
120
|
+
}
|
|
121
|
+
function getPathFromPreload(...paths) {
|
|
122
|
+
return isDev ? (0, import_node_path.join)(import_electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
|
|
123
|
+
}
|
|
124
|
+
function getPathFromPublic(...paths) {
|
|
125
|
+
return isDev ? (0, import_node_path.join)(import_electron.app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
|
|
126
|
+
}
|
|
127
|
+
function getPathFromEntryAsar(...paths) {
|
|
128
|
+
return (0, import_node_path.join)(import_electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
|
|
172
129
|
}
|
|
173
130
|
|
|
174
131
|
// src/utils/zip.ts
|
|
175
132
|
var import_node_fs2 = require("fs");
|
|
176
133
|
var import_node_zlib = require("zlib");
|
|
177
|
-
async function
|
|
178
|
-
if (!(0, import_node_fs2.existsSync)(
|
|
179
|
-
throw new Error(`path to zipped
|
|
134
|
+
async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
135
|
+
if (!(0, import_node_fs2.existsSync)(filePath)) {
|
|
136
|
+
throw new Error(`path to be zipped not exist: ${filePath}`);
|
|
180
137
|
}
|
|
181
|
-
const
|
|
138
|
+
const buffer = (0, import_node_fs2.readFileSync)(filePath);
|
|
182
139
|
return new Promise((resolve, reject) => {
|
|
183
|
-
(0, import_node_zlib.
|
|
184
|
-
(0, import_node_fs2.rmSync)(gzipPath);
|
|
140
|
+
(0, import_node_zlib.brotliCompress)(buffer, (err, buffer2) => {
|
|
185
141
|
if (err) {
|
|
186
142
|
reject(err);
|
|
187
143
|
}
|
|
188
|
-
(0, import_node_fs2.writeFileSync)(targetFilePath,
|
|
144
|
+
(0, import_node_fs2.writeFileSync)(targetFilePath, buffer2);
|
|
189
145
|
resolve(null);
|
|
190
146
|
});
|
|
191
147
|
});
|
|
192
148
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
149
|
+
|
|
150
|
+
// src/utils/unzip.ts
|
|
151
|
+
var import_node_fs3 = require("fs");
|
|
152
|
+
var import_node_zlib2 = require("zlib");
|
|
153
|
+
async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
154
|
+
if (!(0, import_node_fs3.existsSync)(gzipPath)) {
|
|
155
|
+
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
196
156
|
}
|
|
197
|
-
const
|
|
157
|
+
const compressedBuffer = (0, import_node_fs3.readFileSync)(gzipPath);
|
|
198
158
|
return new Promise((resolve, reject) => {
|
|
199
|
-
(0,
|
|
159
|
+
(0, import_node_zlib2.brotliDecompress)(compressedBuffer, (err, buffer) => {
|
|
160
|
+
(0, import_node_fs3.rmSync)(gzipPath);
|
|
200
161
|
if (err) {
|
|
201
162
|
reject(err);
|
|
202
163
|
}
|
|
203
|
-
(0,
|
|
164
|
+
(0, import_node_fs3.writeFileSync)(targetFilePath, buffer);
|
|
204
165
|
resolve(null);
|
|
205
166
|
});
|
|
206
167
|
});
|
|
207
168
|
}
|
|
208
169
|
|
|
209
|
-
// src/utils/
|
|
210
|
-
function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
211
|
-
if (!originRepoURL.startsWith("https://github.com/")) {
|
|
212
|
-
throw new Error("origin url must start with https://github.com/");
|
|
213
|
-
}
|
|
214
|
-
originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
|
|
215
|
-
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
216
|
-
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
217
|
-
return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
218
|
-
}
|
|
170
|
+
// src/utils/version.ts
|
|
219
171
|
function handleUnexpectedErrors(callback) {
|
|
220
172
|
process.on("uncaughtException", callback);
|
|
221
173
|
process.on("unhandledRejection", callback);
|
|
@@ -243,27 +195,99 @@ function parseVersion(version) {
|
|
|
243
195
|
}
|
|
244
196
|
return ret;
|
|
245
197
|
}
|
|
198
|
+
function isLowerVersionDefault(oldVer, newVer) {
|
|
199
|
+
const oldV = parseVersion(oldVer);
|
|
200
|
+
const newV = parseVersion(newVer);
|
|
201
|
+
function compareStrings(str1, str2) {
|
|
202
|
+
if (str1 === "") {
|
|
203
|
+
return str2 !== "";
|
|
204
|
+
} else if (str2 === "") {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
return str1 < str2;
|
|
208
|
+
}
|
|
209
|
+
for (let key of Object.keys(oldV)) {
|
|
210
|
+
if (key === "stage" && compareStrings(oldV[key], newV[key])) {
|
|
211
|
+
return true;
|
|
212
|
+
} else if (oldV[key] !== newV[key]) {
|
|
213
|
+
return oldV[key] < newV[key];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
246
218
|
function isUpdateJSON(json) {
|
|
247
|
-
const
|
|
248
|
-
return
|
|
219
|
+
const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
|
|
220
|
+
return is(json) && is(json?.beta);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// src/utils/crypto/decrypt.ts
|
|
224
|
+
var import_node_crypto2 = require("crypto");
|
|
225
|
+
|
|
226
|
+
// src/utils/crypto/utils.ts
|
|
227
|
+
var import_node_crypto = require("crypto");
|
|
228
|
+
function hashString(data, length) {
|
|
229
|
+
const hash = (0, import_node_crypto.createHash)("SHA256").update(data).digest("binary");
|
|
230
|
+
return Buffer.from(hash).subarray(0, length);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/utils/crypto/decrypt.ts
|
|
234
|
+
function decrypt(encryptedText, key, iv) {
|
|
235
|
+
const decipher = (0, import_node_crypto2.createDecipheriv)("aes-256-cbc", key, iv);
|
|
236
|
+
let decrypted = decipher.update(encryptedText, "base64url", "utf8");
|
|
237
|
+
decrypted += decipher.final("utf8");
|
|
238
|
+
return decrypted;
|
|
239
|
+
}
|
|
240
|
+
function verifySignatureDefault(buffer, signature2, cert) {
|
|
241
|
+
try {
|
|
242
|
+
const [sig, version] = decrypt(signature2, hashString(cert, 32), hashString(buffer, 16)).split("%");
|
|
243
|
+
const result = (0, import_node_crypto2.createVerify)("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
244
|
+
return result ? version : void 0;
|
|
245
|
+
} catch (error) {
|
|
246
|
+
return void 0;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/utils/crypto/encrypt.ts
|
|
251
|
+
var import_node_crypto3 = require("crypto");
|
|
252
|
+
function encrypt(plainText, key, iv) {
|
|
253
|
+
const cipher = (0, import_node_crypto3.createCipheriv)("aes-256-cbc", key, iv);
|
|
254
|
+
let encrypted = cipher.update(plainText, "utf8", "base64url");
|
|
255
|
+
encrypted += cipher.final("base64url");
|
|
256
|
+
return encrypted;
|
|
257
|
+
}
|
|
258
|
+
function signature(buffer, privateKey, cert, version) {
|
|
259
|
+
const sig = (0, import_node_crypto3.createSign)("RSA-SHA256").update(buffer).sign((0, import_node_crypto3.createPrivateKey)(privateKey), "base64");
|
|
260
|
+
return encrypt(`${sig}%${version}`, hashString(cert, 32), hashString(buffer, 16));
|
|
249
261
|
}
|
|
250
262
|
// Annotate the CommonJS export names for ESM import in node:
|
|
251
263
|
0 && (module.exports = {
|
|
264
|
+
decrypt,
|
|
252
265
|
disableHWAccForWin7,
|
|
266
|
+
encrypt,
|
|
267
|
+
getAppVersion,
|
|
268
|
+
getEntryVersion,
|
|
253
269
|
getPathFromAppNameAsar,
|
|
254
|
-
|
|
255
|
-
|
|
270
|
+
getPathFromEntryAsar,
|
|
271
|
+
getPathFromPreload,
|
|
272
|
+
getPathFromPublic,
|
|
256
273
|
handleUnexpectedErrors,
|
|
257
|
-
|
|
274
|
+
hashString,
|
|
275
|
+
isDev,
|
|
276
|
+
isLinux,
|
|
277
|
+
isLowerVersionDefault,
|
|
278
|
+
isMac,
|
|
258
279
|
isUpdateJSON,
|
|
259
|
-
|
|
260
|
-
|
|
280
|
+
isWin,
|
|
281
|
+
loadPage,
|
|
261
282
|
parseVersion,
|
|
283
|
+
requireNative,
|
|
262
284
|
restartApp,
|
|
263
285
|
setAppUserModelId,
|
|
264
286
|
setPortableAppDataPath,
|
|
287
|
+
signature,
|
|
265
288
|
singleInstance,
|
|
266
289
|
unzipFile,
|
|
290
|
+
verifySignatureDefault,
|
|
267
291
|
waitAppReady,
|
|
268
292
|
zipFile
|
|
269
293
|
});
|