electron-incremental-update 2.0.0-beta.2 → 2.0.0-beta.4

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.
@@ -0,0 +1,76 @@
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/version.ts
9
+ function handleUnexpectedErrors(callback) {
10
+ process.on("uncaughtException", callback);
11
+ process.on("unhandledRejection", callback);
12
+ }
13
+ function parseVersion(version) {
14
+ const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
15
+ if (!match) {
16
+ throw new TypeError(`invalid version: ${version}`);
17
+ }
18
+ const [major, minor, patch] = match.slice(1, 4).map(Number);
19
+ const ret = {
20
+ major,
21
+ minor,
22
+ patch,
23
+ stage: "",
24
+ stageVersion: -1
25
+ };
26
+ if (match[4]) {
27
+ let [stage, _v] = match[4].split(".");
28
+ ret.stage = stage;
29
+ ret.stageVersion = Number(_v) || -1;
30
+ }
31
+ if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
32
+ throw new TypeError(`invalid version: ${version}`);
33
+ }
34
+ return ret;
35
+ }
36
+ function defaultIsLowerVersion(oldVer, newVer) {
37
+ const oldV = parseVersion(oldVer);
38
+ const newV = parseVersion(newVer);
39
+ function compareStrings(str1, str2) {
40
+ if (str1 === "") {
41
+ return str2 !== "";
42
+ } else if (str2 === "") {
43
+ return true;
44
+ }
45
+ return str1 < str2;
46
+ }
47
+ for (let key of Object.keys(oldV)) {
48
+ if (key === "stage" && compareStrings(oldV[key], newV[key])) {
49
+ return true;
50
+ } else if (oldV[key] !== newV[key]) {
51
+ return oldV[key] < newV[key];
52
+ }
53
+ }
54
+ return false;
55
+ }
56
+ function isUpdateJSON(json) {
57
+ const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
58
+ return is(json) && is(json?.beta);
59
+ }
60
+ function defaultVersionJsonGenerator(existingJson, buffer, signature, version, minimumVersion) {
61
+ existingJson.beta = {
62
+ version,
63
+ minimumVersion,
64
+ signature,
65
+ size: buffer.length
66
+ };
67
+ if (!parseVersion(version).stage) {
68
+ existingJson.version = version;
69
+ existingJson.minimumVersion = minimumVersion;
70
+ existingJson.signature = signature;
71
+ existingJson.size = buffer.length;
72
+ }
73
+ return existingJson;
74
+ }
75
+
76
+ export { __require, defaultIsLowerVersion, defaultVersionJsonGenerator, handleUnexpectedErrors, isUpdateJSON, parseVersion };
@@ -0,0 +1,53 @@
1
+ import { brotliCompress, brotliDecompress } from 'node:zlib';
2
+ import { createHash, createCipheriv, createSign, createPrivateKey, createDecipheriv, createVerify } from 'node:crypto';
3
+
4
+ // src/utils/zip.ts
5
+ async function defaultZipFile(buffer) {
6
+ return new Promise((resolve, reject) => {
7
+ brotliCompress(buffer, (err, buffer2) => {
8
+ if (err) {
9
+ reject(err);
10
+ } else {
11
+ resolve(buffer2);
12
+ }
13
+ });
14
+ });
15
+ }
16
+ async function defaultUnzipFile(buffer) {
17
+ return new Promise((resolve, reject) => {
18
+ brotliDecompress(buffer, (err, buffer2) => {
19
+ if (err) {
20
+ reject(err);
21
+ } else {
22
+ resolve(buffer2);
23
+ }
24
+ });
25
+ });
26
+ }
27
+ function hashBuffer(data, length) {
28
+ const hash = createHash("SHA256").update(data).digest("binary");
29
+ return Buffer.from(hash).subarray(0, length);
30
+ }
31
+ function aesEncrypt(plainText, key, iv) {
32
+ const cipher = createCipheriv("aes-256-cbc", key, iv);
33
+ return cipher.update(plainText, "utf8", "base64url") + cipher.final("base64url");
34
+ }
35
+ function defaultSignature(buffer, privateKey, cert, version) {
36
+ const sig = createSign("RSA-SHA256").update(buffer).sign(createPrivateKey(privateKey), "base64");
37
+ return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
38
+ }
39
+ function aesDecrypt(encryptedText, key, iv) {
40
+ const decipher = createDecipheriv("aes-256-cbc", key, iv);
41
+ return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
42
+ }
43
+ function defaultVerify(buffer, signature, cert) {
44
+ try {
45
+ const [sig, version] = aesDecrypt(signature, hashBuffer(cert, 32), hashBuffer(buffer, 16)).split("%");
46
+ const result = createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
47
+ return result ? version : void 0;
48
+ } catch {
49
+ return void 0;
50
+ }
51
+ }
52
+
53
+ export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerify, defaultZipFile, hashBuffer };
@@ -0,0 +1,77 @@
1
+ import { __require } from './chunk-BVFQWBLK.js';
2
+ import { readFileSync, existsSync, mkdirSync } from 'node:fs';
3
+ import { join, dirname } from 'node:path';
4
+ import { app } from 'electron';
5
+
6
+ var isDev = __EIU_IS_DEV__;
7
+ var isWin = process.platform === "win32";
8
+ var isMac = process.platform === "darwin";
9
+ var isLinux = process.platform === "linux";
10
+ function getPathFromAppNameAsar(...path) {
11
+ return isDev ? "DEV.asar" : join(dirname(app.getAppPath()), `${app.name}.asar`, ...path);
12
+ }
13
+ function getAppVersion() {
14
+ return isDev ? getEntryVersion() : readFileSync(getPathFromAppNameAsar("version"), "utf-8");
15
+ }
16
+ function getEntryVersion() {
17
+ return app.getVersion();
18
+ }
19
+ function requireNative(moduleName) {
20
+ return __require(join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
21
+ }
22
+ function restartApp() {
23
+ app.relaunch();
24
+ app.quit();
25
+ }
26
+ function setAppUserModelId(id) {
27
+ if (isWin) {
28
+ app.setAppUserModelId(id ?? `org.${app.name}`);
29
+ }
30
+ }
31
+ function disableHWAccForWin7() {
32
+ if (__require("node:os").release().startsWith("6.1")) {
33
+ app.disableHardwareAcceleration();
34
+ }
35
+ }
36
+ function singleInstance(window) {
37
+ const result = app.requestSingleInstanceLock();
38
+ if (result) {
39
+ app.on("second-instance", () => {
40
+ if (window) {
41
+ window.show();
42
+ if (window.isMinimized()) {
43
+ window.restore();
44
+ }
45
+ window.focus();
46
+ }
47
+ });
48
+ } else {
49
+ app.quit();
50
+ }
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 loadPage(win, htmlFilePath = "index.html") {
61
+ if (isDev) {
62
+ win.loadURL(process.env.VITE_DEV_SERVER_URL + htmlFilePath);
63
+ } else {
64
+ win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
65
+ }
66
+ }
67
+ function getPathFromPreload(...paths) {
68
+ return isDev ? join(app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
69
+ }
70
+ function getPathFromPublic(...paths) {
71
+ return isDev ? join(app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
72
+ }
73
+ function getPathFromEntryAsar(...paths) {
74
+ return join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
75
+ }
76
+
77
+ export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
@@ -0,0 +1,134 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, I as IProvider, c as URLHandler } from './types-Bz1VD18z.cjs';
3
+
4
+ declare const ErrorInfo: {
5
+ readonly download: "Download failed";
6
+ readonly validate: "Validate failed";
7
+ readonly param: "Missing params";
8
+ readonly network: "Network error";
9
+ };
10
+ declare class UpdaterError extends Error {
11
+ code: keyof typeof ErrorInfo;
12
+ constructor(msg: keyof typeof ErrorInfo, info: string);
13
+ }
14
+ type CheckResult<T extends UpdateJSON> = {
15
+ success: true;
16
+ data: Omit<T, 'beta'>;
17
+ } | {
18
+ success: false;
19
+ /**
20
+ * minimal version that can update
21
+ */
22
+ data: string;
23
+ } | {
24
+ success: false;
25
+ data: UpdaterError;
26
+ };
27
+ type DownloadResult = {
28
+ success: true;
29
+ } | {
30
+ success: false;
31
+ data: UpdaterError;
32
+ };
33
+ interface Logger {
34
+ info: (msg: string) => void;
35
+ debug: (msg: string) => void;
36
+ warn: (msg: string) => void;
37
+ error: (msg: string, e?: unknown) => void;
38
+ }
39
+ interface UpdaterOption {
40
+ /**
41
+ * public key of signature, which will be auto generated by plugin,
42
+ * generate by `selfsigned` if not set
43
+ */
44
+ SIGNATURE_CERT?: string;
45
+ /**
46
+ * whether to receive beta update
47
+ */
48
+ receiveBeta?: boolean;
49
+ logger?: Logger;
50
+ }
51
+
52
+ declare class Updater extends EventEmitter<{
53
+ 'checking': any;
54
+ 'update-available': [data: UpdateInfo];
55
+ 'update-unavailable': [reason: string];
56
+ 'error': [error: UpdaterError];
57
+ 'download-progress': [info: DownloadingInfo];
58
+ 'update-downloaded': any;
59
+ }> {
60
+ private CERT;
61
+ private info?;
62
+ private provider;
63
+ /**
64
+ * updater logger
65
+ */
66
+ logger?: Logger;
67
+ /**
68
+ * whether to receive beta update
69
+ */
70
+ receiveBeta?: boolean;
71
+ /**
72
+ * whether force update in DEV
73
+ */
74
+ forceUpdate?: boolean;
75
+ /**
76
+ * initialize incremental updater
77
+ * @param provider update provider
78
+ * @param option UpdaterOption
79
+ */
80
+ constructor(provider: IProvider, option?: UpdaterOption);
81
+ /**
82
+ * this function is used to parse download data.
83
+ * - if format is `'json'`
84
+ * - if data is `UpdateJSON`, return it
85
+ * - if data is string or absent, download URL data and return it
86
+ * - if format is `'buffer'`
87
+ * - if data is `Buffer`, return it
88
+ * - if data is string or absent, download URL data and return it
89
+ * @param format 'json' or 'buffer'
90
+ * @param data download URL or update json or buffer
91
+ */
92
+ private fetch;
93
+ /**
94
+ * handle error message and emit error event
95
+ */
96
+ private err;
97
+ /**
98
+ * check update info using default options
99
+ */
100
+ checkUpdate(): Promise<boolean>;
101
+ /**
102
+ * check update info using existing update json
103
+ * @param data existing update json
104
+ */
105
+ checkUpdate(data: UpdateJSON): Promise<boolean>;
106
+ /**
107
+ * download update using default options
108
+ */
109
+ downloadUpdate(): Promise<boolean>;
110
+ /**
111
+ * download update using existing `asar.gz` buffer and signature
112
+ * @param data existing `asar.gz` buffer
113
+ * @param sig signature
114
+ */
115
+ downloadUpdate(data: Uint8Array | Buffer, sig: string): Promise<boolean>;
116
+ /**
117
+ * quit App and install
118
+ */
119
+ quitAndInstall(): void;
120
+ /**
121
+ * setup provider URL handler
122
+ *
123
+ * @example
124
+ * updater.setURLHandler((url, isDownloadingAsar) => {
125
+ * if (isDownloadingAsar) {
126
+ * url.hostname = 'https://cdn.jsdelivr.net/gh'
127
+ * return url
128
+ * }
129
+ * })
130
+ */
131
+ setURLHandler(handler: URLHandler): void;
132
+ }
133
+
134
+ export { type CheckResult as C, type DownloadResult as D, ErrorInfo as E, type Logger as L, Updater as U, type UpdaterOption as a, UpdaterError as b };
@@ -0,0 +1,134 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, I as IProvider, c as URLHandler } from './types-Bz1VD18z.js';
3
+
4
+ declare const ErrorInfo: {
5
+ readonly download: "Download failed";
6
+ readonly validate: "Validate failed";
7
+ readonly param: "Missing params";
8
+ readonly network: "Network error";
9
+ };
10
+ declare class UpdaterError extends Error {
11
+ code: keyof typeof ErrorInfo;
12
+ constructor(msg: keyof typeof ErrorInfo, info: string);
13
+ }
14
+ type CheckResult<T extends UpdateJSON> = {
15
+ success: true;
16
+ data: Omit<T, 'beta'>;
17
+ } | {
18
+ success: false;
19
+ /**
20
+ * minimal version that can update
21
+ */
22
+ data: string;
23
+ } | {
24
+ success: false;
25
+ data: UpdaterError;
26
+ };
27
+ type DownloadResult = {
28
+ success: true;
29
+ } | {
30
+ success: false;
31
+ data: UpdaterError;
32
+ };
33
+ interface Logger {
34
+ info: (msg: string) => void;
35
+ debug: (msg: string) => void;
36
+ warn: (msg: string) => void;
37
+ error: (msg: string, e?: unknown) => void;
38
+ }
39
+ interface UpdaterOption {
40
+ /**
41
+ * public key of signature, which will be auto generated by plugin,
42
+ * generate by `selfsigned` if not set
43
+ */
44
+ SIGNATURE_CERT?: string;
45
+ /**
46
+ * whether to receive beta update
47
+ */
48
+ receiveBeta?: boolean;
49
+ logger?: Logger;
50
+ }
51
+
52
+ declare class Updater extends EventEmitter<{
53
+ 'checking': any;
54
+ 'update-available': [data: UpdateInfo];
55
+ 'update-unavailable': [reason: string];
56
+ 'error': [error: UpdaterError];
57
+ 'download-progress': [info: DownloadingInfo];
58
+ 'update-downloaded': any;
59
+ }> {
60
+ private CERT;
61
+ private info?;
62
+ private provider;
63
+ /**
64
+ * updater logger
65
+ */
66
+ logger?: Logger;
67
+ /**
68
+ * whether to receive beta update
69
+ */
70
+ receiveBeta?: boolean;
71
+ /**
72
+ * whether force update in DEV
73
+ */
74
+ forceUpdate?: boolean;
75
+ /**
76
+ * initialize incremental updater
77
+ * @param provider update provider
78
+ * @param option UpdaterOption
79
+ */
80
+ constructor(provider: IProvider, option?: UpdaterOption);
81
+ /**
82
+ * this function is used to parse download data.
83
+ * - if format is `'json'`
84
+ * - if data is `UpdateJSON`, return it
85
+ * - if data is string or absent, download URL data and return it
86
+ * - if format is `'buffer'`
87
+ * - if data is `Buffer`, return it
88
+ * - if data is string or absent, download URL data and return it
89
+ * @param format 'json' or 'buffer'
90
+ * @param data download URL or update json or buffer
91
+ */
92
+ private fetch;
93
+ /**
94
+ * handle error message and emit error event
95
+ */
96
+ private err;
97
+ /**
98
+ * check update info using default options
99
+ */
100
+ checkUpdate(): Promise<boolean>;
101
+ /**
102
+ * check update info using existing update json
103
+ * @param data existing update json
104
+ */
105
+ checkUpdate(data: UpdateJSON): Promise<boolean>;
106
+ /**
107
+ * download update using default options
108
+ */
109
+ downloadUpdate(): Promise<boolean>;
110
+ /**
111
+ * download update using existing `asar.gz` buffer and signature
112
+ * @param data existing `asar.gz` buffer
113
+ * @param sig signature
114
+ */
115
+ downloadUpdate(data: Uint8Array | Buffer, sig: string): Promise<boolean>;
116
+ /**
117
+ * quit App and install
118
+ */
119
+ quitAndInstall(): void;
120
+ /**
121
+ * setup provider URL handler
122
+ *
123
+ * @example
124
+ * updater.setURLHandler((url, isDownloadingAsar) => {
125
+ * if (isDownloadingAsar) {
126
+ * url.hostname = 'https://cdn.jsdelivr.net/gh'
127
+ * return url
128
+ * }
129
+ * })
130
+ */
131
+ setURLHandler(handler: URLHandler): void;
132
+ }
133
+
134
+ export { type CheckResult as C, type DownloadResult as D, ErrorInfo as E, type Logger as L, Updater as U, type UpdaterOption as a, UpdaterError as b };