electron-incremental-update 1.3.0 → 2.0.0-beta.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/dist/index.cjs CHANGED
@@ -17,69 +17,54 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
20
+ // src/entry.ts
21
+ var entry_exports = {};
22
+ __export(entry_exports, {
23
23
  ErrorInfo: () => ErrorInfo,
24
24
  Updater: () => Updater,
25
25
  UpdaterError: () => UpdaterError,
26
- createUpdater: () => createUpdater,
27
- downloadBufferDefault: () => downloadBufferDefault,
28
- downloadJSONDefault: () => downloadJSONDefault,
29
26
  initApp: () => initApp,
30
- isLowerVersionDefault: () => isLowerVersionDefault,
31
27
  startupWithUpdater: () => startupWithUpdater
32
28
  });
33
- module.exports = __toCommonJS(src_exports);
29
+ module.exports = __toCommonJS(entry_exports);
34
30
  var import_node_path2 = require("path");
35
- var import_node_fs4 = require("fs");
31
+ var import_node_fs5 = require("fs");
36
32
  var import_electron4 = require("electron");
37
33
 
38
34
  // src/updater/core.ts
39
35
  var import_node_fs3 = require("fs");
40
- var import_electron3 = require("electron");
36
+ var import_node_stream = require("stream");
37
+ var import_electron2 = require("electron");
38
+
39
+ // src/utils/version.ts
40
+ function isUpdateJSON(json) {
41
+ const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
42
+ return is(json) && is(json?.beta);
43
+ }
41
44
 
42
45
  // src/utils/electron.ts
43
46
  var import_node_fs = require("fs");
44
47
  var import_node_path = require("path");
45
- var import_node_os = require("os");
46
48
  var import_electron = require("electron");
47
- var is = {
48
- dev: !import_electron.app.isPackaged,
49
- win: process.platform === "win32",
50
- mac: process.platform === "darwin",
51
- linux: process.platform === "linux"
52
- };
49
+ var isDev = __EIU_IS_DEV__;
50
+ var isWin = process.platform === "win32";
51
+ var isMac = process.platform === "darwin";
52
+ var isLinux = process.platform === "linux";
53
53
  function getPathFromAppNameAsar(...path) {
54
- return is.dev ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${import_electron.app.name}.asar`, ...path);
54
+ return isDev ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${import_electron.app.name}.asar`, ...path);
55
55
  }
56
- function getVersions() {
57
- const platform = is.win ? "Windows" : is.mac ? "MacOS" : process.platform.toUpperCase();
58
- return {
59
- appVersion: is.dev ? import_electron.app.getVersion() : (0, import_node_fs.readFileSync)(getPathFromAppNameAsar("version"), "utf-8"),
60
- entryVersion: import_electron.app.getVersion(),
61
- electronVersion: process.versions.electron,
62
- nodeVersion: process.versions.node,
63
- systemVersion: `${platform} ${(0, import_node_os.release)()}`
64
- };
56
+ function getAppVersion() {
57
+ return isDev ? getEntryVersion() : (0, import_node_fs.readFileSync)(getPathFromAppNameAsar("version"), "utf-8");
58
+ }
59
+ function getEntryVersion() {
60
+ return import_electron.app.getVersion();
65
61
  }
66
62
  function restartApp() {
67
63
  import_electron.app.relaunch();
68
64
  import_electron.app.quit();
69
65
  }
70
- function waitAppReady(timeout = 1e3) {
71
- return import_electron.app.isReady() ? Promise.resolve() : new Promise((resolve2, reject) => {
72
- const _ = setTimeout(() => {
73
- reject(new Error("app is not ready"));
74
- }, timeout);
75
- import_electron.app.whenReady().then(() => {
76
- clearTimeout(_);
77
- resolve2();
78
- });
79
- });
80
- }
81
66
 
82
- // src/utils/zip.ts
67
+ // src/utils/unzip.ts
83
68
  var import_node_fs2 = require("fs");
84
69
  var import_node_zlib = require("zlib");
85
70
  async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
@@ -87,212 +72,91 @@ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
87
72
  throw new Error(`path to zipped file not exist: ${gzipPath}`);
88
73
  }
89
74
  const compressedBuffer = (0, import_node_fs2.readFileSync)(gzipPath);
90
- return new Promise((resolve2, reject) => {
75
+ return new Promise((resolve, reject) => {
91
76
  (0, import_node_zlib.brotliDecompress)(compressedBuffer, (err, buffer) => {
92
77
  (0, import_node_fs2.rmSync)(gzipPath);
93
78
  if (err) {
94
79
  reject(err);
95
80
  }
96
81
  (0, import_node_fs2.writeFileSync)(targetFilePath, buffer);
97
- resolve2(null);
82
+ resolve();
98
83
  });
99
84
  });
100
85
  }
101
86
 
102
- // src/utils/pure.ts
103
- function parseVersion(version) {
104
- const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
105
- if (!match) {
106
- throw new TypeError(`invalid version: ${version}`);
107
- }
108
- const [major, minor, patch] = match.slice(1, 4).map(Number);
109
- const ret = {
110
- major,
111
- minor,
112
- patch,
113
- stage: "",
114
- stageVersion: -1
115
- };
116
- if (match[4]) {
117
- let [stage, _v] = match[4].split(".");
118
- ret.stage = stage;
119
- ret.stageVersion = Number(_v) || -1;
120
- }
121
- if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
122
- throw new TypeError(`invalid version: ${version}`);
123
- }
124
- return ret;
125
- }
126
- function isUpdateJSON(json) {
127
- const is2 = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
128
- return is2(json) && is2(json?.beta);
129
- }
130
-
131
- // src/crypto/dec.ts
132
- var import_node_crypto2 = require("crypto");
133
-
134
- // src/crypto/utils.ts
135
- var import_node_crypto = require("crypto");
136
- function hashString(data, length) {
137
- const hash = (0, import_node_crypto.createHash)("SHA256").update(data).digest("binary");
138
- return Buffer.from(hash).subarray(0, length);
139
- }
140
-
141
- // src/crypto/dec.ts
142
- function decrypt(encryptedText, key, iv) {
143
- const decipher = (0, import_node_crypto2.createDecipheriv)("aes-256-cbc", key, iv);
144
- let decrypted = decipher.update(encryptedText, "base64url", "utf8");
145
- decrypted += decipher.final("utf8");
146
- return decrypted;
147
- }
148
- var verify = (buffer, signature, cert) => {
149
- try {
150
- const [sig, version] = decrypt(signature, hashString(cert, 32), hashString(buffer, 16)).split("%");
151
- const result = (0, import_node_crypto2.createVerify)("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
152
- return result ? version : false;
153
- } catch (error) {
154
- return false;
155
- }
156
- };
157
-
158
- // src/crypto/enc.ts
159
- var import_node_crypto3 = require("crypto");
160
-
161
87
  // src/updater/types.ts
162
88
  var ErrorInfo = {
163
- downlaod: "Download failed",
89
+ download: "Download failed",
164
90
  validate: "Validate failed",
165
- param: "Missing params",
166
- version: "Unsatisfied version"
91
+ param: "Missing params"
167
92
  };
168
93
  var UpdaterError = class extends Error {
94
+ code;
169
95
  constructor(msg, info) {
170
- super(msg + ": " + info);
171
- }
172
- };
173
-
174
- // src/updater/defaultFunctions/download.ts
175
- var import_electron2 = require("electron");
176
- async function downlaodFn(url, headers, onResponse) {
177
- await waitAppReady();
178
- return new Promise((resolve2, reject) => {
179
- const request = import_electron2.net.request({ url, method: "GET", redirect: "follow" });
180
- Object.keys(headers).forEach((key) => request.setHeader(key, headers[key]));
181
- request.on("response", (res) => onResponse(res, resolve2, reject));
182
- request.on("error", reject);
183
- request.end();
184
- });
185
- }
186
- var downloadJSONDefault = async (url, headers) => {
187
- return await downlaodFn(url, headers, (resp, resolve2, reject) => {
188
- let data = "";
189
- resp.on("data", (chunk) => data += chunk);
190
- resp.on("end", () => {
191
- try {
192
- const json = JSON.parse(data);
193
- if (isUpdateJSON(json)) {
194
- resolve2(json);
195
- } else {
196
- throw Error;
197
- }
198
- } catch (ignore) {
199
- reject(new Error("invalid update json"));
200
- }
201
- });
202
- resp.on("aborted", () => reject(new Error("aborted")));
203
- resp.on("error", () => reject(new Error("download error")));
204
- });
205
- };
206
- var downloadBufferDefault = async (url, headers, total, onDownloading) => {
207
- let current = 0;
208
- return await downlaodFn(url, headers, (resp, resolve2, reject) => {
209
- let data = [];
210
- resp.on("data", (chunk) => {
211
- current += chunk.length;
212
- onDownloading?.({ percent: `${+(current / total).toFixed(2) * 100}%`, total, current });
213
- data.push(chunk);
214
- });
215
- resp.on("end", () => resolve2(Buffer.concat(data)));
216
- resp.on("aborted", () => reject(new Error("aborted")));
217
- resp.on("error", () => reject(new Error("download error")));
218
- });
219
- };
220
-
221
- // src/updater/defaultFunctions/compareVersion.ts
222
- var isLowerVersionDefault = (version1, version2) => {
223
- const oldV = parseVersion(version1);
224
- const newV = parseVersion(version2);
225
- function compareStrings(str1, str2) {
226
- if (str1 === "") {
227
- return str2 !== "";
228
- } else if (str2 === "") {
229
- return true;
230
- }
231
- return str1 < str2;
232
- }
233
- for (let key of Object.keys(oldV)) {
234
- if (key === "stage" && compareStrings(oldV[key], newV[key])) {
235
- return true;
236
- } else if (oldV[key] !== newV[key]) {
237
- return oldV[key] < newV[key];
238
- }
96
+ super(ErrorInfo[msg] + ": " + info);
97
+ this.code = msg;
239
98
  }
240
- return false;
241
99
  };
242
100
 
243
101
  // src/updater/core.ts
244
- var Updater = class {
245
- CERT = __SIGNATURE_CERT__;
102
+ var Updater = class extends import_node_stream.EventEmitter {
103
+ CERT = __EIU_SIGNATURE_CERT__;
246
104
  info;
247
- option;
105
+ options;
248
106
  asarPath;
249
107
  gzipPath;
250
108
  tmpFilePath;
109
+ provider;
251
110
  /**
252
111
  * updater logger
253
112
  */
254
113
  logger;
255
114
  /**
256
- * downloading progress hook
257
- * @param progress download progress
258
- * @example
259
- * updater.onDownloading = ({ percent, total, current }) => {
260
- * console.log(`download progress: ${percent}, total: ${total}, current: ${current}`)
261
- * }
115
+ * URL handler hook
116
+ *
117
+ * for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDNs}
118
+ * @param url source url
119
+ * @param isDownloadAsar whether is download asar
262
120
  */
263
- onDownloading;
121
+ handleURL;
264
122
  /**
265
123
  * whether receive beta version
266
124
  */
267
125
  get receiveBeta() {
268
- return !!this.option.receiveBeta;
126
+ return !!this.options.receiveBeta;
269
127
  }
270
128
  set receiveBeta(receiveBeta) {
271
- this.option.receiveBeta = receiveBeta;
129
+ this.options.receiveBeta = receiveBeta;
272
130
  }
273
131
  /**
274
132
  * initialize incremental updater
133
+ * @param provider update provider
275
134
  * @param option UpdaterOption
276
135
  */
277
- constructor(option = {}) {
278
- this.option = option;
136
+ constructor(provider, option = {}) {
137
+ super();
138
+ this.provider = provider;
139
+ this.options = option;
279
140
  if (option.SIGNATURE_CERT) {
280
141
  this.CERT = option.SIGNATURE_CERT;
281
142
  }
143
+ if (option.logger) {
144
+ this.logger = option.logger;
145
+ }
146
+ if (isDev && !this.logger) {
147
+ this.logger = {
148
+ info: (...args) => console.log("[EIU-INFO ]", ...args),
149
+ debug: (...args) => console.log("[EIU-DEBUG]", ...args),
150
+ warn: (...args) => console.log("[EIU-WARN ]", ...args),
151
+ error: (...args) => console.error("[EIU-ERROR]", ...args)
152
+ };
153
+ this.logger.info("no logger set, enable dev-only logger");
154
+ }
282
155
  this.asarPath = getPathFromAppNameAsar();
283
156
  this.gzipPath = `${this.asarPath}.gz`;
284
157
  this.tmpFilePath = `${this.asarPath}.tmp`;
285
158
  }
286
- async needUpdate(version, minVersion) {
287
- const isLowerVersion = this.option.overrideFunctions?.isLowerVersion ?? isLowerVersionDefault;
288
- const { appVersion, entryVersion } = getVersions();
289
- if (await isLowerVersion(entryVersion, minVersion)) {
290
- throw new UpdaterError(ErrorInfo.version, `entry version (${entryVersion}) < minimumVersion (${minVersion})`);
291
- }
292
- this.logger?.info(`check update: current version is ${appVersion}, new version is ${version}`);
293
- return await isLowerVersion(appVersion, version);
294
- }
295
- async parseData(format, data) {
159
+ async fetch(format, data) {
296
160
  if ((0, import_node_fs3.existsSync)(this.tmpFilePath)) {
297
161
  this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
298
162
  (0, import_node_fs3.rmSync)(this.tmpFilePath);
@@ -305,99 +169,96 @@ var Updater = class {
305
169
  if (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer.isBuffer(data)) {
306
170
  return data;
307
171
  } else {
308
- throw new UpdaterError(ErrorInfo.param, `invalid type at format '${format}': ${JSON.stringify(data)}`);
172
+ this.err("invalid type", "param", `invalid type at format '${format}': ${JSON.stringify(data)}`);
173
+ return;
309
174
  }
310
175
  }
311
- const ua = this.option.downloadConfig?.userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
312
- const headers = {
313
- Accept: `application/${format === "json" ? "json" : "octet-stream"}`,
314
- UserAgent: ua,
315
- ...this.option.downloadConfig?.extraHeader
316
- };
317
- this.logger?.debug(`download headers: ${JSON.stringify(headers)}`);
318
- const config = format === "json" ? {
319
- name: "updateJsonURL",
320
- url: this.option.updateJsonURL,
321
- repoFallback: `${this.option.repository?.replace("github.com", "raw.githubusercontent.com")}/master/version.json`,
322
- fn: this.option.overrideFunctions?.downloadJSON ?? downloadJSONDefault
323
- } : {
324
- name: "releaseAsarURL",
325
- url: this.option.releaseAsarURL,
326
- repoFallback: `${this.option.repository}/releases/download/v${this.info?.version}/${import_electron3.app.name}-${this.info?.version}.asar.gz`,
327
- fn: this.option.overrideFunctions?.downloadBuffer ?? downloadBufferDefault
328
- };
329
- data ??= config.url;
330
- if (!data) {
331
- this.logger?.debug(`no ${config.name}, fallback to use repository`);
332
- if (!this.option.repository) {
333
- throw new UpdaterError(ErrorInfo.param, `${config.name} or repository is not set`);
334
- }
335
- if (format === "buffer" && !this.info?.version) {
336
- throw new UpdaterError(ErrorInfo.param, "version is not set");
337
- }
338
- data = config.repoFallback;
339
- }
340
- this.logger?.debug(`download ${format} from ${data}`);
176
+ this.logger?.debug(`download from ${this.provider.name}`);
341
177
  try {
342
- const ret = format === "json" ? await config.fn(data, headers) : await config.fn(data, headers, this.info.size, this.onDownloading);
343
- this.logger?.debug(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
344
- return ret;
178
+ const result = format === "json" ? await this.provider.downloadJSON(data ?? __EIU_VERSION_PATH__) : await this.provider.downloadAsar(import_electron2.app.name, this.info, (data2) => this.emit("download-progress", data2));
179
+ this.logger?.debug(`download ${format} success${format === "buffer" ? `, file size: ${result.length}` : ""}`);
180
+ return result;
345
181
  } catch (e) {
346
- throw new UpdaterError(ErrorInfo.downlaod, e.toString());
182
+ this.err(`download ${format} failed`, "download", `download ${format} failed: ${e}`);
347
183
  }
348
184
  }
185
+ /**
186
+ * handle error message and emit error event
187
+ */
188
+ err(msg, code, errorInfo) {
189
+ const err = new UpdaterError(code, errorInfo);
190
+ this.logger?.error(msg, err);
191
+ this.emit("error", err);
192
+ }
349
193
  async checkUpdate(data) {
350
- try {
351
- let { signature, size, version, minimumVersion, beta } = await this.parseData("json", data);
352
- if (this.receiveBeta) {
353
- version = beta.version;
354
- signature = beta.signature;
355
- minimumVersion = beta.minimumVersion;
356
- size = beta.size;
357
- }
358
- this.logger?.debug(`checked version: ${version}, size: ${size}, signature: ${signature}`);
359
- if (!await this.needUpdate(version, minimumVersion)) {
360
- this.logger?.info(`update unavailable: ${version} is the latest version`);
361
- return void 0;
362
- } else {
363
- this.logger?.info(`update available: ${version}`);
364
- this.info = {
365
- signature,
366
- minimumVersion,
367
- version,
368
- size
369
- };
370
- return this.info;
371
- }
372
- } catch (error) {
373
- this.logger?.error("check update failed", error);
374
- return error;
194
+ const emitUnavailable = (msg) => {
195
+ this.logger?.info(msg);
196
+ this.emit("update-unavailable", msg);
197
+ };
198
+ const _data = await this.fetch("json", data);
199
+ if (!_data) {
200
+ emitUnavailable("failed to get update info");
201
+ return false;
375
202
  }
203
+ let { signature, size, version, minimumVersion, beta } = _data;
204
+ if (this.receiveBeta) {
205
+ version = beta.version;
206
+ signature = beta.signature;
207
+ minimumVersion = beta.minimumVersion;
208
+ size = beta.size;
209
+ }
210
+ this.logger?.debug(`checked update, version: ${version}, size: ${size}, signature: ${signature}`);
211
+ if (isDev) {
212
+ emitUnavailable("in dev mode, skip check update");
213
+ return false;
214
+ }
215
+ const isLowerVersion = this.provider.isLowerVersion;
216
+ const entryVersion = getEntryVersion();
217
+ const appVersion = getAppVersion();
218
+ if (isLowerVersion(entryVersion, minimumVersion)) {
219
+ emitUnavailable(`entry version (${entryVersion}) < minimumVersion (${minimumVersion})`);
220
+ return false;
221
+ }
222
+ this.logger?.info(`check update: current version is ${appVersion}, new version is ${version}`);
223
+ if (!isLowerVersion(appVersion, version)) {
224
+ emitUnavailable(`current version (${appVersion}) < new version (${version})`);
225
+ return false;
226
+ }
227
+ this.logger?.info(`update available: ${version}`);
228
+ this.info = { signature, minimumVersion, version, size };
229
+ this.emit("update-available", this.info);
230
+ return true;
376
231
  }
377
232
  async download(data, sig) {
233
+ if (!this.info) {
234
+ this.err("download failed", "param", "no update info, call `checkUpdate` first");
235
+ return false;
236
+ }
237
+ const _sig = sig ?? this.info.signature;
238
+ const buffer = await this.fetch("buffer", data ? Buffer.from(data) : void 0);
239
+ if (!buffer) {
240
+ this.err("download failed", "param", "no update asar file buffer");
241
+ return false;
242
+ }
243
+ this.logger?.debug("verify start");
244
+ const _ver = await this.provider.verifySignaure(buffer, _sig, this.CERT);
245
+ if (!_ver) {
246
+ this.err("verify failed", "validate", "invalid signature / certificate pair");
247
+ return false;
248
+ }
249
+ this.logger?.debug("verify success");
378
250
  try {
379
- const _sig = sig ?? this.info?.signature;
380
- if (!_sig) {
381
- throw new UpdaterError(ErrorInfo.param, "signature is empty");
382
- }
383
- const buffer = await this.parseData("buffer", data);
384
- this.logger?.debug("verify start");
385
- const _verify = this.option.overrideFunctions?.verifySignaure ?? verify;
386
- const _ver = await _verify(buffer, _sig, this.CERT);
387
- if (!_ver) {
388
- throw new UpdaterError(ErrorInfo.validate, "invalid signature or certificate");
389
- }
390
- this.logger?.debug("verify success");
391
251
  this.logger?.debug(`write to ${this.gzipPath}`);
392
252
  (0, import_node_fs3.writeFileSync)(this.gzipPath, buffer);
393
253
  this.logger?.debug(`extract to ${this.tmpFilePath}`);
394
254
  await unzipFile(this.gzipPath, this.tmpFilePath);
395
255
  this.logger?.info(`download success, version: ${_ver}`);
396
256
  this.info = void 0;
257
+ this.emit("update-downloaded");
397
258
  return true;
398
259
  } catch (error) {
399
- this.logger?.error("download asar failed", error);
400
- return error;
260
+ this.err("unwrap asar failed", "download", `fail to unwrap asar file, ${error}`);
261
+ return false;
401
262
  }
402
263
  }
403
264
  /**
@@ -409,56 +270,60 @@ var Updater = class {
409
270
  }
410
271
  };
411
272
 
412
- // src/updater/index.ts
413
- function createUpdater(option) {
414
- return new Updater(option);
415
- }
273
+ // src/utils/zip.ts
274
+ var import_node_fs4 = require("fs");
275
+ var import_node_zlib2 = require("zlib");
276
+
277
+ // src/utils/crypto/decrypt.ts
278
+ var import_node_crypto2 = require("crypto");
416
279
 
417
- // src/index.ts
280
+ // src/utils/crypto/utils.ts
281
+ var import_node_crypto = require("crypto");
282
+
283
+ // src/utils/crypto/encrypt.ts
284
+ var import_node_crypto3 = require("crypto");
285
+
286
+ // src/entry.ts
418
287
  function startupWithUpdater(fn) {
419
288
  return fn;
420
289
  }
421
290
  var defaultOnInstall = (install, _, __, logger) => {
422
291
  install();
423
- logger?.info(`update success!`);
292
+ logger.info(`update success!`);
424
293
  };
425
- async function initApp(appOptions = {}) {
294
+ async function initApp(appOptions) {
426
295
  const {
296
+ provider,
427
297
  updater,
428
- electronDevDistPath = "../dist-electron",
429
- mainPath = "main/index.js",
430
- hooks
431
- } = appOptions || {};
432
- const {
433
298
  onInstall = defaultOnInstall,
434
299
  beforeStart,
435
300
  onStartError
436
- } = hooks || {};
437
- function handleError(err, logger2) {
438
- console.error(err);
439
- onStartError?.(err, logger2);
440
- import_electron4.app.quit();
441
- }
301
+ } = appOptions;
442
302
  let updaterInstance;
443
303
  if (typeof updater === "object" || !updater) {
444
- updaterInstance = createUpdater(updater);
304
+ updaterInstance = new Updater(provider, updater);
445
305
  } else {
446
306
  updaterInstance = await updater();
447
307
  }
448
- const logger = updaterInstance.logger;
308
+ const logger = updaterInstance.logger || console;
449
309
  try {
450
310
  const appNameAsarPath = getPathFromAppNameAsar();
451
311
  const tempAsarPath = `${appNameAsarPath}.tmp`;
452
- if ((0, import_node_fs4.existsSync)(tempAsarPath)) {
453
- logger?.info(`installing new asar: ${tempAsarPath}`);
454
- await onInstall(() => (0, import_node_fs4.renameSync)(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
312
+ if ((0, import_node_fs5.existsSync)(tempAsarPath)) {
313
+ logger.info(`installing new asar: ${tempAsarPath}`);
314
+ await onInstall(() => (0, import_node_fs5.renameSync)(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
455
315
  }
456
- const mainDir = is.dev ? electronDevDistPath : appNameAsarPath;
457
- const entry = (0, import_node_path2.resolve)(__dirname, mainDir, mainPath);
458
- await beforeStart?.(entry, logger);
459
- require(entry)(updaterInstance);
316
+ const mainFilePath = (0, import_node_path2.join)(
317
+ isDev ? (0, import_node_path2.join)(import_electron4.app.getAppPath(), __EIU_MAIN_DEV_DIR__) : appNameAsarPath,
318
+ "main",
319
+ __EIU_MAIN_FILE__
320
+ );
321
+ await beforeStart?.(mainFilePath, logger);
322
+ require(mainFilePath)(updaterInstance);
460
323
  } catch (error) {
461
- handleError(error, logger);
324
+ logger.error("startup error", error);
325
+ onStartError?.(error, logger);
326
+ import_electron4.app.quit();
462
327
  }
463
328
  }
464
329
  // Annotate the CommonJS export names for ESM import in node:
@@ -466,10 +331,6 @@ async function initApp(appOptions = {}) {
466
331
  ErrorInfo,
467
332
  Updater,
468
333
  UpdaterError,
469
- createUpdater,
470
- downloadBufferDefault,
471
- downloadJSONDefault,
472
334
  initApp,
473
- isLowerVersionDefault,
474
335
  startupWithUpdater
475
336
  });