electron-incremental-update 2.0.0-beta.3 → 2.0.0-beta.5

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.
@@ -6,10 +6,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  });
7
7
 
8
8
  // src/utils/version.ts
9
- function handleUnexpectedErrors(callback) {
10
- process.on("uncaughtException", callback);
11
- process.on("unhandledRejection", callback);
12
- }
13
9
  function parseVersion(version) {
14
10
  const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
15
11
  if (!match) {
@@ -54,23 +50,21 @@ function defaultIsLowerVersion(oldVer, newVer) {
54
50
  return false;
55
51
  }
56
52
  function isUpdateJSON(json) {
57
- const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
53
+ const is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
58
54
  return is(json) && is(json?.beta);
59
55
  }
60
- function defaultVersionJsonGenerator(existingJson, buffer, signature, version, minimumVersion) {
56
+ function defaultVersionJsonGenerator(existingJson, signature, version, minimumVersion) {
61
57
  existingJson.beta = {
62
58
  version,
63
59
  minimumVersion,
64
- signature,
65
- size: buffer.length
60
+ signature
66
61
  };
67
62
  if (!parseVersion(version).stage) {
68
63
  existingJson.version = version;
69
64
  existingJson.minimumVersion = minimumVersion;
70
65
  existingJson.signature = signature;
71
- existingJson.size = buffer.length;
72
66
  }
73
67
  return existingJson;
74
68
  }
75
69
 
76
- export { __require, defaultIsLowerVersion, defaultVersionJsonGenerator, handleUnexpectedErrors, isUpdateJSON, parseVersion };
70
+ export { __require, defaultIsLowerVersion, defaultVersionJsonGenerator, isUpdateJSON, parseVersion };
@@ -1,4 +1,4 @@
1
- import { __require } from './chunk-BVFQWBLK.js';
1
+ import { __require } from './chunk-72ZAJ7AF.js';
2
2
  import { readFileSync, existsSync, mkdirSync } from 'node:fs';
3
3
  import { join, dirname } from 'node:path';
4
4
  import { app } from 'electron';
@@ -73,5 +73,9 @@ function getPathFromPublic(...paths) {
73
73
  function getPathFromEntryAsar(...paths) {
74
74
  return join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
75
75
  }
76
+ function handleUnexpectedErrors(callback) {
77
+ process.on("uncaughtException", callback);
78
+ process.on("unhandledRejection", callback);
79
+ }
76
80
 
77
- export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
81
+ export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
@@ -1,16 +1,26 @@
1
- import { writeFileSync } from 'node:fs';
2
- import { brotliDecompress } from 'node:zlib';
1
+ import { brotliCompress, brotliDecompress } from 'node:zlib';
3
2
  import { createHash, createCipheriv, createSign, createPrivateKey, createDecipheriv, createVerify } from 'node:crypto';
4
3
 
5
- // src/utils/unzip.ts
6
- async function defaultUnzipFile(buffer, targetFilePath) {
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) {
7
17
  return new Promise((resolve, reject) => {
8
18
  brotliDecompress(buffer, (err, buffer2) => {
9
19
  if (err) {
10
20
  reject(err);
21
+ } else {
22
+ resolve(buffer2);
11
23
  }
12
- writeFileSync(targetFilePath, buffer2);
13
- resolve();
14
24
  });
15
25
  });
16
26
  }
@@ -40,4 +50,4 @@ function defaultVerify(buffer, signature, cert) {
40
50
  }
41
51
  }
42
52
 
43
- export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerify, hashBuffer };
53
+ export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerify, defaultZipFile, hashBuffer };
@@ -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-C5P0h_bB.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 };
@@ -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-C5P0h_bB.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 };
package/dist/index.cjs CHANGED
@@ -14,7 +14,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
14
14
 
15
15
  // src/utils/version.ts
16
16
  function isUpdateJSON(json) {
17
- const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
17
+ const is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
18
18
  return is(json) && is(json?.beta);
19
19
  }
20
20
  var isDev = __EIU_IS_DEV__;
@@ -54,8 +54,6 @@ var UpdaterError = class extends Error {
54
54
  var Updater = class extends events.EventEmitter {
55
55
  CERT = __EIU_SIGNATURE_CERT__;
56
56
  info;
57
- asarPath;
58
- tmpFilePath;
59
57
  provider;
60
58
  /**
61
59
  * updater logger
@@ -93,14 +91,8 @@ var Updater = class extends events.EventEmitter {
93
91
  };
94
92
  this.logger.info("no logger set, enable dev-only logger");
95
93
  }
96
- this.asarPath = getPathFromAppNameAsar();
97
- this.tmpFilePath = `${this.asarPath}.tmp`;
98
94
  }
99
95
  async fetch(format, data) {
100
- if (fs.existsSync(this.tmpFilePath)) {
101
- this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
102
- fs.rmSync(this.tmpFilePath);
103
- }
104
96
  if (typeof data === "object") {
105
97
  if (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer.isBuffer(data)) {
106
98
  return data;
@@ -136,14 +128,13 @@ var Updater = class extends events.EventEmitter {
136
128
  if (!_data) {
137
129
  return emitUnavailable("failed to get update info");
138
130
  }
139
- let { signature, size, version, minimumVersion, beta } = _data;
131
+ let { signature, version, minimumVersion, beta } = _data;
140
132
  if (this.receiveBeta) {
141
133
  version = beta.version;
142
134
  signature = beta.signature;
143
135
  minimumVersion = beta.minimumVersion;
144
- size = beta.size;
145
136
  }
146
- this.logger?.debug(`checked update, version: ${version}, size: ${size}, signature: ${signature}`);
137
+ this.logger?.debug(`checked update, version: ${version}, signature: ${signature}`);
147
138
  if (isDev && !this.forceUpdate && !data) {
148
139
  return emitUnavailable("skip check update in dev mode, to force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON");
149
140
  }
@@ -158,11 +149,11 @@ var Updater = class extends events.EventEmitter {
158
149
  return emitUnavailable(`current version (${appVersion}) < new version (${version})`);
159
150
  }
160
151
  this.logger?.info(`update available: ${version}`);
161
- this.info = { signature, minimumVersion, version, size };
152
+ this.info = { signature, minimumVersion, version };
162
153
  this.emit("update-available", this.info);
163
154
  return true;
164
155
  }
165
- async download(data, sig) {
156
+ async downloadUpdate(data, sig) {
166
157
  const _sig = sig ?? this.info?.signature;
167
158
  if (!_sig) {
168
159
  this.err("download failed", "param", "no update signature, please call `checkUpdate` first");
@@ -181,8 +172,9 @@ var Updater = class extends events.EventEmitter {
181
172
  }
182
173
  this.logger?.debug("verify success");
183
174
  try {
184
- this.logger?.debug(`extract to ${this.tmpFilePath}`);
185
- await this.provider.unzipFile(buffer, this.tmpFilePath);
175
+ const tmpFilePath = getPathFromAppNameAsar() + ".tmp";
176
+ this.logger?.debug(`install to ${tmpFilePath}`);
177
+ fs.writeFileSync(tmpFilePath, await this.provider.unzipFile(buffer));
186
178
  this.logger?.info(`download success, version: ${_ver}`);
187
179
  this.info = void 0;
188
180
  this.emit("update-downloaded");
@@ -205,7 +197,8 @@ var Updater = class extends events.EventEmitter {
205
197
  * @example
206
198
  * updater.setURLHandler((url, isDownloadingAsar) => {
207
199
  * if (isDownloadingAsar) {
208
- * return url.replace('https://raw.githubusercontent.com', 'https://cdn.jsdelivr.net/gh')
200
+ * url.hostname = 'https://cdn.jsdelivr.net/gh'
201
+ * return url
209
202
  * }
210
203
  * })
211
204
  */
package/dist/index.d.cts CHANGED
@@ -1,139 +1,9 @@
1
- import { EventEmitter } from 'node:events';
2
- import { U as UpdateJSON, a as UpdateInfo } from './version-CemSHimT.cjs';
3
- import { D as DownloadingInfo, I as IProvider, U as URLHandler } from './types-Tequ_V2o.cjs';
1
+ import { U as Updater, a as UpdaterOption, L as Logger } from './core-DmU2Vk_S.cjs';
2
+ export { C as CheckResult, D as DownloadResult, E as ErrorInfo, b as UpdaterError } from './core-DmU2Vk_S.cjs';
3
+ import { I as IProvider } from './types-C5P0h_bB.cjs';
4
+ import 'node:events';
4
5
  import '@subframe7536/type-utils';
5
6
 
6
- declare const ErrorInfo: {
7
- readonly download: "Download failed";
8
- readonly validate: "Validate failed";
9
- readonly param: "Missing params";
10
- readonly network: "Network error";
11
- };
12
- declare class UpdaterError extends Error {
13
- code: keyof typeof ErrorInfo;
14
- constructor(msg: keyof typeof ErrorInfo, info: string);
15
- }
16
- type CheckResult<T extends UpdateJSON> = {
17
- success: true;
18
- data: Omit<T, 'beta'>;
19
- } | {
20
- success: false;
21
- /**
22
- * minimal version that can update
23
- */
24
- data: string;
25
- } | {
26
- success: false;
27
- data: UpdaterError;
28
- };
29
- type DownloadResult = {
30
- success: true;
31
- } | {
32
- success: false;
33
- data: UpdaterError;
34
- };
35
- interface Logger {
36
- info: (msg: string) => void;
37
- debug: (msg: string) => void;
38
- warn: (msg: string) => void;
39
- error: (msg: string, e?: unknown) => void;
40
- }
41
- interface UpdaterOption {
42
- /**
43
- * public key of signature, which will be auto generated by plugin,
44
- * generate by `selfsigned` if not set
45
- */
46
- SIGNATURE_CERT?: string;
47
- /**
48
- * whether to receive beta update
49
- */
50
- receiveBeta?: boolean;
51
- logger?: Logger;
52
- }
53
-
54
- declare class Updater extends EventEmitter<{
55
- 'checking': any;
56
- 'update-available': [data: UpdateInfo];
57
- 'update-unavailable': [reason: string];
58
- 'error': [error: UpdaterError];
59
- 'download-progress': [info: DownloadingInfo];
60
- 'update-downloaded': any;
61
- }> {
62
- private CERT;
63
- private info?;
64
- private asarPath;
65
- private tmpFilePath;
66
- private provider;
67
- /**
68
- * updater logger
69
- */
70
- logger?: Logger;
71
- /**
72
- * whether to receive beta update
73
- */
74
- receiveBeta?: boolean;
75
- /**
76
- * whether force update in DEV
77
- */
78
- forceUpdate?: boolean;
79
- /**
80
- * initialize incremental updater
81
- * @param provider update provider
82
- * @param option UpdaterOption
83
- */
84
- constructor(provider: IProvider, option?: UpdaterOption);
85
- /**
86
- * this function is used to parse download data.
87
- * - if format is `'json'`
88
- * - if data is `UpdateJSON`, return it
89
- * - if data is string or absent, download URL data and return it
90
- * - if format is `'buffer'`
91
- * - if data is `Buffer`, return it
92
- * - if data is string or absent, download URL data and return it
93
- * @param format 'json' or 'buffer'
94
- * @param data download URL or update json or buffer
95
- */
96
- private fetch;
97
- /**
98
- * handle error message and emit error event
99
- */
100
- private err;
101
- /**
102
- * check update info using default options
103
- */
104
- checkUpdate(): Promise<boolean>;
105
- /**
106
- * check update info using existing update json
107
- * @param data existing update json
108
- */
109
- checkUpdate(data: UpdateJSON): Promise<boolean>;
110
- /**
111
- * download update using default options
112
- */
113
- download(): Promise<boolean>;
114
- /**
115
- * download update using existing `asar.gz` buffer and signature
116
- * @param data existing `asar.gz` buffer
117
- * @param sig signature
118
- */
119
- download(data: Uint8Array | Buffer, sig: string): Promise<boolean>;
120
- /**
121
- * quit App and install
122
- */
123
- quitAndInstall(): void;
124
- /**
125
- * setup provider URL handler
126
- *
127
- * @example
128
- * updater.setURLHandler((url, isDownloadingAsar) => {
129
- * if (isDownloadingAsar) {
130
- * return url.replace('https://raw.githubusercontent.com', 'https://cdn.jsdelivr.net/gh')
131
- * }
132
- * })
133
- */
134
- setURLHandler(handler: URLHandler): void;
135
- }
136
-
137
7
  type Promisable<T> = T | Promise<T>;
138
8
  /**
139
9
  * hooks on rename temp asar path to `${app.name}.asar`
@@ -205,4 +75,4 @@ declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>):
205
75
  */
206
76
  declare function initApp(appOptions: AppOption): Promise<void>;
207
77
 
208
- export { type AppOption, type CheckResult, type DownloadResult, ErrorInfo, type Logger, Updater, UpdaterError, type UpdaterOption, initApp, startupWithUpdater };
78
+ export { type AppOption, Logger, Updater, UpdaterOption, initApp, startupWithUpdater };