electron-incremental-update 3.0.0-beta.4 → 3.0.0-beta.6

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,346 @@
1
+ const require_zip = require("./zip-D1dbBzw4.cjs");
2
+ let node_fs = require("node:fs");
3
+ node_fs = require_zip.__toESM(node_fs, 1);
4
+ let node_path = require("node:path");
5
+ node_path = require_zip.__toESM(node_path, 1);
6
+ let electron = require("electron");
7
+ let node_url = require("node:url");
8
+ //#region src/utils/devtools/font.css?inline
9
+ var font_default = ":root,body{--source-code-font-family:var(--mono)!important;--source-code-font-size:12px!important;--monospace-font-family:var(--mono)!important;--monospace-font-size:12px!important;--default-font-family:var(--sans), sans-serif!important;--default-font-size:12px!important}button,input,select,.undisplayable-text,.expandable-inline-button{font-family:var(--sans)!important}\n";
10
+ //#endregion
11
+ //#region src/utils/devtools/js.ts?inject
12
+ var js_default = "export { };";
13
+ //#endregion
14
+ //#region src/utils/devtools/scrollbar.css?inline
15
+ var scrollbar_default = ":root{--scrollbar-width:max(.85vw, 10px)}@media (prefers-color-scheme:light){:root{--scrollbar-color-rgb:0, 0, 0}}@media (prefers-color-scheme:dark){:root{--scrollbar-color-rgb:255, 255, 255}}::-webkit-scrollbar{width:var(--scrollbar-width)!important;height:var(--scrollbar-width)!important}::-webkit-scrollbar-track{border-radius:var(--scrollbar-width)!important;box-shadow:none!important;background-color:#0000!important}::-webkit-scrollbar-thumb{background-clip:content-box;box-shadow:inset 0 0 0 var(--scrollbar-width)!important;border-radius:var(--scrollbar-width)!important;border:calc(var(--scrollbar-width) * 2 / 9) solid transparent!important;color:rgba(var(--scrollbar-color-rgb), 30%)!important;background-color:#0000!important}::-webkit-scrollbar-thumb:hover{color:rgba(var(--scrollbar-color-rgb), 45%)!important}::-webkit-scrollbar-thumb:active{color:rgba(var(--scrollbar-color-rgb), 60%)!important}@supports not selector(::-webkit-scrollbar){html{scrollbar-color:rgb(var(--scrollbar-color-rgb));scrollbar-width:thin}}\n";
16
+ //#endregion
17
+ //#region src/utils/electron.ts
18
+ /**
19
+ * Compile time dev check
20
+ */
21
+ const isDev = __EIU_IS_DEV__;
22
+ const isWin = process.platform === "win32";
23
+ const isMac = process.platform === "darwin";
24
+ const isLinux = process.platform === "linux";
25
+ /**
26
+ * Get joined path of `${electron.app.name}.asar` (not `app.asar`)
27
+ *
28
+ * If is in dev, **always** return `'DEV.asar'`
29
+ */
30
+ function getPathFromAppNameAsar(...paths) {
31
+ return isDev ? node_path.default.join(__EIU_LOCAL_DEV_UPDATE_ASAR_PATH__ || "DEV.asar", ...paths) : node_path.default.join(node_path.default.dirname(electron.app.getAppPath()), `${electron.app.name}.asar`, ...paths);
32
+ }
33
+ /**
34
+ * Get app version, if is in dev, return `getEntryVersion()`
35
+ */
36
+ function getAppVersion() {
37
+ if (!isDev) return node_fs.default.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
38
+ if (!__EIU_LOCAL_DEV_UPDATE__) return getEntryVersion();
39
+ try {
40
+ return node_fs.default.readFileSync(getPathFromAppNameAsar("version"), "utf-8").trim();
41
+ } catch {
42
+ return getEntryVersion();
43
+ }
44
+ }
45
+ /**
46
+ * Get entry version
47
+ */
48
+ function getEntryVersion() {
49
+ return electron.app.getVersion();
50
+ }
51
+ /**
52
+ * Use `require` to load native module from entry asar
53
+ * @param moduleName file name in entry
54
+ * @example
55
+ * requireNative<typeof import('../native/db')>('db')
56
+ */
57
+ function requireNative(moduleName) {
58
+ const m = getPathFromEntryAsar(moduleName);
59
+ if (__EIU_IS_ESM__) throw new Error(`Cannot require "${m}", \`requireNative\` only supports CommonJS. Use \`importNative\` instead`);
60
+ return require(m);
61
+ }
62
+ /**
63
+ * Use `import` to load native module from entry asar
64
+ * @param moduleName file name in entry
65
+ * @example
66
+ * await importNative<typeof import('../native/db')>('db')
67
+ */
68
+ async function importNative(moduleName) {
69
+ const m = getPathFromEntryAsar(moduleName);
70
+ if (!__EIU_IS_ESM__) throw new Error(`Cannot import "${m}", \`importNative\` only supports ESModule. Use \`requireNative\` instead`);
71
+ return await import((0, node_url.pathToFileURL)(node_path.default.extname(m) ? m : `${m}.mjs`).href);
72
+ }
73
+ /**
74
+ * Restarts the Electron app.
75
+ */
76
+ function restartApp() {
77
+ if (isDev && __EIU_LOCAL_DEV_UPDATE__ && process.send) {
78
+ const forceExit = setTimeout(() => electron.app.exit(0), 5e3);
79
+ process.once("message", (message) => {
80
+ if (message === "eiu:restart-ready") {
81
+ clearTimeout(forceExit);
82
+ electron.app.exit(0);
83
+ }
84
+ });
85
+ process.send("eiu:restart");
86
+ return;
87
+ }
88
+ electron.app.relaunch();
89
+ electron.app.quit();
90
+ }
91
+ /**
92
+ * Fix app use model id, only for Windows
93
+ * @param id app id, default is `org.${electron.app.name}`
94
+ */
95
+ function setAppUserModelId(id) {
96
+ if (isWin) electron.app.setAppUserModelId(id ?? `org.${electron.app.name}`);
97
+ }
98
+ /**
99
+ * Disable hardware acceleration for Windows 7
100
+ *
101
+ * Only support CommonJS
102
+ */
103
+ function disableHWAccForWin7() {
104
+ if (!__EIU_IS_ESM__ && require("node:os").release().startsWith("6.1")) electron.app.disableHardwareAcceleration();
105
+ }
106
+ /**
107
+ * Keep single electron instance and auto restore window on `second-instance` event
108
+ * @param window brwoser window to show
109
+ */
110
+ function singleInstance(window) {
111
+ electron.app.on("second-instance", () => {
112
+ if (window) {
113
+ window.show();
114
+ if (window.isMinimized()) window.restore();
115
+ window.focus();
116
+ }
117
+ });
118
+ }
119
+ /**
120
+ * Set `userData` dir to the dir of .exe file
121
+ *
122
+ * Useful for portable Windows app
123
+ * @param dirName dir name, default to `data`
124
+ * @param create whether to create dir, default to `true`
125
+ */
126
+ function setPortableDataPath(dirName = "data", create = true) {
127
+ if (electron.app.isReady()) throw new Error("Portable app data dir must be setup before app is ready");
128
+ const portableDir = node_path.default.join(node_path.default.dirname(electron.app.getPath("exe")), dirName);
129
+ if (create) {
130
+ if (!node_fs.default.existsSync(portableDir)) node_fs.default.mkdirSync(portableDir);
131
+ else if (!node_fs.default.statSync(portableDir).isDirectory()) {
132
+ node_fs.default.rmSync(portableDir);
133
+ node_fs.default.mkdirSync(portableDir);
134
+ }
135
+ } else if (!node_fs.default.existsSync(portableDir)) throw new Error("Portable app data dir does not exists");
136
+ electron.app.setPath("userData", portableDir);
137
+ }
138
+ /**
139
+ * @deprecated Use {@link setPortableDataPath} instead
140
+ */
141
+ const setPortableAppDataPath = setPortableDataPath;
142
+ /**
143
+ * Load `process.env.VITE_DEV_SERVER_URL` when dev, else load html file
144
+ * @param win window
145
+ * @param htmlFilePath html file path, default is `index.html`
146
+ */
147
+ function loadPage(win, htmlFilePath = "index.html") {
148
+ if (isDev) win.loadURL(process.env.VITE_DEV_SERVER_URL + htmlFilePath);
149
+ else win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
150
+ }
151
+ /**
152
+ * Beautify devtools' font and scrollbar
153
+ * @param win target window
154
+ * @param options sans font family, mono font family and scrollbar
155
+ * @see https://github.com/electron/electron/issues/42055
156
+ */
157
+ function beautifyDevTools(win, options) {
158
+ const { mono, sans, scrollbar = true } = options;
159
+ win.webContents.on("devtools-opened", async () => {
160
+ let css = `:root{--sans:${sans};--mono:${mono}}${font_default}`;
161
+ if (scrollbar) css += scrollbar_default;
162
+ const js = `const __CSS__=\`${css}\`;${js_default}`;
163
+ await win?.webContents.devToolsWebContents?.executeJavaScript(js).catch((e) => console.log(`Failed to execute js: ${js}.\n`, e));
164
+ });
165
+ }
166
+ /**
167
+ * Get joined path from main dir
168
+ * @param paths rest paths
169
+ */
170
+ function getPathFromMain(...paths) {
171
+ return isDev ? node_path.default.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "main", ...paths) : getPathFromAppNameAsar("main", ...paths);
172
+ }
173
+ /**
174
+ * Get joined path from preload dir
175
+ * @param paths rest paths
176
+ */
177
+ function getPathFromPreload(...paths) {
178
+ return isDev ? node_path.default.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
179
+ }
180
+ /**
181
+ * Get joined path from publich dir
182
+ * @param paths rest paths
183
+ */
184
+ function getPathFromPublic(...paths) {
185
+ return isDev ? node_path.default.join(electron.app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
186
+ }
187
+ /**
188
+ * Get joined path from entry asar
189
+ * @param paths rest paths
190
+ */
191
+ function getPathFromEntryAsar(...paths) {
192
+ return node_path.default.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
193
+ }
194
+ /**
195
+ * Handle all unhandled error
196
+ * @param callback callback function
197
+ */
198
+ function handleUnexpectedErrors(callback) {
199
+ process.on("uncaughtException", callback);
200
+ process.on("unhandledRejection", callback);
201
+ }
202
+ /**
203
+ * @deprecated No longer needed. It is embeded in `startupWithUpdater()`
204
+ */
205
+ function reloadOnPreloadScriptChanged() {
206
+ console.warn("`reloadOnPreloadScriptChange()` is no longer needed. It is embeded in `startupWithUpdater()`");
207
+ }
208
+ //#endregion
209
+ Object.defineProperty(exports, "beautifyDevTools", {
210
+ enumerable: true,
211
+ get: function() {
212
+ return beautifyDevTools;
213
+ }
214
+ });
215
+ Object.defineProperty(exports, "disableHWAccForWin7", {
216
+ enumerable: true,
217
+ get: function() {
218
+ return disableHWAccForWin7;
219
+ }
220
+ });
221
+ Object.defineProperty(exports, "getAppVersion", {
222
+ enumerable: true,
223
+ get: function() {
224
+ return getAppVersion;
225
+ }
226
+ });
227
+ Object.defineProperty(exports, "getEntryVersion", {
228
+ enumerable: true,
229
+ get: function() {
230
+ return getEntryVersion;
231
+ }
232
+ });
233
+ Object.defineProperty(exports, "getPathFromAppNameAsar", {
234
+ enumerable: true,
235
+ get: function() {
236
+ return getPathFromAppNameAsar;
237
+ }
238
+ });
239
+ Object.defineProperty(exports, "getPathFromEntryAsar", {
240
+ enumerable: true,
241
+ get: function() {
242
+ return getPathFromEntryAsar;
243
+ }
244
+ });
245
+ Object.defineProperty(exports, "getPathFromMain", {
246
+ enumerable: true,
247
+ get: function() {
248
+ return getPathFromMain;
249
+ }
250
+ });
251
+ Object.defineProperty(exports, "getPathFromPreload", {
252
+ enumerable: true,
253
+ get: function() {
254
+ return getPathFromPreload;
255
+ }
256
+ });
257
+ Object.defineProperty(exports, "getPathFromPublic", {
258
+ enumerable: true,
259
+ get: function() {
260
+ return getPathFromPublic;
261
+ }
262
+ });
263
+ Object.defineProperty(exports, "handleUnexpectedErrors", {
264
+ enumerable: true,
265
+ get: function() {
266
+ return handleUnexpectedErrors;
267
+ }
268
+ });
269
+ Object.defineProperty(exports, "importNative", {
270
+ enumerable: true,
271
+ get: function() {
272
+ return importNative;
273
+ }
274
+ });
275
+ Object.defineProperty(exports, "isDev", {
276
+ enumerable: true,
277
+ get: function() {
278
+ return isDev;
279
+ }
280
+ });
281
+ Object.defineProperty(exports, "isLinux", {
282
+ enumerable: true,
283
+ get: function() {
284
+ return isLinux;
285
+ }
286
+ });
287
+ Object.defineProperty(exports, "isMac", {
288
+ enumerable: true,
289
+ get: function() {
290
+ return isMac;
291
+ }
292
+ });
293
+ Object.defineProperty(exports, "isWin", {
294
+ enumerable: true,
295
+ get: function() {
296
+ return isWin;
297
+ }
298
+ });
299
+ Object.defineProperty(exports, "loadPage", {
300
+ enumerable: true,
301
+ get: function() {
302
+ return loadPage;
303
+ }
304
+ });
305
+ Object.defineProperty(exports, "reloadOnPreloadScriptChanged", {
306
+ enumerable: true,
307
+ get: function() {
308
+ return reloadOnPreloadScriptChanged;
309
+ }
310
+ });
311
+ Object.defineProperty(exports, "requireNative", {
312
+ enumerable: true,
313
+ get: function() {
314
+ return requireNative;
315
+ }
316
+ });
317
+ Object.defineProperty(exports, "restartApp", {
318
+ enumerable: true,
319
+ get: function() {
320
+ return restartApp;
321
+ }
322
+ });
323
+ Object.defineProperty(exports, "setAppUserModelId", {
324
+ enumerable: true,
325
+ get: function() {
326
+ return setAppUserModelId;
327
+ }
328
+ });
329
+ Object.defineProperty(exports, "setPortableAppDataPath", {
330
+ enumerable: true,
331
+ get: function() {
332
+ return setPortableAppDataPath;
333
+ }
334
+ });
335
+ Object.defineProperty(exports, "setPortableDataPath", {
336
+ enumerable: true,
337
+ get: function() {
338
+ return setPortableDataPath;
339
+ }
340
+ });
341
+ Object.defineProperty(exports, "singleInstance", {
342
+ enumerable: true,
343
+ get: function() {
344
+ return singleInstance;
345
+ }
346
+ });
package/dist/index.cjs CHANGED
@@ -1,12 +1,13 @@
1
- const require_version = require('./version-aPrLuz_-.cjs');
2
- const require_electron = require('./electron-C-qmVhAt.cjs');
3
- let electron = require("electron");
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_zip = require("./zip-D1dbBzw4.cjs");
3
+ const require_local = require("./local-Daf8naRn.cjs");
4
+ const require_electron = require("./electron-D_8AbLQ5.cjs");
4
5
  let node_fs = require("node:fs");
5
- node_fs = require_version.__toESM(node_fs);
6
+ node_fs = require_zip.__toESM(node_fs, 1);
6
7
  let node_path = require("node:path");
7
- node_path = require_version.__toESM(node_path);
8
+ node_path = require_zip.__toESM(node_path, 1);
9
+ let electron = require("electron");
8
10
  let node_events = require("node:events");
9
-
10
11
  //#region src/entry/types.ts
11
12
  var UpdaterError = class extends Error {
12
13
  code;
@@ -15,12 +16,12 @@ var UpdaterError = class extends Error {
15
16
  this.code = code;
16
17
  }
17
18
  };
18
-
19
19
  //#endregion
20
20
  //#region src/entry/updater.ts
21
21
  var Updater = class extends node_events.EventEmitter {
22
22
  CERT;
23
23
  controller;
24
+ getCurrentAppVersion;
24
25
  info;
25
26
  tmpFilePath;
26
27
  processing = false;
@@ -47,6 +48,7 @@ var Updater = class extends node_events.EventEmitter {
47
48
  this.receiveBeta = options.receiveBeta;
48
49
  this.CERT = options.SIGNATURE_CERT || __EIU_SIGNATURE_CERT__;
49
50
  this.logger = options.logger;
51
+ this.getCurrentAppVersion = options.getAppVersion ?? require_electron.getAppVersion;
50
52
  this.controller = new AbortController();
51
53
  if (require_electron.isDev && !this.logger) {
52
54
  this.logger = {
@@ -57,10 +59,9 @@ var Updater = class extends node_events.EventEmitter {
57
59
  };
58
60
  this.logger.info("No logger set, enable dev-only logger");
59
61
  }
60
- if (!this.provider) this.logger?.debug("WARN: No update provider");
61
62
  }
62
63
  async fetch(format, data) {
63
- if (typeof data === "object") if (format === "json" && require_version.isUpdateJSON(data) || format === "buffer" && Buffer.isBuffer(data)) return data;
64
+ if (typeof data === "object") if (format === "json" && require_zip.isUpdateJSON(data) || format === "buffer" && Buffer.isBuffer(data)) return data;
64
65
  else {
65
66
  this.err("Invalid type", "ERR_PARAM", `Invalid type at format '${format}': ${JSON.stringify(data)}`);
66
67
  return;
@@ -90,9 +91,12 @@ var Updater = class extends node_events.EventEmitter {
90
91
  const err = new UpdaterError(code, errorInfo);
91
92
  this.logger?.error(`[${code}] ${msg}`, err);
92
93
  this.cleanup();
93
- this.emit("error", err);
94
+ if (this.listenerCount("error") > 0) this.emit("error", err);
94
95
  }
95
- async checkForUpdates(data) {
96
+ /**
97
+ * Check update info using default options
98
+ */
99
+ async checkForUpdates() {
96
100
  const emitUnavailable = (msg, code, info) => {
97
101
  this.logger?.info(`[${code}] ${msg}`);
98
102
  this.logger?.debug("Check update end");
@@ -100,18 +104,18 @@ var Updater = class extends node_events.EventEmitter {
100
104
  this.emit("update-not-available", code, msg, info);
101
105
  return false;
102
106
  };
107
+ if (!this.provider) {
108
+ const msg = "No update json or provider";
109
+ this.err("Check update failed", "ERR_PARAM", msg);
110
+ return emitUnavailable(msg, "UNAVAILABLE_ERROR");
111
+ }
103
112
  if (this.processing) {
104
113
  this.logger?.info("Updater is already processing, skip check update");
105
114
  return false;
106
115
  }
107
116
  this.processing = true;
108
117
  this.logger?.debug("Check update start");
109
- if (!data && !this.provider) {
110
- const msg = "No update json or provider";
111
- this.err("Check update failed", "ERR_PARAM", msg);
112
- return emitUnavailable(msg, "UNAVAILABLE_ERROR");
113
- }
114
- const _data = await this.fetch("json", data);
118
+ const _data = await this.fetch("json");
115
119
  if (!_data) return emitUnavailable("Failed to get update info", "UNAVAILABLE_ERROR");
116
120
  const { signature, version, minimumVersion, url, ...rest } = this.receiveBeta ? _data.beta : _data;
117
121
  const info = {
@@ -124,12 +128,12 @@ var Updater = class extends node_events.EventEmitter {
124
128
  signature,
125
129
  minimumVersion,
126
130
  version,
127
- appVersion: require_electron.getAppVersion(),
131
+ appVersion: this.getCurrentAppVersion(),
128
132
  entryVersion: require_electron.getEntryVersion(),
129
133
  ...rest
130
134
  };
131
135
  this.logger?.debug(`Checked update, version: ${version}, signature: ${signature}`);
132
- if (require_electron.isDev && !this.forceUpdate && !data) return emitUnavailable("Skip check update in dev mode. To force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON", "UNAVAILABLE_DEV");
136
+ if (require_electron.isDev && !this.forceUpdate) return emitUnavailable("Skip check update in dev mode. To force update, set `updater.forceUpdate` to `true`", "UNAVAILABLE_DEV");
133
137
  const isLowerVersion = this.provider.isLowerVersion;
134
138
  try {
135
139
  if (isLowerVersion(extraVersionInfo.entryVersion, minimumVersion)) return emitUnavailable(`Entry Version (${extraVersionInfo.entryVersion}) < MinimumVersion (${minimumVersion})`, "UNAVAILABLE_VERSION", extraVersionInfo);
@@ -147,25 +151,32 @@ var Updater = class extends node_events.EventEmitter {
147
151
  return emitUnavailable(msg, "UNAVAILABLE_ERROR", extraVersionInfo);
148
152
  }
149
153
  }
150
- async downloadUpdate(data, info) {
154
+ /**
155
+ * Download update using default options
156
+ */
157
+ async downloadUpdate() {
151
158
  const emitError = (code, errorInfo) => {
152
159
  this.err(`Download update failed`, code, errorInfo);
153
160
  this.logger?.debug("Download update end");
154
161
  this.processing = false;
155
162
  return false;
156
163
  };
164
+ if (!this.provider) return emitError("ERR_PARAM", "No update asar buffer and provider");
157
165
  if (this.processing) {
158
166
  this.logger?.info("Updater is already processing, skip download update");
159
167
  return false;
160
168
  }
161
169
  this.processing = true;
162
170
  this.logger?.debug("Download update start");
163
- const _sig = info?.signature ?? this.info?.signature;
164
- const _version = info?.version ?? this.info?.version;
165
- if (!_sig || !_version) return emitError("ERR_PARAM", "No update signature, please call `checkUpdate` first or manually setup params");
166
- if (!data && !this.provider) return emitError("ERR_PARAM", "No update asar buffer and provider");
167
- const buffer = await this.fetch("buffer", data ? Buffer.from(data) : void 0);
168
- if (!buffer) return emitError("ERR_PARAM", "No update asar file buffer");
171
+ const _sig = this.info?.signature;
172
+ const _version = this.info?.version;
173
+ if (!_sig || !_version) return emitError("ERR_PARAM", "No update signature, please call `checkUpdate` first");
174
+ const buffer = await this.fetch("buffer");
175
+ if (!buffer) {
176
+ this.logger?.debug("Download update end");
177
+ this.processing = false;
178
+ return false;
179
+ }
169
180
  this.logger?.debug("Validation start");
170
181
  if (!await this.provider.verifySignaure(buffer, _version, _sig, this.CERT)) return emitError("ERR_VALIDATE", "Invalid update asar file");
171
182
  this.logger?.debug("Validation end");
@@ -206,7 +217,6 @@ var Updater = class extends node_events.EventEmitter {
206
217
  async function autoUpdate(updater) {
207
218
  if (await updater.checkForUpdates() && await updater.downloadUpdate()) updater.quitAndInstall();
208
219
  }
209
-
210
220
  //#endregion
211
221
  //#region src/entry/core.ts
212
222
  /**
@@ -231,6 +241,25 @@ const defaultOnInstall = (install, _, __, logger) => {
231
241
  install();
232
242
  logger?.info(`update success!`);
233
243
  };
244
+ function readDevAsarVersion() {
245
+ try {
246
+ return node_fs.default.readFileSync(require_electron.getPathFromAppNameAsar("version"), "utf-8").trim();
247
+ } catch {
248
+ return electron.app.getVersion();
249
+ }
250
+ }
251
+ function resolveUpdaterOption(updater) {
252
+ if (!require_electron.isDev || !__EIU_LOCAL_DEV_UPDATE__ || updater?.provider) return updater;
253
+ return {
254
+ ...updater,
255
+ provider: new require_local.LocalDevProvider({
256
+ baseDir: __EIU_LOCAL_DEV_UPDATE_DIR__,
257
+ chunkDelay: __EIU_LOCAL_DEV_UPDATE_CHUNK_DELAY__,
258
+ chunkSize: __EIU_LOCAL_DEV_UPDATE_CHUNK_SIZE__
259
+ }),
260
+ getAppVersion: updater?.getAppVersion ?? readDevAsarVersion
261
+ };
262
+ }
234
263
  /**
235
264
  * Initialize Electron with updater
236
265
  * @example
@@ -249,7 +278,9 @@ const defaultOnInstall = (install, _, __, logger) => {
249
278
  async function createElectronApp(appOptions = {}) {
250
279
  const appNameAsarPath = require_electron.getPathFromAppNameAsar();
251
280
  const { mainPath = require_electron.isDev ? node_path.default.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "main", __EIU_MAIN_FILE__) : node_path.default.join(node_path.default.dirname(electron.app.getAppPath()), __EIU_ASAR_BASE_NAME__, "main", __EIU_MAIN_FILE__), updater, onInstall = defaultOnInstall, beforeStart, onStartError } = appOptions;
252
- const updaterInstance = typeof updater === "object" || !updater ? new Updater(updater) : await updater();
281
+ const useAutoLocalDevProvider = require_electron.isDev && __EIU_LOCAL_DEV_UPDATE__ && typeof updater !== "function";
282
+ const updaterInstance = typeof updater === "object" || !updater ? new Updater(resolveUpdaterOption(updater)) : await updater();
283
+ if (useAutoLocalDevProvider && updaterInstance.provider?.name === "LocalDevProvider") updaterInstance.forceUpdate = true;
253
284
  const logger = updaterInstance.logger;
254
285
  try {
255
286
  const tempAsarPath = `${appNameAsarPath}.tmp`;
@@ -258,8 +289,10 @@ async function createElectronApp(appOptions = {}) {
258
289
  await onInstall(() => node_fs.default.renameSync(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
259
290
  }
260
291
  await beforeStart?.(mainPath, logger);
261
- if (__EIU_IS_ESM__) runWithDefaultExport(await import(`file://${mainPath}`), updaterInstance);
262
- else runWithDefaultExport(require(mainPath), updaterInstance);
292
+ if (__EIU_IS_ESM__) {
293
+ const { pathToFileURL } = await import("node:url");
294
+ runWithDefaultExport(await import(pathToFileURL(mainPath).href), updaterInstance);
295
+ } else runWithDefaultExport(require(mainPath), updaterInstance);
263
296
  } catch (error) {
264
297
  logger?.error("Fail to startup", error);
265
298
  onStartError?.(error, logger);
@@ -270,11 +303,10 @@ async function createElectronApp(appOptions = {}) {
270
303
  * @deprecated Use {@link createElectronApp} instead
271
304
  */
272
305
  const initApp = createElectronApp;
273
-
274
306
  //#endregion
275
307
  exports.Updater = Updater;
276
308
  exports.UpdaterError = UpdaterError;
277
309
  exports.autoUpdate = autoUpdate;
278
310
  exports.createElectronApp = createElectronApp;
279
311
  exports.initApp = initApp;
280
- exports.startupWithUpdater = startupWithUpdater;
312
+ exports.startupWithUpdater = startupWithUpdater;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as UpdateJSONWithURL, m as Promisable, n as IProvider, o as UpdateInfo, s as UpdateJSON, t as DownloadingInfo } from "./types-BM9Jfu7q.cjs";
1
+ import { m as Promisable, n as IProvider, o as UpdateInfo, t as DownloadingInfo } from "./types-BOqQ_r5Q.cjs";
2
2
  import { EventEmitter } from "node:events";
3
3
 
4
4
  //#region src/entry/types.d.ts
@@ -34,6 +34,13 @@ interface UpdaterOption {
34
34
  * Updater logger
35
35
  */
36
36
  logger?: Logger;
37
+ /**
38
+ * Override current app version source.
39
+ *
40
+ * This is mainly used by dev tooling where the installed asar version differs
41
+ * from Electron's package version.
42
+ */
43
+ getAppVersion?: () => string;
37
44
  }
38
45
  /**
39
46
  * Update info with current app version and entry version
@@ -60,6 +67,7 @@ declare class Updater<T extends UpdateInfoWithExtraVersion = UpdateInfoWithExtra
60
67
  }> {
61
68
  private CERT;
62
69
  private controller;
70
+ private getCurrentAppVersion;
63
71
  private info?;
64
72
  private tmpFilePath?;
65
73
  private processing;
@@ -107,21 +115,10 @@ declare class Updater<T extends UpdateInfoWithExtraVersion = UpdateInfoWithExtra
107
115
  */
108
116
  checkForUpdates(): Promise<boolean>;
109
117
  /**
110
- * Check update info using existing update json
111
- * @param data existing update json
112
- */
113
- checkForUpdates(data: UpdateJSON | UpdateJSONWithURL): Promise<boolean>;
114
- /**
115
118
  * Download update using default options
116
119
  */
117
120
  downloadUpdate(): Promise<boolean>;
118
121
  /**
119
- * Download update using existing `asar.gz` buffer and signature
120
- * @param data existing `asar.gz` buffer
121
- * @param info update info
122
- */
123
- downloadUpdate(data: Uint8Array, info: Omit<UpdateInfo, "minimumVersion">): Promise<boolean>;
124
- /**
125
122
  * quit App and install
126
123
  */
127
124
  quitAndInstall(): void;
@@ -141,7 +138,7 @@ declare function autoUpdate(updater: Updater): Promise<void>;
141
138
  * @param logger logger
142
139
  * @default install(); logger.info('update success!')
143
140
  */
144
- type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
141
+ type OnInstallFunction = (install: () => void, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
145
142
  interface AppOption {
146
143
  /**
147
144
  * Path to index file that make {@link startupWithUpdater} as default export
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as UpdateJSONWithURL, m as Promisable, n as IProvider, o as UpdateInfo, s as UpdateJSON, t as DownloadingInfo } from "./types-DASqEPXE.mjs";
1
+ import { m as Promisable, n as IProvider, o as UpdateInfo, t as DownloadingInfo } from "./types-BOqQ_r5Q.mjs";
2
2
  import { EventEmitter } from "node:events";
3
3
 
4
4
  //#region src/entry/types.d.ts
@@ -34,6 +34,13 @@ interface UpdaterOption {
34
34
  * Updater logger
35
35
  */
36
36
  logger?: Logger;
37
+ /**
38
+ * Override current app version source.
39
+ *
40
+ * This is mainly used by dev tooling where the installed asar version differs
41
+ * from Electron's package version.
42
+ */
43
+ getAppVersion?: () => string;
37
44
  }
38
45
  /**
39
46
  * Update info with current app version and entry version
@@ -60,6 +67,7 @@ declare class Updater<T extends UpdateInfoWithExtraVersion = UpdateInfoWithExtra
60
67
  }> {
61
68
  private CERT;
62
69
  private controller;
70
+ private getCurrentAppVersion;
63
71
  private info?;
64
72
  private tmpFilePath?;
65
73
  private processing;
@@ -107,21 +115,10 @@ declare class Updater<T extends UpdateInfoWithExtraVersion = UpdateInfoWithExtra
107
115
  */
108
116
  checkForUpdates(): Promise<boolean>;
109
117
  /**
110
- * Check update info using existing update json
111
- * @param data existing update json
112
- */
113
- checkForUpdates(data: UpdateJSON | UpdateJSONWithURL): Promise<boolean>;
114
- /**
115
118
  * Download update using default options
116
119
  */
117
120
  downloadUpdate(): Promise<boolean>;
118
121
  /**
119
- * Download update using existing `asar.gz` buffer and signature
120
- * @param data existing `asar.gz` buffer
121
- * @param info update info
122
- */
123
- downloadUpdate(data: Uint8Array, info: Omit<UpdateInfo, "minimumVersion">): Promise<boolean>;
124
- /**
125
122
  * quit App and install
126
123
  */
127
124
  quitAndInstall(): void;
@@ -141,7 +138,7 @@ declare function autoUpdate(updater: Updater): Promise<void>;
141
138
  * @param logger logger
142
139
  * @default install(); logger.info('update success!')
143
140
  */
144
- type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
141
+ type OnInstallFunction = (install: () => void, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
145
142
  interface AppOption {
146
143
  /**
147
144
  * Path to index file that make {@link startupWithUpdater} as default export