electron-incremental-update 2.0.0-beta.9 → 2.0.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.
@@ -0,0 +1,87 @@
1
+ import { __require } from './chunk-RCRKUKFX.js';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import electron from 'electron';
5
+
6
+ var isDev = __EIU_IS_DEV__;
7
+ var isWin = process.platform === "win32";
8
+ var isMac = process.platform === "darwin";
9
+ var isLinux = process.platform === "linux";
10
+ function getPathFromAppNameAsar(...paths) {
11
+ return isDev ? "DEV.asar" : path.join(path.dirname(electron.app.getAppPath()), `${electron.app.name}.asar`, ...paths);
12
+ }
13
+ function getAppVersion() {
14
+ return isDev ? getEntryVersion() : fs.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
15
+ }
16
+ function getEntryVersion() {
17
+ return electron.app.getVersion();
18
+ }
19
+ function requireNative(moduleName) {
20
+ if (__EIU_IS_ESM__) {
21
+ throw new Error(`Cannot require "${path.join(__EIU_ENTRY_DIST_PATH__, moduleName)}", \`requireNative\` only support CommonJS`);
22
+ }
23
+ return __require(path.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
24
+ }
25
+ function restartApp() {
26
+ electron.app.relaunch();
27
+ electron.app.quit();
28
+ }
29
+ function setAppUserModelId(id) {
30
+ if (isWin) {
31
+ electron.app.setAppUserModelId(id ?? `org.${electron.app.name}`);
32
+ }
33
+ }
34
+ function disableHWAccForWin7() {
35
+ if (!__EIU_IS_ESM__ && __require("node:os").release().startsWith("6.1")) {
36
+ electron.app.disableHardwareAcceleration();
37
+ }
38
+ }
39
+ function singleInstance(window) {
40
+ const result = electron.app.requestSingleInstanceLock();
41
+ if (result) {
42
+ electron.app.on("second-instance", () => {
43
+ if (window) {
44
+ window.show();
45
+ if (window.isMinimized()) {
46
+ window.restore();
47
+ }
48
+ window.focus();
49
+ }
50
+ });
51
+ } else {
52
+ electron.app.quit();
53
+ }
54
+ return result;
55
+ }
56
+ function setPortableAppDataPath(dirName = "data") {
57
+ const portablePath = path.join(path.dirname(electron.app.getPath("exe")), dirName);
58
+ if (!fs.existsSync(portablePath)) {
59
+ fs.mkdirSync(portablePath);
60
+ }
61
+ electron.app.setPath("appData", portablePath);
62
+ }
63
+ function loadPage(win, htmlFilePath = "index.html") {
64
+ if (isDev) {
65
+ win.loadURL(process.env.VITE_DEV_SERVER_URL + htmlFilePath);
66
+ } else {
67
+ win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
68
+ }
69
+ }
70
+ function getPathFromMain(...paths) {
71
+ return isDev ? path.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "main", ...paths) : getPathFromAppNameAsar("main", ...paths);
72
+ }
73
+ function getPathFromPreload(...paths) {
74
+ return isDev ? path.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
75
+ }
76
+ function getPathFromPublic(...paths) {
77
+ return isDev ? path.join(electron.app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
78
+ }
79
+ function getPathFromEntryAsar(...paths) {
80
+ return path.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
81
+ }
82
+ function handleUnexpectedErrors(callback) {
83
+ process.on("uncaughtException", callback);
84
+ process.on("unhandledRejection", callback);
85
+ }
86
+
87
+ export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
@@ -25,7 +25,7 @@ function parseVersion(version) {
25
25
  ret.stageVersion = Number(_v) || -1;
26
26
  }
27
27
  if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
28
- throw new TypeError(`invalid version: ${version}`);
28
+ throw new TypeError(`Invalid version: ${version}`);
29
29
  }
30
30
  return ret;
31
31
  }
package/dist/index.cjs CHANGED
@@ -8,6 +8,7 @@ var path = require('path');
8
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
9
 
10
10
  var fs3__default = /*#__PURE__*/_interopDefault(fs3);
11
+ var electron__default = /*#__PURE__*/_interopDefault(electron);
11
12
  var path__default = /*#__PURE__*/_interopDefault(path);
12
13
 
13
14
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
@@ -27,53 +28,54 @@ process.platform === "win32";
27
28
  process.platform === "darwin";
28
29
  process.platform === "linux";
29
30
  function getPathFromAppNameAsar(...paths) {
30
- return isDev ? "DEV.asar" : path__default.default.join(path__default.default.dirname(electron.app.getAppPath()), `${electron.app.name}.asar`, ...paths);
31
+ return isDev ? "DEV.asar" : path__default.default.join(path__default.default.dirname(electron__default.default.app.getAppPath()), `${electron__default.default.app.name}.asar`, ...paths);
31
32
  }
32
33
  function getAppVersion() {
33
34
  return isDev ? getEntryVersion() : fs3__default.default.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
34
35
  }
35
36
  function getEntryVersion() {
36
- return electron.app.getVersion();
37
+ return electron__default.default.app.getVersion();
37
38
  }
38
39
  function restartApp() {
39
- electron.app.relaunch();
40
- electron.app.quit();
40
+ electron__default.default.app.relaunch();
41
+ electron__default.default.app.quit();
41
42
  }
42
43
 
43
44
  // src/entry/types.ts
44
45
  var ErrorInfo = {
45
- download: "Download failed",
46
- validate: "Validate failed",
47
- param: "Missing params",
48
- network: "Network error"
46
+ download: "Download Failed",
47
+ validate: "Validate Failed",
48
+ param: "Missing Params",
49
+ network: "Network Error"
49
50
  };
50
51
  var UpdaterError = class extends Error {
51
52
  code;
52
53
  constructor(msg, info) {
53
- super(ErrorInfo[msg] + ": " + info);
54
+ super(`[${ErrorInfo[msg]}] ${info}`);
54
55
  this.code = msg;
55
56
  }
56
57
  };
57
58
 
58
59
  // src/entry/updater.ts
59
60
  var Updater = class extends events.EventEmitter {
60
- CERT = __EIU_SIGNATURE_CERT__;
61
+ CERT;
62
+ controller;
61
63
  info;
62
64
  provider;
63
65
  /**
64
- * updater logger
66
+ * Updater logger
65
67
  */
66
68
  logger;
67
69
  /**
68
- * whether to receive beta update
70
+ * Whether to receive beta update
69
71
  */
70
72
  receiveBeta;
71
73
  /**
72
- * whether force update in DEV
74
+ * Whether force update in DEV
73
75
  */
74
76
  forceUpdate;
75
77
  /**
76
- * initialize incremental updater
78
+ * Initialize incremental updater
77
79
  * @param options UpdaterOption
78
80
  */
79
81
  constructor(options = {}) {
@@ -82,6 +84,7 @@ var Updater = class extends events.EventEmitter {
82
84
  this.receiveBeta = options.receiveBeta;
83
85
  this.CERT = options.SIGNATURE_CERT || __EIU_SIGNATURE_CERT__;
84
86
  this.logger = options.logger;
87
+ this.controller = new AbortController();
85
88
  if (isDev && !this.logger) {
86
89
  this.logger = {
87
90
  info: (...args) => console.log("[EIU-INFO ]", ...args),
@@ -89,15 +92,10 @@ var Updater = class extends events.EventEmitter {
89
92
  warn: (...args) => console.log("[EIU-WARN ]", ...args),
90
93
  error: (...args) => console.error("[EIU-ERROR]", ...args)
91
94
  };
92
- this.logger.info("no logger set, enable dev-only logger");
95
+ this.logger.info("No logger set, enable dev-only logger");
93
96
  }
94
97
  if (!this.provider) {
95
- this.logger?.debug("No update provider, please setup provider before checking update");
96
- }
97
- }
98
- checkProvider() {
99
- if (!this.provider) {
100
- throw new UpdaterError("param", "missing update provider");
98
+ this.logger?.debug("WARN: No update provider");
101
99
  }
102
100
  }
103
101
  async fetch(format, data) {
@@ -105,92 +103,99 @@ var Updater = class extends events.EventEmitter {
105
103
  if (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer.isBuffer(data)) {
106
104
  return data;
107
105
  } else {
108
- this.err("invalid type", "param", `invalid type at format '${format}': ${JSON.stringify(data)}`);
106
+ this.err("Invalid type", "param", `Invalid type at format '${format}': ${JSON.stringify(data)}`);
109
107
  return;
110
108
  }
111
109
  }
112
- this.logger?.debug(`download from ${this.provider.name}`);
110
+ this.logger?.debug(`Download from \`${this.provider.name}\``);
113
111
  try {
114
- const result = format === "json" ? await this.provider.downloadJSON(data ?? __EIU_VERSION_PATH__) : await this.provider.downloadAsar(electron.app.name, this.info, (data2) => this.emit("download-progress", data2));
115
- this.logger?.debug(`download ${format} success${format === "buffer" ? `, file size: ${result.length}` : ""}`);
112
+ const result = format === "json" ? await this.provider.downloadJSON(__EIU_VERSION_PATH__, this.controller.signal) : await this.provider.downloadAsar(electron.app.name, this.info, this.controller.signal, (info) => this.emit("download-progress", info));
113
+ this.logger?.debug(`Download ${format} success${format === "buffer" ? `, file size: ${result.length}` : ""}`);
116
114
  return result;
117
115
  } catch (e) {
118
- this.err(`fetch ${format} failed`, "network", `download ${format} failed: ${e}`);
116
+ this.err(`Fetch ${format} failed`, "network", e instanceof Error ? e.message : e.toString());
119
117
  }
120
118
  }
121
119
  /**
122
- * handle error message and emit error event
120
+ * Handle error message and emit error event
123
121
  */
124
122
  err(msg, code, errorInfo) {
125
123
  const err = new UpdaterError(code, errorInfo);
126
124
  this.logger?.error(msg, err);
127
125
  this.emit("error", err);
128
126
  }
129
- async checkUpdate(data) {
130
- this.checkProvider();
131
- const emitUnavailable = (msg) => {
127
+ async checkForUpdates(data) {
128
+ const emitUnavailable = (msg, info2) => {
132
129
  this.logger?.info(msg);
133
- this.emit("update-unavailable", msg);
130
+ this.emit("update-not-available", msg, info2);
134
131
  return false;
135
132
  };
133
+ if (!data && !this.provider) {
134
+ this.err("Check update failed", "param", "No update json or provider");
135
+ return false;
136
+ }
136
137
  const _data = await this.fetch("json", data);
137
138
  if (!_data) {
138
- return emitUnavailable("failed to get update info");
139
- }
140
- let { signature, version, minimumVersion, beta } = _data;
141
- if (this.receiveBeta) {
142
- version = beta.version;
143
- signature = beta.signature;
144
- minimumVersion = beta.minimumVersion;
139
+ return emitUnavailable("Failed to get update info");
145
140
  }
146
- this.logger?.debug(`checked update, version: ${version}, signature: ${signature}`);
141
+ const { signature, version, minimumVersion } = this.receiveBeta ? _data.beta : _data;
142
+ const info = { signature, minimumVersion, version };
143
+ this.logger?.debug(`Checked update, version: ${version}, signature: ${signature}`);
147
144
  if (isDev && !this.forceUpdate && !data) {
148
- return emitUnavailable("skip check update in dev mode, to force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON");
145
+ return emitUnavailable("Skip check update in dev mode. To force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON", info);
149
146
  }
150
147
  const isLowerVersion = this.provider.isLowerVersion;
151
148
  const entryVersion = getEntryVersion();
152
149
  const appVersion = getAppVersion();
153
- if (isLowerVersion(entryVersion, minimumVersion)) {
154
- return emitUnavailable(`entry version (${entryVersion}) < minimumVersion (${minimumVersion})`);
155
- }
156
- this.logger?.info(`check update: current version is ${appVersion}, new version is ${version}`);
157
- if (!isLowerVersion(appVersion, version)) {
158
- return emitUnavailable(`current version (${appVersion}) < new version (${version})`);
150
+ try {
151
+ if (isLowerVersion(entryVersion, minimumVersion)) {
152
+ return emitUnavailable(`Entry Version (${entryVersion}) < MinimumVersion (${minimumVersion})`, info);
153
+ }
154
+ this.logger?.info(`Check update: current version is ${appVersion}, new version is ${version}`);
155
+ if (!isLowerVersion(appVersion, version)) {
156
+ return emitUnavailable(`Current version (${appVersion}) < New version (${version})`, info);
157
+ }
158
+ this.logger?.info(`Update available: ${version}`);
159
+ this.emit("update-available", info);
160
+ this.info = info;
161
+ return true;
162
+ } catch {
163
+ this.err("Fail to parse version", "validate", "Fail to parse version string");
164
+ return false;
159
165
  }
160
- this.logger?.info(`update available: ${version}`);
161
- this.info = { signature, minimumVersion, version };
162
- this.emit("update-available", this.info);
163
- return true;
164
166
  }
165
167
  async downloadUpdate(data, info) {
166
- this.checkProvider();
167
168
  const _sig = info?.signature ?? this.info?.signature;
168
169
  const _version = info?.version ?? this.info?.version;
169
170
  if (!_sig || !_version) {
170
- this.err("download failed", "param", "no update signature, please call `checkUpdate` first or manually setup params");
171
+ this.err("Download failed", "param", "No update signature, please call `checkUpdate` first or manually setup params");
172
+ return false;
173
+ }
174
+ if (!data && !this.provider) {
175
+ this.err("Download failed", "param", "No update asar buffer and provider");
171
176
  return false;
172
177
  }
173
178
  const buffer = await this.fetch("buffer", data ? Buffer.from(data) : void 0);
174
179
  if (!buffer) {
175
- this.err("download failed", "param", "no update asar file buffer");
180
+ this.err("Download failed", "param", "No update asar file buffer");
176
181
  return false;
177
182
  }
178
183
  this.logger?.debug("verify start");
179
184
  if (!await this.provider.verifySignaure(buffer, _version, _sig, this.CERT)) {
180
- this.err("download failed", "validate", "invalid update asar file");
185
+ this.err("Download failed", "validate", "Invalid update asar file");
181
186
  return false;
182
187
  }
183
- this.logger?.debug("verify success");
188
+ this.logger?.debug("Verify success");
184
189
  try {
185
- const tmpFilePath = getPathFromAppNameAsar() + ".tmp";
186
- this.logger?.debug(`install to ${tmpFilePath}`);
190
+ const tmpFilePath = `${getPathFromAppNameAsar()}.tmp`;
191
+ this.logger?.debug(`Install to ${tmpFilePath}`);
187
192
  fs3__default.default.writeFileSync(tmpFilePath, await this.provider.unzipFile(buffer));
188
- this.logger?.info(`download success, version: ${_version}`);
193
+ this.logger?.info(`Download success, version: ${_version}`);
189
194
  this.info = void 0;
190
195
  this.emit("update-downloaded");
191
196
  return true;
192
197
  } catch (error) {
193
- this.err("download failed", "download", `fail to unwrap asar file, ${error}`);
198
+ this.err("Download failed", "download", `Fail to unwrap asar file, ${error}`);
194
199
  return false;
195
200
  }
196
201
  }
@@ -198,12 +203,21 @@ var Updater = class extends events.EventEmitter {
198
203
  * quit App and install
199
204
  */
200
205
  quitAndInstall() {
201
- this.logger?.info("quit and install");
206
+ this.logger?.info("Quit and install");
202
207
  restartApp();
203
208
  }
209
+ cancel() {
210
+ if (this.controller.signal.aborted) {
211
+ return;
212
+ }
213
+ this.controller.abort();
214
+ this.logger?.info("Cancel update");
215
+ this.emit("update-cancelled");
216
+ this.controller = new AbortController();
217
+ }
204
218
  };
205
219
  async function autoUpdate(updater) {
206
- if (await updater.checkUpdate() && await updater.downloadUpdate()) {
220
+ if (await updater.checkForUpdates() && await updater.downloadUpdate()) {
207
221
  updater.quitAndInstall();
208
222
  }
209
223
  }
@@ -214,8 +228,14 @@ var defaultOnInstall = (install, _, __, logger) => {
214
228
  install();
215
229
  logger?.info(`update success!`);
216
230
  };
217
- async function initApp(appOptions) {
231
+ async function createElectronApp(appOptions = {}) {
232
+ const appNameAsarPath = getPathFromAppNameAsar();
218
233
  const {
234
+ mainPath = path__default.default.join(
235
+ isDev ? path__default.default.join(electron.app.getAppPath(), __EIU_MAIN_DEV_DIR__) : appNameAsarPath,
236
+ "main",
237
+ __EIU_MAIN_FILE__
238
+ ),
219
239
  updater,
220
240
  onInstall = defaultOnInstall,
221
241
  beforeStart,
@@ -229,29 +249,29 @@ async function initApp(appOptions) {
229
249
  }
230
250
  const logger = updaterInstance.logger;
231
251
  try {
232
- const appNameAsarPath = getPathFromAppNameAsar();
233
252
  const tempAsarPath = `${appNameAsarPath}.tmp`;
234
253
  if (fs3__default.default.existsSync(tempAsarPath)) {
235
- logger?.info(`installing new asar: ${tempAsarPath}`);
254
+ logger?.info(`Installing new asar from ${tempAsarPath}`);
236
255
  await onInstall(() => fs3__default.default.renameSync(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
237
256
  }
238
- const mainFilePath = path__default.default.join(
239
- isDev ? path__default.default.join(electron.app.getAppPath(), __EIU_MAIN_DEV_DIR__) : appNameAsarPath,
240
- "main",
241
- __EIU_MAIN_FILE__
242
- );
243
- await beforeStart?.(mainFilePath, logger);
244
- __require(mainFilePath)(updaterInstance);
257
+ await beforeStart?.(mainPath, logger);
258
+ if (__EIU_IS_ESM__) {
259
+ (await import(`file://${mainPath}`)).default(updaterInstance);
260
+ } else {
261
+ __require(mainPath)(updaterInstance);
262
+ }
245
263
  } catch (error) {
246
264
  logger?.error("startup error", error);
247
265
  onStartError?.(error, logger);
248
266
  electron.app.quit();
249
267
  }
250
268
  }
269
+ var initApp = createElectronApp;
251
270
 
252
271
  exports.ErrorInfo = ErrorInfo;
253
272
  exports.Updater = Updater;
254
273
  exports.UpdaterError = UpdaterError;
255
274
  exports.autoUpdate = autoUpdate;
275
+ exports.createElectronApp = createElectronApp;
256
276
  exports.initApp = initApp;
257
277
  exports.startupWithUpdater = startupWithUpdater;
package/dist/index.d.cts CHANGED
@@ -1,37 +1,18 @@
1
1
  import { EventEmitter } from 'node:events';
2
- import { U as UpdateJSON, a as UpdateInfo } from './version-DgfjJQUx.cjs';
3
- import { I as IProvider, D as DownloadingInfo } from './types-mEfMjnlV.cjs';
4
- import '@subframe7536/type-utils';
2
+ import { U as UpdateInfo, a as UpdateJSON } from './version-BYVQ367i.cjs';
3
+ import { I as IProvider, D as DownloadingInfo } from './types-DkCn03M3.cjs';
4
+ import { Promisable } from '@subframe7536/type-utils';
5
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";
7
+ readonly download: "Download Failed";
8
+ readonly validate: "Validate Failed";
9
+ readonly param: "Missing Params";
10
+ readonly network: "Network Error";
11
11
  };
12
12
  declare class UpdaterError extends Error {
13
13
  code: keyof typeof ErrorInfo;
14
14
  constructor(msg: keyof typeof ErrorInfo, info: string);
15
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
16
  interface Logger {
36
17
  info: (msg: string) => void;
37
18
  debug: (msg: string) => void;
@@ -40,81 +21,82 @@ interface Logger {
40
21
  }
41
22
  interface UpdaterOption {
42
23
  /**
43
- * update provider
24
+ * Update provider
25
+ *
26
+ * If you will not setup `UpdateJSON` or `Buffer` in params when checking update or download, this option is **required**
44
27
  */
45
28
  provider?: IProvider;
46
29
  /**
47
- * public key of signature, which will be auto generated by plugin,
30
+ * Certifaction key of signature, which will be auto generated by plugin,
48
31
  * generate by `selfsigned` if not set
49
32
  */
50
33
  SIGNATURE_CERT?: string;
51
34
  /**
52
- * whether to receive beta update
35
+ * Whether to receive beta update
53
36
  */
54
37
  receiveBeta?: boolean;
38
+ /**
39
+ * Updater logger
40
+ */
55
41
  logger?: Logger;
56
42
  }
57
43
 
58
44
  declare class Updater extends EventEmitter<{
59
45
  'checking': any;
60
46
  'update-available': [data: UpdateInfo];
61
- 'update-unavailable': [reason: string];
47
+ 'update-not-available': [reason: string, data?: UpdateInfo];
62
48
  'error': [error: UpdaterError];
63
49
  'download-progress': [info: DownloadingInfo];
64
50
  'update-downloaded': any;
51
+ 'update-cancelled': any;
65
52
  }> {
66
53
  private CERT;
54
+ private controller;
67
55
  private info?;
68
56
  provider?: IProvider;
69
57
  /**
70
- * updater logger
58
+ * Updater logger
71
59
  */
72
60
  logger?: Logger;
73
61
  /**
74
- * whether to receive beta update
62
+ * Whether to receive beta update
75
63
  */
76
64
  receiveBeta?: boolean;
77
65
  /**
78
- * whether force update in DEV
66
+ * Whether force update in DEV
79
67
  */
80
68
  forceUpdate?: boolean;
81
69
  /**
82
- * initialize incremental updater
70
+ * Initialize incremental updater
83
71
  * @param options UpdaterOption
84
72
  */
85
73
  constructor(options?: UpdaterOption);
86
- private checkProvider;
87
- /**
88
- * this function is used to parse download data.
89
- * - if format is `'json'`
90
- * - if data is `UpdateJSON`, return it
91
- * - if data is string or absent, download URL data and return it
92
- * - if format is `'buffer'`
93
- * - if data is `Buffer`, return it
94
- * - if data is string or absent, download URL data and return it
95
- * @param format 'json' or 'buffer'
96
- * @param data download URL or update json or buffer
74
+ /**
75
+ * This function is used to parse download data.
76
+ *
77
+ * if data is absent, download URL from provider and return it,
78
+ * else if data is `UpdateJSON`, return it
97
79
  */
98
80
  private fetch;
99
81
  /**
100
- * handle error message and emit error event
82
+ * Handle error message and emit error event
101
83
  */
102
84
  private err;
103
85
  /**
104
- * check update info using default options
86
+ * Check update info using default options
105
87
  */
106
- checkUpdate(): Promise<boolean>;
88
+ checkForUpdates(): Promise<boolean>;
107
89
  /**
108
- * check update info using existing update json
90
+ * Check update info using existing update json
109
91
  * @param data existing update json
110
92
  */
111
- checkUpdate(data: UpdateJSON): Promise<boolean>;
93
+ checkForUpdates(data: UpdateJSON): Promise<boolean>;
112
94
  /**
113
- * download update using default options
95
+ * Download update using default options
114
96
  */
115
97
  downloadUpdate(): Promise<boolean>;
116
98
  /**
117
- * download update using existing `asar.gz` buffer and signature
99
+ * Download update using existing `asar.gz` buffer and signature
118
100
  * @param data existing `asar.gz` buffer
119
101
  * @param info update info
120
102
  */
@@ -123,46 +105,52 @@ declare class Updater extends EventEmitter<{
123
105
  * quit App and install
124
106
  */
125
107
  quitAndInstall(): void;
108
+ cancel(): void;
126
109
  }
127
110
  /**
128
- * auto check update, download and install
111
+ * Auto check update, download and install
129
112
  */
130
113
  declare function autoUpdate(updater: Updater): Promise<void>;
131
114
 
132
- type Promisable<T> = T | Promise<T>;
133
115
  /**
134
- * hooks on rename temp asar path to `${app.name}.asar`
116
+ * Hooks on rename temp asar path to `${app.name}.asar`
135
117
  * @param install `() => renameSync(tempAsarPath, appNameAsarPath)`
136
118
  * @param tempAsarPath temp(updated) asar path
137
119
  * @param appNameAsarPath `${app.name}.asar` path
138
120
  * @param logger logger
139
- * @default install(); logger.info(`update success!`)
121
+ * @default install(); logger.info('update success!')
140
122
  */
141
123
  type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
142
124
  interface AppOption {
143
125
  /**
144
- * updater options
126
+ * Path to index file that make {@link startupWithUpdater} as default export
127
+ *
128
+ * Generate from plugin configuration by default
129
+ */
130
+ mainPath?: string;
131
+ /**
132
+ * Updater options
145
133
  */
146
134
  updater?: (() => Promisable<Updater>) | UpdaterOption;
147
135
  /**
148
- * hooks on rename temp asar path to `${app.name}.asar`
136
+ * Hooks on rename temp asar path to `${app.name}.asar`
149
137
  */
150
138
  onInstall?: OnInstallFunction;
151
139
  /**
152
- * hooks before app start up
140
+ * Hooks before app startup
153
141
  * @param mainFilePath main file path of `${app.name}.asar`
154
142
  * @param logger logger
155
143
  */
156
144
  beforeStart?: (mainFilePath: string, logger?: Logger) => Promisable<void>;
157
145
  /**
158
- * hooks on app start up error
146
+ * Hooks on app startup error
159
147
  * @param err installing or startup error
160
148
  * @param logger logger
161
149
  */
162
150
  onStartError?: (err: unknown, logger?: Logger) => void;
163
151
  }
164
152
  /**
165
- * utils for startuping with updater
153
+ * Utils to startup with updater
166
154
  * @param fn startup function
167
155
  * @example
168
156
  * // in electron/main/index.ts
@@ -172,28 +160,24 @@ interface AppOption {
172
160
  */
173
161
  declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>): (updater: Updater) => Promisable<void>;
174
162
  /**
175
- * initialize app
163
+ * Initialize Electron with updater
176
164
  * @example
177
- * ```ts
178
- * import { getGithubReleaseCdnGroup, initApp, parseGithubCdnURL } from 'electron-incremental-update'
179
- * import { repository } from '../package.json'
180
- *
181
- * const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
182
- * const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
183
- *
184
- * initApp({
185
- * // can be updater option or function that return updater
165
+ * createElectronApp({
186
166
  * updater: {
187
- * SIGNATURE_CERT: 'custom certificate',
188
- * repository,
189
- * updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
190
- * releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${app.name}.asar.gz`),
191
- * receiveBeta: true,
167
+ * provider: new GitHubProvider({
168
+ * username: 'yourname',
169
+ * repo: 'electron',
170
+ * }),
171
+ * },
172
+ * beforeStart(mainFilePath, logger) {
173
+ * logger?.debug(mainFilePath)
192
174
  * },
193
- * onStart: console.log
194
175
  * })
195
- * ```
196
176
  */
197
- declare function initApp(appOptions: AppOption): Promise<void>;
177
+ declare function createElectronApp(appOptions?: AppOption): Promise<void>;
178
+ /**
179
+ * @alias {@link createElectronApp}
180
+ */
181
+ declare const initApp: typeof createElectronApp;
198
182
 
199
- export { type AppOption, type CheckResult, type DownloadResult, ErrorInfo, type Logger, Updater, UpdaterError, type UpdaterOption, autoUpdate, initApp, startupWithUpdater };
183
+ export { type AppOption, ErrorInfo, type Logger, Updater, UpdaterError, type UpdaterOption, autoUpdate, createElectronApp, initApp, startupWithUpdater };