electron-incremental-update 0.7.7 → 0.7.9

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
@@ -60,16 +60,17 @@ import { name, repository } from '../package.json'
60
60
 
61
61
  const SIGNATURE_CERT = '' // auto generate certificate when start app
62
62
 
63
- const { cdnPrefix } = getGithubReleaseCdnGroup()[0]
63
+ const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
64
+ const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
64
65
  initApp({ onStart: console.log })
65
66
  // can be updater option or function that return updater
66
67
  .setUpdater({
67
68
  SIGNATURE_CERT,
68
69
  productName: name,
69
70
  repository,
70
- updateJsonURL: parseGithubCdnURL(repository, 'fastly.jsdelivr.net/gh', 'version.json'),
71
- releaseAsarURL: parseGithubCdnURL(repository, cdnPrefix, `download/latest/${name}.asar.gz`),
72
- debug: true,
71
+ updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
72
+ releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${name}.asar.gz`),
73
+ receiveBeta: true
73
74
  })
74
75
  ```
75
76
 
@@ -94,18 +95,16 @@ const startup: StartupWithUpdater = (updater: Updater) => {
94
95
  console.log(`\tasar path: ${getProductAsarPath(name)}`)
95
96
  console.log(`\tentry: ${getEntryVersion()}`)
96
97
  console.log(`\tapp: ${getProductVersion(name)}`)
97
- let size = 0
98
- updater.on('downloading', (progress) => {
99
- console.log(`${(progress / size).toFixed(2)}%`)
100
- })
101
- updater.on('debug', data => console.log('[updater]:', data))
98
+ updater.onDownloading = ({ percent }) => {
99
+ console.log(percent)
100
+ }
101
+ updater.logger = console
102
102
  updater.checkUpdate().then(async (result) => {
103
103
  if (result === undefined) {
104
104
  console.log('Update Unavailable')
105
105
  } else if (result instanceof Error) {
106
106
  console.error(result)
107
107
  } else {
108
- size = result.size
109
108
  console.log('new version: ', result.version)
110
109
  const { response } = await dialog.showMessageBox({
111
110
  type: 'info',
@@ -0,0 +1,9 @@
1
+ // src/updateJson.ts
2
+ function isUpdateJSON(json) {
3
+ const is = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
4
+ return is(json) && "beta" in json && is(json.beta);
5
+ }
6
+
7
+ export {
8
+ isUpdateJSON
9
+ };
@@ -1,10 +1,6 @@
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")
5
- return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
1
+ import {
2
+ __require
3
+ } from "./chunk-ZFXKCRJC.mjs";
8
4
 
9
5
  // src/utils.ts
10
6
  import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
@@ -20,9 +16,20 @@ function getEntryVersion() {
20
16
  function getProductVersion(name) {
21
17
  return app.isPackaged ? readFileSync(join(getProductAsarPath(name), "version"), "utf-8") : getEntryVersion();
22
18
  }
19
+ var NoSuchNativeModuleError = class extends Error {
20
+ moduleName;
21
+ constructor(moduleName) {
22
+ super(`no such native module: ${moduleName}`);
23
+ this.moduleName = moduleName;
24
+ }
25
+ };
23
26
  function requireNative(packageName) {
24
27
  const path = app.isPackaged ? join(app.getAppPath(), "node_modules", packageName) : packageName;
25
- return __require(path);
28
+ try {
29
+ return __require(path);
30
+ } catch (error) {
31
+ throw new NoSuchNativeModuleError(packageName);
32
+ }
26
33
  }
27
34
  function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
28
35
  if (!repository.startsWith("https://github.com/")) {
@@ -71,11 +78,11 @@ function waitAppReady(duration = 1e3) {
71
78
  }, duration);
72
79
  app.whenReady().then(() => {
73
80
  clearTimeout(timeout);
74
- resolve(null);
81
+ resolve();
75
82
  });
76
83
  });
77
84
  }
78
- async function unzipFile(gzipPath, targetFilePath) {
85
+ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
79
86
  if (!existsSync(gzipPath)) {
80
87
  throw new Error(`path to zipped file not exist: ${gzipPath}`);
81
88
  }
@@ -114,12 +121,36 @@ function handleUnexpectedErrors(callback) {
114
121
  process.on("uncaughtException", listener);
115
122
  process.on("unhandledRejection", listener);
116
123
  }
124
+ function parseVersion(version) {
125
+ const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
126
+ const match = semver.exec(version);
127
+ if (!match) {
128
+ throw new TypeError(`invalid version: ${version}`);
129
+ }
130
+ const [major, minor, patch] = match.slice(1, 4).map(Number);
131
+ const ret = {
132
+ major,
133
+ minor,
134
+ patch,
135
+ stage: "",
136
+ stageVersion: -1
137
+ };
138
+ if (match[4]) {
139
+ let [stage, _v] = match[4].split(".");
140
+ ret.stage = stage;
141
+ ret.stageVersion = Number(_v) || -1;
142
+ }
143
+ if (isNaN(major) || isNaN(minor) || isNaN(patch) || isNaN(ret.stageVersion)) {
144
+ throw new TypeError(`invalid version: ${version}`);
145
+ }
146
+ return ret;
147
+ }
117
148
 
118
149
  export {
119
- __require,
120
150
  getProductAsarPath,
121
151
  getEntryVersion,
122
152
  getProductVersion,
153
+ NoSuchNativeModuleError,
123
154
  requireNative,
124
155
  parseGithubCdnURL,
125
156
  getGithubFileCdnGroup,
@@ -128,5 +159,6 @@ export {
128
159
  waitAppReady,
129
160
  unzipFile,
130
161
  zipFile,
131
- handleUnexpectedErrors
162
+ handleUnexpectedErrors,
163
+ parseVersion
132
164
  };
@@ -0,0 +1,11 @@
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")
5
+ return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+ export {
10
+ __require
11
+ };
package/dist/index.d.mts CHANGED
@@ -1,35 +1,78 @@
1
1
  import { Buffer } from 'node:buffer';
2
+ import { UpdateJSON } from './updateJson.mjs';
2
3
 
3
- type CheckResultType = Omit<UpdateJSON, 'signature'> | undefined | Error;
4
- type InstallResult = true | Error;
5
- type UpdateEvents = {
6
- downloading: [progress: number];
7
- downloadBuffer: [buffer: Buffer];
8
- debug: [msg: string | Error];
9
- };
10
- type UpdateJSON = {
4
+ declare class MinimumVersionError extends Error {
5
+ currentVersion: string;
6
+ minVersion: string;
7
+ constructor(version: string, minimumVersion: string);
8
+ }
9
+ declare class VerifyFailedError extends Error {
11
10
  signature: string;
12
- version: string;
11
+ cert: string;
12
+ constructor(signature: string, cert: string);
13
+ }
14
+ declare class IncrementalUpdater implements Updater {
15
+ private info?;
16
+ private option;
17
+ private asarPath;
18
+ private gzipPath;
19
+ private tmpFilePath;
20
+ logger?: Logger;
21
+ onDownloading?: (progress: DownloadingInfo) => void;
22
+ get productName(): string;
23
+ set productName(name: string);
24
+ get receiveBeta(): boolean;
25
+ set receiveBeta(receiveBeta: boolean);
26
+ constructor(option: UpdaterOption);
27
+ private needUpdate;
28
+ private parseData;
29
+ checkUpdate(data?: string | UpdateJSON): Promise<CheckResultType>;
30
+ download(data?: string | Buffer, sig?: string): Promise<DownloadResult>;
31
+ }
32
+ /**
33
+ * create updater instance
34
+ * @param option updater option
35
+ * @returns updater
36
+ */
37
+ declare function createUpdater(option: UpdaterOption): IncrementalUpdater;
38
+
39
+ type CheckResultType = {
13
40
  size: number;
41
+ version: string;
42
+ } | undefined | Error | MinimumVersionError | TypeError;
43
+ type DownloadResult = true | Error | VerifyFailedError | TypeError;
44
+ type DownloadingInfo = {
45
+ /**
46
+ * downloaded percent, 0% - 100%
47
+ */
48
+ percent: string;
49
+ /**
50
+ * total size
51
+ */
52
+ total: number;
53
+ /**
54
+ * downloaded size
55
+ */
56
+ current: number;
57
+ };
58
+ type Logger = {
59
+ info: (msg: string) => void;
60
+ debug: (msg: string) => void;
61
+ warn: (msg: string) => void;
62
+ error: (msg: string, e?: Error) => void;
14
63
  };
15
- type MaybeArray<T> = T extends undefined | null | never ? [] : T extends any[] ? T['length'] extends 1 ? [data: T[0]] : T : [data: T];
16
- interface TypedUpdater<T extends Record<string | symbol, MaybeArray<any>>, Event extends Exclude<keyof T, number> = Exclude<keyof T, number>> {
17
- removeAllListeners<E extends Event>(event?: E): this;
18
- listeners<E extends Event>(eventName: E): Function[];
19
- eventNames(): (Event)[];
20
- on<E extends Event>(eventName: E, listener: (...data: MaybeArray<T[E]>) => void): this;
21
- once<E extends Event>(eventName: E, listener: (...data: MaybeArray<T[E]>) => void): this;
22
- emit<E extends Event>(eventName: E, ...args: MaybeArray<T[E]>): boolean;
23
- off<E extends Event>(eventName: E, listener: (...args: MaybeArray<T[E]>) => void): this;
64
+ interface Updater {
65
+ productName: string;
66
+ receiveBeta: boolean;
24
67
  /**
25
68
  * check update info
26
- * @param data update json url
69
+ * @param data update json url or object
27
70
  * @returns
28
71
  * - `{size: number, version: string}`: available
29
72
  * - `false`: unavailable
30
- * - `Error`: fail
73
+ * - `Error`: fail ({@link MinimumVersionError} or other)
31
74
  */
32
- checkUpdate(data?: string | UpdateJSON): Promise<CheckResultType>;
75
+ checkUpdate: (data?: string | UpdateJSON) => Promise<CheckResultType>;
33
76
  /**
34
77
  * download update
35
78
  *
@@ -38,15 +81,60 @@ interface TypedUpdater<T extends Record<string | symbol, MaybeArray<any>>, Event
38
81
  * @param sig signature
39
82
  * @returns
40
83
  * - `true`: success
41
- * - `Error`: fail
84
+ * - `Error`: fail ({@link VerifyFailedError} or other)
42
85
  */
43
- download(data?: string | Buffer, sig?: string): Promise<InstallResult>;
44
- debugMode: boolean;
45
- productName: string;
86
+ download: (data?: string | Buffer, sig?: string) => Promise<DownloadResult>;
87
+ /**
88
+ * log function
89
+ * @param data log info
90
+ */
91
+ logger?: Logger;
92
+ onDownloading?: (progress: DownloadingInfo) => void;
46
93
  }
47
- type FunctionVerifySignature = (buffer: Buffer, signature: string, cert: string) => string | false;
48
- type FunctionCompareVersion = (oldVersion: string, newVersion: string) => boolean;
49
- type Updater = TypedUpdater<UpdateEvents>;
94
+ type UpdaterOverrideFunctions = {
95
+ /**
96
+ * custom version compare function
97
+ * @param version1 old version string
98
+ * @param version2 new version string
99
+ * @returns whether version1 < version2
100
+ */
101
+ compareVersion?: (version1: string, version2: string) => boolean | Promise<boolean>;
102
+ /**
103
+ * custom verify signature function
104
+ * @param buffer file buffer
105
+ * @param signature signature
106
+ * @param cert certificate
107
+ * @returns if signature is valid, returns the version or `true` , otherwise returns `false`
108
+ */
109
+ verifySignaure?: (buffer: Buffer, signature: string, cert: string) => string | boolean | Promise<string | boolean>;
110
+ /**
111
+ * custom download JSON function
112
+ * @param url download url
113
+ * @param updater updater, to trigger events
114
+ * @param header download header
115
+ * @returns `UpdateJSON`
116
+ */
117
+ downloadJSON?: (url: string, headers: Record<string, any>) => Promise<UpdateJSON>;
118
+ /**
119
+ * custom download buffer function
120
+ * @param url download url
121
+ * @param updater updater, to trigger events
122
+ * @param header download header
123
+ * @returns `Buffer`
124
+ */
125
+ downloadBuffer?: (url: string, headers: Record<string, any>, total: number, onDownloading?: (progress: DownloadingInfo) => void) => Promise<Buffer>;
126
+ };
127
+ type UpdaterDownloadConfig = {
128
+ /**
129
+ * download user agent
130
+ * @default 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'
131
+ */
132
+ userAgent?: string;
133
+ /**
134
+ * extra download header, `accept` and `user-agent` is set by default
135
+ */
136
+ extraHeader?: Record<string, string>;
137
+ };
50
138
  interface UpdaterOption {
51
139
  /**
52
140
  * public key of signature, which will be auto generated by plugin
@@ -90,59 +178,13 @@ interface UpdaterOption {
90
178
  */
91
179
  releaseAsarURL?: string;
92
180
  /**
93
- * whether to enable debug listener
94
- */
95
- debug?: boolean;
96
- overrideFunctions?: {
97
- /**
98
- * custom version compare function {@link FunctionCompareVersion}
99
- * @param oldVersion old version string
100
- * @param newVersion new version string
101
- * @returns whether oldVersion < newVersion
102
- */
103
- compareVersion?: FunctionCompareVersion;
104
- /**
105
- * custom verify signature function {@link FunctionVerifySignature}
106
- * @param buffer file buffer
107
- * @param signature signature
108
- * @param cert certificate
109
- */
110
- verifySignaure?: FunctionVerifySignature;
111
- /**
112
- * custom download JSON function
113
- * @param url download url
114
- * @param updater updater, to trigger events
115
- * @param header download header
116
- * @returns `UpdateJSON`
117
- */
118
- downloadJSON?: (url: string, updater: Updater, headers: Record<string, any>) => Promise<UpdateJSON>;
119
- /**
120
- * custom download buffer function
121
- * @param url download url
122
- * @param updater updater, to trigger events
123
- * @param header download header
124
- * @returns `Buffer`
125
- */
126
- downloadBuffer?: (url: string, updater: Updater, headers: Record<string, any>) => Promise<Buffer>;
127
- };
128
- downloadConfig?: {
129
- /**
130
- * download user agent
131
- * @default 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'
132
- */
133
- userAgent?: string;
134
- /**
135
- * extra download header, `accept` and `user-agent` is set by default
136
- */
137
- extraHeader?: Record<string, string>;
138
- };
181
+ * whether to receive beta update
182
+ */
183
+ receiveBeta?: boolean;
184
+ overrideFunctions?: UpdaterOverrideFunctions;
185
+ downloadConfig?: UpdaterDownloadConfig;
139
186
  }
140
187
 
141
- /**
142
- * Creates an updater based on the provided options
143
- */
144
- declare function createUpdater(updaterOptions: UpdaterOption): Updater;
145
-
146
188
  type AppOption = {
147
189
  /**
148
190
  * path of electron output dist when in development
@@ -179,19 +221,20 @@ type SetUpdater = {
179
221
  *
180
222
  * const SIGNATURE_CERT = '' // auto generate certificate when start app
181
223
  *
182
- * const { cdnPrefix } = getGithubReleaseCdnGroup()[0]
224
+ * const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
225
+ * const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
183
226
  * initApp({ onStart: console.log })
184
227
  * // can be updater option or function that return updater
185
228
  * .setUpdater({
186
229
  * SIGNATURE_CERT,
187
230
  * productName: name,
188
231
  * repository,
189
- * updateJsonURL: parseGithubCdnURL(repository, 'fastly.jsdelivr.net/gh', 'version.json'),
190
- * releaseAsarURL: parseGithubCdnURL(repository, cdnPrefix, `download/latest/${name}.asar.gz`),
191
- * debug: true,
232
+ * updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
233
+ * releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${name}.asar.gz`),
234
+ * receiveBeta: true,
192
235
  * })
193
236
  * ```
194
237
  */
195
238
  declare function initApp(appOptions?: AppOption): SetUpdater;
196
239
 
197
- export { AppOption, FunctionCompareVersion, FunctionVerifySignature, StartupWithUpdater, UpdateJSON, Updater, UpdaterOption, createUpdater, initApp };
240
+ export { AppOption, IncrementalUpdater, MinimumVersionError, StartupWithUpdater, Updater, UpdaterOption, VerifyFailedError, createUpdater, initApp };
package/dist/index.d.ts CHANGED
@@ -1,35 +1,78 @@
1
1
  import { Buffer } from 'node:buffer';
2
+ import { UpdateJSON } from './updateJson.js';
2
3
 
3
- type CheckResultType = Omit<UpdateJSON, 'signature'> | undefined | Error;
4
- type InstallResult = true | Error;
5
- type UpdateEvents = {
6
- downloading: [progress: number];
7
- downloadBuffer: [buffer: Buffer];
8
- debug: [msg: string | Error];
9
- };
10
- type UpdateJSON = {
4
+ declare class MinimumVersionError extends Error {
5
+ currentVersion: string;
6
+ minVersion: string;
7
+ constructor(version: string, minimumVersion: string);
8
+ }
9
+ declare class VerifyFailedError extends Error {
11
10
  signature: string;
12
- version: string;
11
+ cert: string;
12
+ constructor(signature: string, cert: string);
13
+ }
14
+ declare class IncrementalUpdater implements Updater {
15
+ private info?;
16
+ private option;
17
+ private asarPath;
18
+ private gzipPath;
19
+ private tmpFilePath;
20
+ logger?: Logger;
21
+ onDownloading?: (progress: DownloadingInfo) => void;
22
+ get productName(): string;
23
+ set productName(name: string);
24
+ get receiveBeta(): boolean;
25
+ set receiveBeta(receiveBeta: boolean);
26
+ constructor(option: UpdaterOption);
27
+ private needUpdate;
28
+ private parseData;
29
+ checkUpdate(data?: string | UpdateJSON): Promise<CheckResultType>;
30
+ download(data?: string | Buffer, sig?: string): Promise<DownloadResult>;
31
+ }
32
+ /**
33
+ * create updater instance
34
+ * @param option updater option
35
+ * @returns updater
36
+ */
37
+ declare function createUpdater(option: UpdaterOption): IncrementalUpdater;
38
+
39
+ type CheckResultType = {
13
40
  size: number;
41
+ version: string;
42
+ } | undefined | Error | MinimumVersionError | TypeError;
43
+ type DownloadResult = true | Error | VerifyFailedError | TypeError;
44
+ type DownloadingInfo = {
45
+ /**
46
+ * downloaded percent, 0% - 100%
47
+ */
48
+ percent: string;
49
+ /**
50
+ * total size
51
+ */
52
+ total: number;
53
+ /**
54
+ * downloaded size
55
+ */
56
+ current: number;
57
+ };
58
+ type Logger = {
59
+ info: (msg: string) => void;
60
+ debug: (msg: string) => void;
61
+ warn: (msg: string) => void;
62
+ error: (msg: string, e?: Error) => void;
14
63
  };
15
- type MaybeArray<T> = T extends undefined | null | never ? [] : T extends any[] ? T['length'] extends 1 ? [data: T[0]] : T : [data: T];
16
- interface TypedUpdater<T extends Record<string | symbol, MaybeArray<any>>, Event extends Exclude<keyof T, number> = Exclude<keyof T, number>> {
17
- removeAllListeners<E extends Event>(event?: E): this;
18
- listeners<E extends Event>(eventName: E): Function[];
19
- eventNames(): (Event)[];
20
- on<E extends Event>(eventName: E, listener: (...data: MaybeArray<T[E]>) => void): this;
21
- once<E extends Event>(eventName: E, listener: (...data: MaybeArray<T[E]>) => void): this;
22
- emit<E extends Event>(eventName: E, ...args: MaybeArray<T[E]>): boolean;
23
- off<E extends Event>(eventName: E, listener: (...args: MaybeArray<T[E]>) => void): this;
64
+ interface Updater {
65
+ productName: string;
66
+ receiveBeta: boolean;
24
67
  /**
25
68
  * check update info
26
- * @param data update json url
69
+ * @param data update json url or object
27
70
  * @returns
28
71
  * - `{size: number, version: string}`: available
29
72
  * - `false`: unavailable
30
- * - `Error`: fail
73
+ * - `Error`: fail ({@link MinimumVersionError} or other)
31
74
  */
32
- checkUpdate(data?: string | UpdateJSON): Promise<CheckResultType>;
75
+ checkUpdate: (data?: string | UpdateJSON) => Promise<CheckResultType>;
33
76
  /**
34
77
  * download update
35
78
  *
@@ -38,15 +81,60 @@ interface TypedUpdater<T extends Record<string | symbol, MaybeArray<any>>, Event
38
81
  * @param sig signature
39
82
  * @returns
40
83
  * - `true`: success
41
- * - `Error`: fail
84
+ * - `Error`: fail ({@link VerifyFailedError} or other)
42
85
  */
43
- download(data?: string | Buffer, sig?: string): Promise<InstallResult>;
44
- debugMode: boolean;
45
- productName: string;
86
+ download: (data?: string | Buffer, sig?: string) => Promise<DownloadResult>;
87
+ /**
88
+ * log function
89
+ * @param data log info
90
+ */
91
+ logger?: Logger;
92
+ onDownloading?: (progress: DownloadingInfo) => void;
46
93
  }
47
- type FunctionVerifySignature = (buffer: Buffer, signature: string, cert: string) => string | false;
48
- type FunctionCompareVersion = (oldVersion: string, newVersion: string) => boolean;
49
- type Updater = TypedUpdater<UpdateEvents>;
94
+ type UpdaterOverrideFunctions = {
95
+ /**
96
+ * custom version compare function
97
+ * @param version1 old version string
98
+ * @param version2 new version string
99
+ * @returns whether version1 < version2
100
+ */
101
+ compareVersion?: (version1: string, version2: string) => boolean | Promise<boolean>;
102
+ /**
103
+ * custom verify signature function
104
+ * @param buffer file buffer
105
+ * @param signature signature
106
+ * @param cert certificate
107
+ * @returns if signature is valid, returns the version or `true` , otherwise returns `false`
108
+ */
109
+ verifySignaure?: (buffer: Buffer, signature: string, cert: string) => string | boolean | Promise<string | boolean>;
110
+ /**
111
+ * custom download JSON function
112
+ * @param url download url
113
+ * @param updater updater, to trigger events
114
+ * @param header download header
115
+ * @returns `UpdateJSON`
116
+ */
117
+ downloadJSON?: (url: string, headers: Record<string, any>) => Promise<UpdateJSON>;
118
+ /**
119
+ * custom download buffer function
120
+ * @param url download url
121
+ * @param updater updater, to trigger events
122
+ * @param header download header
123
+ * @returns `Buffer`
124
+ */
125
+ downloadBuffer?: (url: string, headers: Record<string, any>, total: number, onDownloading?: (progress: DownloadingInfo) => void) => Promise<Buffer>;
126
+ };
127
+ type UpdaterDownloadConfig = {
128
+ /**
129
+ * download user agent
130
+ * @default 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'
131
+ */
132
+ userAgent?: string;
133
+ /**
134
+ * extra download header, `accept` and `user-agent` is set by default
135
+ */
136
+ extraHeader?: Record<string, string>;
137
+ };
50
138
  interface UpdaterOption {
51
139
  /**
52
140
  * public key of signature, which will be auto generated by plugin
@@ -90,59 +178,13 @@ interface UpdaterOption {
90
178
  */
91
179
  releaseAsarURL?: string;
92
180
  /**
93
- * whether to enable debug listener
94
- */
95
- debug?: boolean;
96
- overrideFunctions?: {
97
- /**
98
- * custom version compare function {@link FunctionCompareVersion}
99
- * @param oldVersion old version string
100
- * @param newVersion new version string
101
- * @returns whether oldVersion < newVersion
102
- */
103
- compareVersion?: FunctionCompareVersion;
104
- /**
105
- * custom verify signature function {@link FunctionVerifySignature}
106
- * @param buffer file buffer
107
- * @param signature signature
108
- * @param cert certificate
109
- */
110
- verifySignaure?: FunctionVerifySignature;
111
- /**
112
- * custom download JSON function
113
- * @param url download url
114
- * @param updater updater, to trigger events
115
- * @param header download header
116
- * @returns `UpdateJSON`
117
- */
118
- downloadJSON?: (url: string, updater: Updater, headers: Record<string, any>) => Promise<UpdateJSON>;
119
- /**
120
- * custom download buffer function
121
- * @param url download url
122
- * @param updater updater, to trigger events
123
- * @param header download header
124
- * @returns `Buffer`
125
- */
126
- downloadBuffer?: (url: string, updater: Updater, headers: Record<string, any>) => Promise<Buffer>;
127
- };
128
- downloadConfig?: {
129
- /**
130
- * download user agent
131
- * @default 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'
132
- */
133
- userAgent?: string;
134
- /**
135
- * extra download header, `accept` and `user-agent` is set by default
136
- */
137
- extraHeader?: Record<string, string>;
138
- };
181
+ * whether to receive beta update
182
+ */
183
+ receiveBeta?: boolean;
184
+ overrideFunctions?: UpdaterOverrideFunctions;
185
+ downloadConfig?: UpdaterDownloadConfig;
139
186
  }
140
187
 
141
- /**
142
- * Creates an updater based on the provided options
143
- */
144
- declare function createUpdater(updaterOptions: UpdaterOption): Updater;
145
-
146
188
  type AppOption = {
147
189
  /**
148
190
  * path of electron output dist when in development
@@ -179,19 +221,20 @@ type SetUpdater = {
179
221
  *
180
222
  * const SIGNATURE_CERT = '' // auto generate certificate when start app
181
223
  *
182
- * const { cdnPrefix } = getGithubReleaseCdnGroup()[0]
224
+ * const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
225
+ * const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
183
226
  * initApp({ onStart: console.log })
184
227
  * // can be updater option or function that return updater
185
228
  * .setUpdater({
186
229
  * SIGNATURE_CERT,
187
230
  * productName: name,
188
231
  * repository,
189
- * updateJsonURL: parseGithubCdnURL(repository, 'fastly.jsdelivr.net/gh', 'version.json'),
190
- * releaseAsarURL: parseGithubCdnURL(repository, cdnPrefix, `download/latest/${name}.asar.gz`),
191
- * debug: true,
232
+ * updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
233
+ * releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${name}.asar.gz`),
234
+ * receiveBeta: true,
192
235
  * })
193
236
  * ```
194
237
  */
195
238
  declare function initApp(appOptions?: AppOption): SetUpdater;
196
239
 
197
- export { AppOption, FunctionCompareVersion, FunctionVerifySignature, StartupWithUpdater, UpdateJSON, Updater, UpdaterOption, createUpdater, initApp };
240
+ export { AppOption, IncrementalUpdater, MinimumVersionError, StartupWithUpdater, Updater, UpdaterOption, VerifyFailedError, createUpdater, initApp };