electron-incremental-update 2.1.1 → 2.1.2

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 CHANGED
@@ -245,7 +245,7 @@ Luckily, `Esbuild` can bundle all the dependencies. Just follow the steps:
245
245
  1. setup `nativeModuleEntryMap` option
246
246
  2. Manually copy the native binaries in `postBuild` callback
247
247
  3. Exclude all the dependencies in `electron-builder`'s config
248
- 4. call the native functions with `requireNative` in your code
248
+ 4. call the native functions with `requireNative` / `importNative` in your code
249
249
 
250
250
  #### Example
251
251
 
@@ -283,8 +283,9 @@ in `electron/native/db.ts`
283
283
 
284
284
  ```ts
285
285
  import Database from 'better-sqlite3'
286
+ import { getPathFromEntryAsar } from 'electron-incremental-update/utils'
286
287
 
287
- const db = new Database(':memory:', { nativeBinding: './better_sqlite3.node' })
288
+ const db = new Database(':memory:', { nativeBinding: getPathFromEntryAsar('./better_sqlite3.node') })
288
289
 
289
290
  export function test(): void {
290
291
  db.exec(
@@ -308,9 +309,13 @@ export function test(): void {
308
309
  in `electron/main/service.ts`
309
310
 
310
311
  ```ts
311
- import { requireNative } from 'electron-incremental-update/utils'
312
+ import { importNative, requireNative } from 'electron-incremental-update/utils'
312
313
 
314
+ // commonjs
313
315
  requireNative<typeof import('../native/db')>('db').test()
316
+
317
+ // esm
318
+ importNative<typeof import('../native/db')>('db').test()
314
319
  ```
315
320
 
316
321
  in `electron-builder.config.js`
@@ -349,6 +354,124 @@ https://electron-vite.org/guide/source-code-protection
349
354
  - Only support commonjs
350
355
  - Only for main process by default, if you want to use in preload script, please use `electronWithUpdater({ bytecode: { enablePreload: true } })` and set `sandbox: false` when creating window
351
356
 
357
+ ### Utils
358
+
359
+ ```ts
360
+ /**
361
+ * Compile time dev check
362
+ */
363
+ const isDev: boolean
364
+ const isWin: boolean
365
+ const isMac: boolean
366
+ const isLinux: boolean
367
+ /**
368
+ * Get joined path of `${electron.app.name}.asar` (not `app.asar`)
369
+ *
370
+ * If is in dev, **always** return `'DEV.asar'`
371
+ */
372
+ function getPathFromAppNameAsar(...paths: string[]): string
373
+ /**
374
+ * Get app version, if is in dev, return `getEntryVersion()`
375
+ */
376
+ function getAppVersion(): string
377
+ /**
378
+ * Get entry version
379
+ */
380
+ function getEntryVersion(): string
381
+ /**
382
+ * Use `require` to load native module from entry asar
383
+ * @param moduleName file name in entry
384
+ * @example
385
+ * requireNative<typeof import('../native/db')>('db')
386
+ */
387
+ function requireNative<T = any>(moduleName: string): T
388
+ /**
389
+ * Use `import` to load native module from entry asar
390
+ * @param moduleName file name in entry
391
+ * @example
392
+ * await importNative<typeof import('../native/db')>('db')
393
+ */
394
+ function importNative<T = any>(moduleName: string): Promise<T>
395
+ /**
396
+ * Restarts the Electron app.
397
+ */
398
+ function restartApp(): void
399
+ /**
400
+ * Fix app use model id, only for Windows
401
+ * @param id app id, default is `org.${electron.app.name}`
402
+ */
403
+ function setAppUserModelId(id?: string): void
404
+ /**
405
+ * Disable hardware acceleration for Windows 7
406
+ *
407
+ * Only support CommonJS
408
+ */
409
+ function disableHWAccForWin7(): void
410
+ /**
411
+ * Keep single electron instance and auto restore window on `second-instance` event
412
+ * @param window brwoser window to show
413
+ */
414
+ function singleInstance(window?: BrowserWindow): void
415
+ /**
416
+ * Set `AppData` dir to the dir of .exe file
417
+ *
418
+ * Useful for portable Windows app
419
+ * @param dirName dir name, default to `data`
420
+ */
421
+ function setPortableAppDataPath(dirName?: string): void
422
+ /**
423
+ * Load `process.env.VITE_DEV_SERVER_URL` when dev, else load html file
424
+ * @param win window
425
+ * @param htmlFilePath html file path, default is `index.html`
426
+ */
427
+ function loadPage(win: BrowserWindow, htmlFilePath?: string): void
428
+ interface BeautifyDevToolsOptions {
429
+ /**
430
+ * Sans-serif font family
431
+ */
432
+ sans: string
433
+ /**
434
+ * Monospace font family
435
+ */
436
+ mono: string
437
+ /**
438
+ * Whether to round scrollbar
439
+ */
440
+ scrollbar?: boolean
441
+ }
442
+ /**
443
+ * Beautify devtools' font and scrollbar
444
+ * @param win target window
445
+ * @param options sans font family, mono font family and scrollbar
446
+ */
447
+ function beautifyDevTools(win: BrowserWindow, options: BeautifyDevToolsOptions): void
448
+ /**
449
+ * Get joined path from main dir
450
+ * @param paths rest paths
451
+ */
452
+ function getPathFromMain(...paths: string[]): string
453
+ /**
454
+ * Get joined path from preload dir
455
+ * @param paths rest paths
456
+ */
457
+ function getPathFromPreload(...paths: string[]): string
458
+ /**
459
+ * Get joined path from publich dir
460
+ * @param paths rest paths
461
+ */
462
+ function getPathFromPublic(...paths: string[]): string
463
+ /**
464
+ * Get joined path from entry asar
465
+ * @param paths rest paths
466
+ */
467
+ function getPathFromEntryAsar(...paths: string[]): string
468
+ /**
469
+ * Handle all unhandled error
470
+ * @param callback callback function
471
+ */
472
+ function handleUnexpectedErrors(callback: (err: unknown) => void): void
473
+ ```
474
+
352
475
  ### Types
353
476
 
354
477
  #### Entry
@@ -45,21 +45,15 @@ function disableHWAccForWin7() {
45
45
  }
46
46
  }
47
47
  function singleInstance(window) {
48
- const result = electron.app.requestSingleInstanceLock();
49
- if (result) {
50
- electron.app.on("second-instance", () => {
51
- if (window) {
52
- window.show();
53
- if (window.isMinimized()) {
54
- window.restore();
55
- }
56
- window.focus();
48
+ electron.app.on("second-instance", () => {
49
+ if (window) {
50
+ window.show();
51
+ if (window.isMinimized()) {
52
+ window.restore();
57
53
  }
58
- });
59
- } else {
60
- electron.app.quit();
61
- }
62
- return result;
54
+ window.focus();
55
+ }
56
+ });
63
57
  }
64
58
  function setPortableAppDataPath(dirName = "data") {
65
59
  const portablePath = path.join(path.dirname(electron.app.getPath("exe")), dirName);
@@ -4,24 +4,12 @@ import crypto from 'node:crypto';
4
4
  // src/utils/zip.ts
5
5
  async function defaultZipFile(buffer) {
6
6
  return new Promise((resolve, reject) => {
7
- zlib.brotliCompress(buffer, (err, buffer2) => {
8
- if (err) {
9
- reject(err);
10
- } else {
11
- resolve(buffer2);
12
- }
13
- });
7
+ zlib.brotliCompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
14
8
  });
15
9
  }
16
10
  async function defaultUnzipFile(buffer) {
17
11
  return new Promise((resolve, reject) => {
18
- zlib.brotliDecompress(buffer, (err, buffer2) => {
19
- if (err) {
20
- reject(err);
21
- } else {
22
- resolve(buffer2);
23
- }
24
- });
12
+ zlib.brotliDecompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
25
13
  });
26
14
  }
27
15
  function hashBuffer(data, length) {
package/dist/index.cjs CHANGED
@@ -242,12 +242,7 @@ async function createElectronApp(appOptions = {}) {
242
242
  beforeStart,
243
243
  onStartError
244
244
  } = appOptions;
245
- let updaterInstance;
246
- if (typeof updater === "object" || !updater) {
247
- updaterInstance = new Updater(updater);
248
- } else {
249
- updaterInstance = await updater();
250
- }
245
+ const updaterInstance = typeof updater === "object" || !updater ? new Updater(updater) : await updater();
251
246
  const logger = updaterInstance.logger;
252
247
  try {
253
248
  const tempAsarPath = `${appNameAsarPath}.tmp`;
package/dist/index.d.cts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
  import { U as UpdateJSON, a as UpdateInfo } from './version-DcFMG3pT.cjs';
3
- import { U as UpdateInfoWithExtraVersion, a as UnavailableCode, b as UpdaterError, D as DownloadingInfo, I as IProvider, L as Logger, c as UpdaterOption, d as UpdateJSONWithURL } from './types-DADYYy6C.cjs';
4
- export { E as ErrorCode, e as UpdateInfoWithURL } from './types-DADYYy6C.cjs';
3
+ import { U as UpdateInfoWithExtraVersion, a as UpdaterUnavailableCode, b as UpdaterError, D as DownloadingInfo, I as IProvider, L as Logger, c as UpdaterOption, d as UpdateJSONWithURL } from './types-BPH66pNz.cjs';
4
+ export { f as UpdateInfoWithURL, e as UpdaterErrorCode } from './types-BPH66pNz.cjs';
5
5
  import { Promisable } from '@subframe7536/type-utils';
6
6
 
7
7
  declare class Updater extends EventEmitter<{
8
8
  'checking': any;
9
9
  'update-available': [data: UpdateInfoWithExtraVersion];
10
- 'update-not-available': [code: UnavailableCode, msg: string, info?: UpdateInfoWithExtraVersion];
10
+ 'update-not-available': [code: UpdaterUnavailableCode, msg: string, info?: UpdateInfoWithExtraVersion];
11
11
  'error': [error: UpdaterError];
12
12
  'download-progress': [info: DownloadingInfo];
13
13
  'update-downloaded': any;
@@ -143,4 +143,4 @@ declare function createElectronApp(appOptions?: AppOption): Promise<void>;
143
143
  */
144
144
  declare const initApp: typeof createElectronApp;
145
145
 
146
- export { type AppOption, Logger, UnavailableCode, UpdateInfoWithExtraVersion, Updater, UpdaterError, UpdaterOption, autoUpdate, createElectronApp, initApp, startupWithUpdater };
146
+ export { type AppOption, Logger, UpdateInfoWithExtraVersion, Updater, UpdaterError, UpdaterOption, UpdaterUnavailableCode, autoUpdate, createElectronApp, initApp, startupWithUpdater };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
  import { U as UpdateJSON, a as UpdateInfo } from './version-DcFMG3pT.js';
3
- import { U as UpdateInfoWithExtraVersion, a as UnavailableCode, b as UpdaterError, D as DownloadingInfo, I as IProvider, L as Logger, c as UpdaterOption, d as UpdateJSONWithURL } from './types-BVcfNRXE.js';
4
- export { E as ErrorCode, e as UpdateInfoWithURL } from './types-BVcfNRXE.js';
3
+ import { U as UpdateInfoWithExtraVersion, a as UpdaterUnavailableCode, b as UpdaterError, D as DownloadingInfo, I as IProvider, L as Logger, c as UpdaterOption, d as UpdateJSONWithURL } from './types-DQKdsHc_.js';
4
+ export { f as UpdateInfoWithURL, e as UpdaterErrorCode } from './types-DQKdsHc_.js';
5
5
  import { Promisable } from '@subframe7536/type-utils';
6
6
 
7
7
  declare class Updater extends EventEmitter<{
8
8
  'checking': any;
9
9
  'update-available': [data: UpdateInfoWithExtraVersion];
10
- 'update-not-available': [code: UnavailableCode, msg: string, info?: UpdateInfoWithExtraVersion];
10
+ 'update-not-available': [code: UpdaterUnavailableCode, msg: string, info?: UpdateInfoWithExtraVersion];
11
11
  'error': [error: UpdaterError];
12
12
  'download-progress': [info: DownloadingInfo];
13
13
  'update-downloaded': any;
@@ -143,4 +143,4 @@ declare function createElectronApp(appOptions?: AppOption): Promise<void>;
143
143
  */
144
144
  declare const initApp: typeof createElectronApp;
145
145
 
146
- export { type AppOption, Logger, UnavailableCode, UpdateInfoWithExtraVersion, Updater, UpdaterError, UpdaterOption, autoUpdate, createElectronApp, initApp, startupWithUpdater };
146
+ export { type AppOption, Logger, UpdateInfoWithExtraVersion, Updater, UpdaterError, UpdaterOption, UpdaterUnavailableCode, autoUpdate, createElectronApp, initApp, startupWithUpdater };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isDev, getAppVersion, getEntryVersion, getPathFromAppNameAsar, restartApp } from './chunk-ZM5CIZ4L.js';
1
+ import { isDev, getAppVersion, getEntryVersion, getPathFromAppNameAsar, restartApp } from './chunk-2XSFM3E5.js';
2
2
  import { isUpdateJSON, __require } from './chunk-RCRKUKFX.js';
3
3
  import fs2 from 'node:fs';
4
4
  import { EventEmitter } from 'node:events';
@@ -206,12 +206,7 @@ async function createElectronApp(appOptions = {}) {
206
206
  beforeStart,
207
207
  onStartError
208
208
  } = appOptions;
209
- let updaterInstance;
210
- if (typeof updater === "object" || !updater) {
211
- updaterInstance = new Updater(updater);
212
- } else {
213
- updaterInstance = await updater();
214
- }
209
+ const updaterInstance = typeof updater === "object" || !updater ? new Updater(updater) : await updater();
215
210
  const logger = updaterInstance.logger;
216
211
  try {
217
212
  const tempAsarPath = `${appNameAsarPath}.tmp`;
package/dist/provider.cjs CHANGED
@@ -175,13 +175,7 @@ function defaultVerifySignature(buffer, version, signature, cert) {
175
175
  }
176
176
  async function defaultUnzipFile(buffer) {
177
177
  return new Promise((resolve, reject) => {
178
- zlib__default.default.brotliDecompress(buffer, (err, buffer2) => {
179
- if (err) {
180
- reject(err);
181
- } else {
182
- resolve(buffer2);
183
- }
184
- });
178
+ zlib__default.default.brotliDecompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
185
179
  });
186
180
  }
187
181
 
@@ -1,4 +1,4 @@
1
- import { I as IProvider, d as UpdateJSONWithURL, e as UpdateInfoWithURL, D as DownloadingInfo, f as URLHandler, O as OnDownloading } from './types-DADYYy6C.cjs';
1
+ import { I as IProvider, d as UpdateJSONWithURL, f as UpdateInfoWithURL, D as DownloadingInfo, g as URLHandler, O as OnDownloading } from './types-BPH66pNz.cjs';
2
2
  import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-rm9ED9nU.cjs';
3
3
  import { d as defaultIsLowerVersion, U as UpdateJSON } from './version-DcFMG3pT.cjs';
4
4
  import { Arrayable } from '@subframe7536/type-utils';
@@ -1,4 +1,4 @@
1
- import { I as IProvider, d as UpdateJSONWithURL, e as UpdateInfoWithURL, D as DownloadingInfo, f as URLHandler, O as OnDownloading } from './types-BVcfNRXE.js';
1
+ import { I as IProvider, d as UpdateJSONWithURL, f as UpdateInfoWithURL, D as DownloadingInfo, g as URLHandler, O as OnDownloading } from './types-DQKdsHc_.js';
2
2
  import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-rm9ED9nU.js';
3
3
  import { d as defaultIsLowerVersion, U as UpdateJSON } from './version-DcFMG3pT.js';
4
4
  import { Arrayable } from '@subframe7536/type-utils';
package/dist/provider.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defaultVerifySignature, defaultUnzipFile } from './chunk-KZSYEXLO.js';
1
+ import { defaultVerifySignature, defaultUnzipFile } from './chunk-PUVBFHOK.js';
2
2
  import { isUpdateJSON, defaultIsLowerVersion } from './chunk-RCRKUKFX.js';
3
3
  import { URL } from 'node:url';
4
4
  import electron from 'electron';
@@ -1,11 +1,11 @@
1
1
  import { Promisable } from '@subframe7536/type-utils';
2
2
  import { a as UpdateInfo } from './version-DcFMG3pT.cjs';
3
3
 
4
- type ErrorCode = 'ERR_DOWNLOAD' | 'ERR_VALIDATE' | 'ERR_PARAM' | 'ERR_NETWORK';
5
- type UnavailableCode = 'UNAVAILABLE_ERROR' | 'UNAVAILABLE_DEV' | 'UNAVAILABLE_VERSION';
4
+ type UpdaterErrorCode = 'ERR_DOWNLOAD' | 'ERR_VALIDATE' | 'ERR_PARAM' | 'ERR_NETWORK';
5
+ type UpdaterUnavailableCode = 'UNAVAILABLE_ERROR' | 'UNAVAILABLE_DEV' | 'UNAVAILABLE_VERSION';
6
6
  declare class UpdaterError extends Error {
7
- code: ErrorCode;
8
- constructor(code: ErrorCode, info: string);
7
+ code: UpdaterErrorCode;
8
+ constructor(code: UpdaterErrorCode, info: string);
9
9
  }
10
10
  interface Logger {
11
11
  info: (msg: string) => void;
@@ -114,4 +114,4 @@ interface IProvider {
114
114
  }
115
115
  type URLHandler = (url: URL) => Promisable<URL | string | undefined | null>;
116
116
 
117
- export { type DownloadingInfo as D, type ErrorCode as E, type IProvider as I, type Logger as L, type OnDownloading as O, type UpdateInfoWithExtraVersion as U, type UnavailableCode as a, UpdaterError as b, type UpdaterOption as c, type UpdateJSONWithURL as d, type UpdateInfoWithURL as e, type URLHandler as f };
117
+ export { type DownloadingInfo as D, type IProvider as I, type Logger as L, type OnDownloading as O, type UpdateInfoWithExtraVersion as U, type UpdaterUnavailableCode as a, UpdaterError as b, type UpdaterOption as c, type UpdateJSONWithURL as d, type UpdaterErrorCode as e, type UpdateInfoWithURL as f, type URLHandler as g };
@@ -1,11 +1,11 @@
1
1
  import { Promisable } from '@subframe7536/type-utils';
2
2
  import { a as UpdateInfo } from './version-DcFMG3pT.js';
3
3
 
4
- type ErrorCode = 'ERR_DOWNLOAD' | 'ERR_VALIDATE' | 'ERR_PARAM' | 'ERR_NETWORK';
5
- type UnavailableCode = 'UNAVAILABLE_ERROR' | 'UNAVAILABLE_DEV' | 'UNAVAILABLE_VERSION';
4
+ type UpdaterErrorCode = 'ERR_DOWNLOAD' | 'ERR_VALIDATE' | 'ERR_PARAM' | 'ERR_NETWORK';
5
+ type UpdaterUnavailableCode = 'UNAVAILABLE_ERROR' | 'UNAVAILABLE_DEV' | 'UNAVAILABLE_VERSION';
6
6
  declare class UpdaterError extends Error {
7
- code: ErrorCode;
8
- constructor(code: ErrorCode, info: string);
7
+ code: UpdaterErrorCode;
8
+ constructor(code: UpdaterErrorCode, info: string);
9
9
  }
10
10
  interface Logger {
11
11
  info: (msg: string) => void;
@@ -114,4 +114,4 @@ interface IProvider {
114
114
  }
115
115
  type URLHandler = (url: URL) => Promisable<URL | string | undefined | null>;
116
116
 
117
- export { type DownloadingInfo as D, type ErrorCode as E, type IProvider as I, type Logger as L, type OnDownloading as O, type UpdateInfoWithExtraVersion as U, type UnavailableCode as a, UpdaterError as b, type UpdaterOption as c, type UpdateJSONWithURL as d, type UpdateInfoWithURL as e, type URLHandler as f };
117
+ export { type DownloadingInfo as D, type IProvider as I, type Logger as L, type OnDownloading as O, type UpdateInfoWithExtraVersion as U, type UpdaterUnavailableCode as a, UpdaterError as b, type UpdaterOption as c, type UpdateJSONWithURL as d, type UpdaterErrorCode as e, type UpdateInfoWithURL as f, type URLHandler as g };
package/dist/utils.cjs CHANGED
@@ -62,21 +62,15 @@ function disableHWAccForWin7() {
62
62
  }
63
63
  }
64
64
  function singleInstance(window) {
65
- const result = electron__default.default.app.requestSingleInstanceLock();
66
- if (result) {
67
- electron__default.default.app.on("second-instance", () => {
68
- if (window) {
69
- window.show();
70
- if (window.isMinimized()) {
71
- window.restore();
72
- }
73
- window.focus();
65
+ electron__default.default.app.on("second-instance", () => {
66
+ if (window) {
67
+ window.show();
68
+ if (window.isMinimized()) {
69
+ window.restore();
74
70
  }
75
- });
76
- } else {
77
- electron__default.default.app.quit();
78
- }
79
- return result;
71
+ window.focus();
72
+ }
73
+ });
80
74
  }
81
75
  function setPortableAppDataPath(dirName = "data") {
82
76
  const portablePath = path__default.default.join(path__default.default.dirname(electron__default.default.app.getPath("exe")), dirName);
@@ -121,24 +115,12 @@ function handleUnexpectedErrors(callback) {
121
115
  }
122
116
  async function defaultZipFile(buffer) {
123
117
  return new Promise((resolve, reject) => {
124
- zlib__default.default.brotliCompress(buffer, (err, buffer2) => {
125
- if (err) {
126
- reject(err);
127
- } else {
128
- resolve(buffer2);
129
- }
130
- });
118
+ zlib__default.default.brotliCompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
131
119
  });
132
120
  }
133
121
  async function defaultUnzipFile(buffer) {
134
122
  return new Promise((resolve, reject) => {
135
- zlib__default.default.brotliDecompress(buffer, (err, buffer2) => {
136
- if (err) {
137
- reject(err);
138
- } else {
139
- resolve(buffer2);
140
- }
141
- });
123
+ zlib__default.default.brotliDecompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
142
124
  });
143
125
  }
144
126
 
package/dist/utils.d.cts CHANGED
@@ -55,9 +55,8 @@ declare function disableHWAccForWin7(): void;
55
55
  /**
56
56
  * Keep single electron instance and auto restore window on `second-instance` event
57
57
  * @param window brwoser window to show
58
- * @returns `false` if the app is running
59
58
  */
60
- declare function singleInstance(window?: BrowserWindow): boolean;
59
+ declare function singleInstance(window?: BrowserWindow): void;
61
60
  /**
62
61
  * Set `AppData` dir to the dir of .exe file
63
62
  *
@@ -71,13 +70,28 @@ declare function setPortableAppDataPath(dirName?: string): void;
71
70
  * @param htmlFilePath html file path, default is `index.html`
72
71
  */
73
72
  declare function loadPage(win: BrowserWindow, htmlFilePath?: string): void;
74
- declare function beautifyDevTools(win: BrowserWindow, options: {
73
+ interface BeautifyDevToolsOptions {
74
+ /**
75
+ * Sans-serif font family
76
+ */
75
77
  sans: string;
78
+ /**
79
+ * Monospace font family
80
+ */
76
81
  mono: string;
82
+ /**
83
+ * Whether to round scrollbar
84
+ */
77
85
  scrollbar?: boolean;
78
- }): void;
86
+ }
79
87
  /**
80
- * Get joined path from preload dir
88
+ * Beautify devtools' font and scrollbar
89
+ * @param win target window
90
+ * @param options sans font family, mono font family and scrollbar
91
+ */
92
+ declare function beautifyDevTools(win: BrowserWindow, options: BeautifyDevToolsOptions): void;
93
+ /**
94
+ * Get joined path from main dir
81
95
  * @param paths rest paths
82
96
  */
83
97
  declare function getPathFromMain(...paths: string[]): string;
package/dist/utils.d.ts CHANGED
@@ -55,9 +55,8 @@ declare function disableHWAccForWin7(): void;
55
55
  /**
56
56
  * Keep single electron instance and auto restore window on `second-instance` event
57
57
  * @param window brwoser window to show
58
- * @returns `false` if the app is running
59
58
  */
60
- declare function singleInstance(window?: BrowserWindow): boolean;
59
+ declare function singleInstance(window?: BrowserWindow): void;
61
60
  /**
62
61
  * Set `AppData` dir to the dir of .exe file
63
62
  *
@@ -71,13 +70,28 @@ declare function setPortableAppDataPath(dirName?: string): void;
71
70
  * @param htmlFilePath html file path, default is `index.html`
72
71
  */
73
72
  declare function loadPage(win: BrowserWindow, htmlFilePath?: string): void;
74
- declare function beautifyDevTools(win: BrowserWindow, options: {
73
+ interface BeautifyDevToolsOptions {
74
+ /**
75
+ * Sans-serif font family
76
+ */
75
77
  sans: string;
78
+ /**
79
+ * Monospace font family
80
+ */
76
81
  mono: string;
82
+ /**
83
+ * Whether to round scrollbar
84
+ */
77
85
  scrollbar?: boolean;
78
- }): void;
86
+ }
79
87
  /**
80
- * Get joined path from preload dir
88
+ * Beautify devtools' font and scrollbar
89
+ * @param win target window
90
+ * @param options sans font family, mono font family and scrollbar
91
+ */
92
+ declare function beautifyDevTools(win: BrowserWindow, options: BeautifyDevToolsOptions): void;
93
+ /**
94
+ * Get joined path from main dir
81
95
  * @param paths rest paths
82
96
  */
83
97
  declare function getPathFromMain(...paths: string[]): string;
package/dist/utils.js CHANGED
@@ -1,3 +1,3 @@
1
- export { beautifyDevTools, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, importNative, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance } from './chunk-ZM5CIZ4L.js';
2
- export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultZipFile, hashBuffer } from './chunk-KZSYEXLO.js';
1
+ export { beautifyDevTools, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, importNative, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance } from './chunk-2XSFM3E5.js';
2
+ export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultZipFile, hashBuffer } from './chunk-PUVBFHOK.js';
3
3
  export { defaultIsLowerVersion, defaultVersionJsonGenerator, isUpdateJSON, parseVersion } from './chunk-RCRKUKFX.js';
package/dist/vite.d.ts CHANGED
@@ -367,6 +367,40 @@ interface ElectronWithUpdaterOptions {
367
367
  * You can override all the vite configs, except output directories (use `options.updater.paths.electronDistPath` instead)
368
368
  *
369
369
  * @example
370
+ * ```ts
371
+ * import { defineConfig } from 'vite'
372
+ * import { debugStartup, electronWithUpdater } from 'electron-incremental-update/vite'
373
+ *
374
+ * export default defineConfig(async ({ command }) => {
375
+ * const isBuild = command === 'build'
376
+ * return {
377
+ * plugins: [
378
+ * electronWithUpdater({
379
+ * isBuild,
380
+ * logParsedOptions: true,
381
+ * main: {
382
+ * files: ['./electron/main/index.ts', './electron/main/worker.ts'],
383
+ * // see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
384
+ * onstart: debugStartup,
385
+ * },
386
+ * preload: {
387
+ * files: './electron/preload/index.ts',
388
+ * },
389
+ * updater: {
390
+ * // options
391
+ * }
392
+ * }),
393
+ * ],
394
+ * server: process.env.VSCODE_DEBUG && (() => {
395
+ * const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
396
+ * return {
397
+ * host: url.hostname,
398
+ * port: +url.port,
399
+ * }
400
+ * })(),
401
+ * }
402
+ * })
403
+ * ```
370
404
  */
371
405
  declare function electronWithUpdater(options: ElectronWithUpdaterOptions): Promise<PluginOption[] | undefined>;
372
406
 
package/dist/vite.js CHANGED
@@ -159,13 +159,7 @@ async function buildEntry({
159
159
  }
160
160
  async function defaultZipFile(buffer) {
161
161
  return new Promise((resolve, reject) => {
162
- zlib.brotliCompress(buffer, (err, buffer2) => {
163
- if (err) {
164
- reject(err);
165
- } else {
166
- resolve(buffer2);
167
- }
168
- });
162
+ zlib.brotliCompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
169
163
  });
170
164
  }
171
165
  function hashBuffer(data, length) {
@@ -305,7 +299,7 @@ function debugStartup(args) {
305
299
  args.startup();
306
300
  }
307
301
  }
308
- function getMainFilePath(options) {
302
+ function getMainFileBaseName(options) {
309
303
  let mainFilePath;
310
304
  if (typeof options === "string") {
311
305
  mainFilePath = path3.basename(options);
@@ -314,7 +308,7 @@ function getMainFilePath(options) {
314
308
  } else {
315
309
  const name = options?.index ?? options?.main;
316
310
  if (!name) {
317
- throw new Error(`\`options.main.files\` (${options}) must have "index" or "main" key, like \`{ index: "..." }\``);
311
+ throw new Error(`\`options.main.files\` (${options}) must have "index" or "main" key, like \`{ index: "./electron/main/index.ts" }\``);
318
312
  }
319
313
  mainFilePath = options?.index ? "index.js" : "main.js";
320
314
  }
@@ -380,7 +374,7 @@ async function electronWithUpdater(options) {
380
374
  __EIU_IS_DEV__: JSON.stringify(!isBuild),
381
375
  __EIU_IS_ESM__: JSON.stringify(isESM),
382
376
  __EIU_MAIN_DEV_DIR__: JSON.stringify(normalizePath(buildAsarOption.electronDistPath)),
383
- __EIU_MAIN_FILE__: JSON.stringify(getMainFilePath(_main.files)),
377
+ __EIU_MAIN_FILE__: JSON.stringify(getMainFileBaseName(_main.files)),
384
378
  __EIU_SIGNATURE_CERT__: JSON.stringify(cert),
385
379
  __EIU_VERSION_PATH__: JSON.stringify(parseVersionPath(normalizePath(buildVersionOption.versionPath)))
386
380
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
3
  "type": "module",
4
- "version": "2.1.1",
4
+ "version": "2.1.2",
5
5
  "description": "Electron incremental update tools with Vite plugin, support bytecode protection",
6
6
  "author": "subframe7536",
7
7
  "license": "MIT",