electron-incremental-update 0.8.0 → 0.8.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/index.d.mts CHANGED
@@ -190,6 +190,7 @@ interface UpdaterOption {
190
190
  downloadConfig?: UpdaterDownloadConfig;
191
191
  }
192
192
 
193
+ type Promisable<T> = T | Promise<T>;
193
194
  type AppOption = {
194
195
  /**
195
196
  * path of electron output dist when in development
@@ -204,12 +205,15 @@ type AppOption = {
204
205
  hooks?: {
205
206
  /**
206
207
  * hooks before replace the old asar is replaced by the new asar
208
+ *
209
+ * @param oldAsarPath old asar path
210
+ * @param updateTempAsarPath new asar path, end with .tmp
207
211
  */
208
- beforeDoUpdate?: (updateTempAsarPath: string) => void | Promise<void>;
212
+ beforeDoUpdate?: (oldAsarPath: string, updateTempAsarPath: string) => Promisable<void>;
209
213
  /**
210
- * hooks on start up
214
+ * hooks before start up
211
215
  */
212
- onStart?: (productAsarPath: string) => void;
216
+ beforeStart?: (productAsarPath: string) => Promisable<void>;
213
217
  /**
214
218
  * hooks on start up error
215
219
  */
@@ -221,7 +225,7 @@ type SetUpdater = {
221
225
  /**
222
226
  * set updater option or create function
223
227
  */
224
- setUpdater: (updater: (() => Updater | Promise<Updater>) | UpdaterOption) => void;
228
+ setUpdater: (updater: (() => Promisable<Updater>) | UpdaterOption) => void;
225
229
  };
226
230
  /**
227
231
  * initialize app
package/dist/index.d.ts CHANGED
@@ -190,6 +190,7 @@ interface UpdaterOption {
190
190
  downloadConfig?: UpdaterDownloadConfig;
191
191
  }
192
192
 
193
+ type Promisable<T> = T | Promise<T>;
193
194
  type AppOption = {
194
195
  /**
195
196
  * path of electron output dist when in development
@@ -204,12 +205,15 @@ type AppOption = {
204
205
  hooks?: {
205
206
  /**
206
207
  * hooks before replace the old asar is replaced by the new asar
208
+ *
209
+ * @param oldAsarPath old asar path
210
+ * @param updateTempAsarPath new asar path, end with .tmp
207
211
  */
208
- beforeDoUpdate?: (updateTempAsarPath: string) => void | Promise<void>;
212
+ beforeDoUpdate?: (oldAsarPath: string, updateTempAsarPath: string) => Promisable<void>;
209
213
  /**
210
- * hooks on start up
214
+ * hooks before start up
211
215
  */
212
- onStart?: (productAsarPath: string) => void;
216
+ beforeStart?: (productAsarPath: string) => Promisable<void>;
213
217
  /**
214
218
  * hooks on start up error
215
219
  */
@@ -221,7 +225,7 @@ type SetUpdater = {
221
225
  /**
222
226
  * set updater option or create function
223
227
  */
224
- setUpdater: (updater: (() => Updater | Promise<Updater>) | UpdaterOption) => void;
228
+ setUpdater: (updater: (() => Promisable<Updater>) | UpdaterOption) => void;
225
229
  };
226
230
  /**
227
231
  * initialize app
package/dist/index.js CHANGED
@@ -405,7 +405,7 @@ function initApp(appOptions) {
405
405
  } = appOptions || {};
406
406
  const {
407
407
  beforeDoUpdate,
408
- onStart,
408
+ beforeStart,
409
409
  onStartError
410
410
  } = hooks || {};
411
411
  function handleError(msg) {
@@ -415,13 +415,14 @@ function initApp(appOptions) {
415
415
  async function startup(updater) {
416
416
  try {
417
417
  const asarPath = getProductAsarPath(updater.productName);
418
- if ((0, import_node_fs3.existsSync)(`${asarPath}.tmp`)) {
419
- await beforeDoUpdate?.(asarPath);
420
- (0, import_node_fs3.renameSync)(`${asarPath}.tmp`, asarPath);
418
+ const updateAsarPath = `${asarPath}.tmp`;
419
+ if ((0, import_node_fs3.existsSync)(updateAsarPath)) {
420
+ await beforeDoUpdate?.(asarPath, updateAsarPath);
421
+ (0, import_node_fs3.renameSync)(updateAsarPath, asarPath);
421
422
  }
422
423
  const mainDir = import_electron3.app.isPackaged ? asarPath : electronDevDistPath;
423
424
  const entry = (0, import_node_path2.resolve)(__dirname, mainDir, mainPath);
424
- onStart?.(entry);
425
+ await beforeStart?.(entry);
425
426
  require(entry)(updater);
426
427
  } catch (error) {
427
428
  handleError(`failed to start app, ${error}`);
package/dist/index.mjs CHANGED
@@ -299,7 +299,7 @@ function initApp(appOptions) {
299
299
  } = appOptions || {};
300
300
  const {
301
301
  beforeDoUpdate,
302
- onStart,
302
+ beforeStart,
303
303
  onStartError
304
304
  } = hooks || {};
305
305
  function handleError(msg) {
@@ -309,13 +309,14 @@ function initApp(appOptions) {
309
309
  async function startup(updater) {
310
310
  try {
311
311
  const asarPath = getProductAsarPath(updater.productName);
312
- if (existsSync2(`${asarPath}.tmp`)) {
313
- await beforeDoUpdate?.(asarPath);
314
- renameSync(`${asarPath}.tmp`, asarPath);
312
+ const updateAsarPath = `${asarPath}.tmp`;
313
+ if (existsSync2(updateAsarPath)) {
314
+ await beforeDoUpdate?.(asarPath, updateAsarPath);
315
+ renameSync(updateAsarPath, asarPath);
315
316
  }
316
317
  const mainDir = app.isPackaged ? asarPath : electronDevDistPath;
317
318
  const entry = resolve(__dirname, mainDir, mainPath);
318
- onStart?.(entry);
319
+ await beforeStart?.(entry);
319
320
  __require(entry)(updater);
320
321
  } catch (error) {
321
322
  handleError(`failed to start app, ${error}`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
3
  "author": "subframe7536",
4
- "version": "0.8.0",
4
+ "version": "0.8.1",
5
5
  "description": "electron incremental update tools, powered by vite",
6
6
  "scripts": {
7
7
  "build": "tsup && node fix-module.js",