electron-incremental-update 0.7.10 → 0.8.0

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/index.d.mts CHANGED
@@ -12,7 +12,7 @@ declare class VerifyFailedError extends Error {
12
12
  constructor(signature: string, cert: string);
13
13
  }
14
14
  declare class DownloadError extends Error {
15
- constructor();
15
+ constructor(msg: string);
16
16
  }
17
17
  declare class IncrementalUpdater implements Updater {
18
18
  private info?;
@@ -111,7 +111,7 @@ type UpdaterOverrideFunctions = {
111
111
  * @param cert certificate
112
112
  * @returns if signature is valid, returns the version or `true` , otherwise returns `false`
113
113
  */
114
- verifySignaure?: (buffer: Buffer, signature: string, cert: string) => string | boolean | Promise<string | boolean>;
114
+ verifySignaure?: (buffer: Buffer, signature: string, cert: string) => string | false | Promise<string | false>;
115
115
  /**
116
116
  * custom download JSON function
117
117
  * @param url download url
@@ -201,14 +201,20 @@ type AppOption = {
201
201
  * @default 'main/index.js'
202
202
  */
203
203
  mainPath?: string;
204
- /**
205
- * hooks for start up
206
- */
207
- onStart?: (productAsarPath: string) => void;
208
- /**
209
- * hooks for start up error
210
- */
211
- onStartError?: (err: unknown) => void;
204
+ hooks?: {
205
+ /**
206
+ * hooks before replace the old asar is replaced by the new asar
207
+ */
208
+ beforeDoUpdate?: (updateTempAsarPath: string) => void | Promise<void>;
209
+ /**
210
+ * hooks on start up
211
+ */
212
+ onStart?: (productAsarPath: string) => void;
213
+ /**
214
+ * hooks on start up error
215
+ */
216
+ onStartError?: (err: unknown) => void;
217
+ };
212
218
  };
213
219
  type StartupWithUpdater = (updater: Updater) => void;
214
220
  type SetUpdater = {
@@ -218,14 +224,13 @@ type SetUpdater = {
218
224
  setUpdater: (updater: (() => Updater | Promise<Updater>) | UpdaterOption) => void;
219
225
  };
220
226
  /**
221
- * create updater manually
227
+ * initialize app
222
228
  * @example
223
229
  * ```ts
224
230
  * import { getGithubReleaseCdnGroup, initApp, parseGithubCdnURL } from 'electron-incremental-update'
225
231
  * import { name, repository } from '../package.json'
226
232
  *
227
233
  * const SIGNATURE_CERT = '' // auto generate certificate when start app
228
- *
229
234
  * const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
230
235
  * const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
231
236
  * initApp({ onStart: console.log })
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ declare class VerifyFailedError extends Error {
12
12
  constructor(signature: string, cert: string);
13
13
  }
14
14
  declare class DownloadError extends Error {
15
- constructor();
15
+ constructor(msg: string);
16
16
  }
17
17
  declare class IncrementalUpdater implements Updater {
18
18
  private info?;
@@ -111,7 +111,7 @@ type UpdaterOverrideFunctions = {
111
111
  * @param cert certificate
112
112
  * @returns if signature is valid, returns the version or `true` , otherwise returns `false`
113
113
  */
114
- verifySignaure?: (buffer: Buffer, signature: string, cert: string) => string | boolean | Promise<string | boolean>;
114
+ verifySignaure?: (buffer: Buffer, signature: string, cert: string) => string | false | Promise<string | false>;
115
115
  /**
116
116
  * custom download JSON function
117
117
  * @param url download url
@@ -201,14 +201,20 @@ type AppOption = {
201
201
  * @default 'main/index.js'
202
202
  */
203
203
  mainPath?: string;
204
- /**
205
- * hooks for start up
206
- */
207
- onStart?: (productAsarPath: string) => void;
208
- /**
209
- * hooks for start up error
210
- */
211
- onStartError?: (err: unknown) => void;
204
+ hooks?: {
205
+ /**
206
+ * hooks before replace the old asar is replaced by the new asar
207
+ */
208
+ beforeDoUpdate?: (updateTempAsarPath: string) => void | Promise<void>;
209
+ /**
210
+ * hooks on start up
211
+ */
212
+ onStart?: (productAsarPath: string) => void;
213
+ /**
214
+ * hooks on start up error
215
+ */
216
+ onStartError?: (err: unknown) => void;
217
+ };
212
218
  };
213
219
  type StartupWithUpdater = (updater: Updater) => void;
214
220
  type SetUpdater = {
@@ -218,14 +224,13 @@ type SetUpdater = {
218
224
  setUpdater: (updater: (() => Updater | Promise<Updater>) | UpdaterOption) => void;
219
225
  };
220
226
  /**
221
- * create updater manually
227
+ * initialize app
222
228
  * @example
223
229
  * ```ts
224
230
  * import { getGithubReleaseCdnGroup, initApp, parseGithubCdnURL } from 'electron-incremental-update'
225
231
  * import { name, repository } from '../package.json'
226
232
  *
227
233
  * const SIGNATURE_CERT = '' // auto generate certificate when start app
228
- *
229
234
  * const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
230
235
  * const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
231
236
  * initApp({ onStart: console.log })
package/dist/index.js CHANGED
@@ -241,8 +241,8 @@ var VerifyFailedError = class extends Error {
241
241
  }
242
242
  };
243
243
  var DownloadError = class extends Error {
244
- constructor() {
245
- super("download update error");
244
+ constructor(msg) {
245
+ super(`download update error, ${msg}`);
246
246
  }
247
247
  };
248
248
  var IncrementalUpdater = class {
@@ -334,7 +334,7 @@ var IncrementalUpdater = class {
334
334
  this.logger?.info(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
335
335
  return ret;
336
336
  } catch (e) {
337
- throw new DownloadError();
337
+ throw new DownloadError(e.toString());
338
338
  }
339
339
  }
340
340
  async checkUpdate(data) {
@@ -383,7 +383,7 @@ var IncrementalUpdater = class {
383
383
  await (0, import_promises.writeFile)(this.gzipPath, buffer);
384
384
  this.logger?.info(`extract to ${this.tmpFilePath}`);
385
385
  await unzipFile(this.gzipPath, this.tmpFilePath);
386
- this.logger?.info(`download success${typeof _ver === "string" ? `, version: ${_ver}` : ""}`);
386
+ this.logger?.info(`download success, version: ${_ver}`);
387
387
  this.info = void 0;
388
388
  return true;
389
389
  } catch (error) {
@@ -401,17 +401,22 @@ function initApp(appOptions) {
401
401
  const {
402
402
  electronDevDistPath = "dist-electron",
403
403
  mainPath = "main/index.js",
404
+ hooks
405
+ } = appOptions || {};
406
+ const {
407
+ beforeDoUpdate,
404
408
  onStart,
405
409
  onStartError
406
- } = appOptions || {};
410
+ } = hooks || {};
407
411
  function handleError(msg) {
408
412
  onStartError?.(new Error(msg));
409
413
  import_electron3.app.quit();
410
414
  }
411
- function startup(updater) {
415
+ async function startup(updater) {
412
416
  try {
413
417
  const asarPath = getProductAsarPath(updater.productName);
414
418
  if ((0, import_node_fs3.existsSync)(`${asarPath}.tmp`)) {
419
+ await beforeDoUpdate?.(asarPath);
415
420
  (0, import_node_fs3.renameSync)(`${asarPath}.tmp`, asarPath);
416
421
  }
417
422
  const mainDir = import_electron3.app.isPackaged ? asarPath : electronDevDistPath;
@@ -429,9 +434,9 @@ function initApp(appOptions) {
429
434
  async setUpdater(updater) {
430
435
  clearTimeout(timer);
431
436
  if (typeof updater === "object") {
432
- startup(createUpdater(updater));
437
+ await startup(createUpdater(updater));
433
438
  } else if (typeof updater === "function") {
434
- startup(await updater());
439
+ await startup(await updater());
435
440
  } else {
436
441
  handleError("invalid updater option or updater is not a function");
437
442
  }
package/dist/index.mjs CHANGED
@@ -135,8 +135,8 @@ var VerifyFailedError = class extends Error {
135
135
  }
136
136
  };
137
137
  var DownloadError = class extends Error {
138
- constructor() {
139
- super("download update error");
138
+ constructor(msg) {
139
+ super(`download update error, ${msg}`);
140
140
  }
141
141
  };
142
142
  var IncrementalUpdater = class {
@@ -228,7 +228,7 @@ var IncrementalUpdater = class {
228
228
  this.logger?.info(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
229
229
  return ret;
230
230
  } catch (e) {
231
- throw new DownloadError();
231
+ throw new DownloadError(e.toString());
232
232
  }
233
233
  }
234
234
  async checkUpdate(data) {
@@ -277,7 +277,7 @@ var IncrementalUpdater = class {
277
277
  await writeFile(this.gzipPath, buffer);
278
278
  this.logger?.info(`extract to ${this.tmpFilePath}`);
279
279
  await unzipFile(this.gzipPath, this.tmpFilePath);
280
- this.logger?.info(`download success${typeof _ver === "string" ? `, version: ${_ver}` : ""}`);
280
+ this.logger?.info(`download success, version: ${_ver}`);
281
281
  this.info = void 0;
282
282
  return true;
283
283
  } catch (error) {
@@ -295,17 +295,22 @@ function initApp(appOptions) {
295
295
  const {
296
296
  electronDevDistPath = "dist-electron",
297
297
  mainPath = "main/index.js",
298
+ hooks
299
+ } = appOptions || {};
300
+ const {
301
+ beforeDoUpdate,
298
302
  onStart,
299
303
  onStartError
300
- } = appOptions || {};
304
+ } = hooks || {};
301
305
  function handleError(msg) {
302
306
  onStartError?.(new Error(msg));
303
307
  app.quit();
304
308
  }
305
- function startup(updater) {
309
+ async function startup(updater) {
306
310
  try {
307
311
  const asarPath = getProductAsarPath(updater.productName);
308
312
  if (existsSync2(`${asarPath}.tmp`)) {
313
+ await beforeDoUpdate?.(asarPath);
309
314
  renameSync(`${asarPath}.tmp`, asarPath);
310
315
  }
311
316
  const mainDir = app.isPackaged ? asarPath : electronDevDistPath;
@@ -323,9 +328,9 @@ function initApp(appOptions) {
323
328
  async setUpdater(updater) {
324
329
  clearTimeout(timer);
325
330
  if (typeof updater === "object") {
326
- startup(createUpdater(updater));
331
+ await startup(createUpdater(updater));
327
332
  } else if (typeof updater === "function") {
328
- startup(await updater());
333
+ await startup(await updater());
329
334
  } else {
330
335
  handleError("invalid updater option or updater is not a function");
331
336
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
3
  "author": "subframe7536",
4
- "version": "0.7.10",
4
+ "version": "0.8.0",
5
5
  "description": "electron incremental update tools, powered by vite",
6
6
  "scripts": {
7
7
  "build": "tsup && node fix-module.js",