electron-incremental-update 2.0.0-beta.3 → 2.0.0-beta.4

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.js CHANGED
@@ -1,7 +1,7 @@
1
- import { isDev, getPathFromAppNameAsar, getEntryVersion, getAppVersion, restartApp } from './chunk-PNYRQYFC.js';
1
+ import { isDev, getEntryVersion, getAppVersion, getPathFromAppNameAsar, restartApp } from './chunk-PNYRQYFC.js';
2
2
  import { isUpdateJSON, __require } from './chunk-BVFQWBLK.js';
3
3
  import { join } from 'node:path';
4
- import { existsSync, rmSync, renameSync } from 'node:fs';
4
+ import { writeFileSync, existsSync, renameSync } from 'node:fs';
5
5
  import { app } from 'electron';
6
6
  import { EventEmitter } from 'node:events';
7
7
 
@@ -24,8 +24,6 @@ var UpdaterError = class extends Error {
24
24
  var Updater = class extends EventEmitter {
25
25
  CERT = __EIU_SIGNATURE_CERT__;
26
26
  info;
27
- asarPath;
28
- tmpFilePath;
29
27
  provider;
30
28
  /**
31
29
  * updater logger
@@ -63,14 +61,8 @@ var Updater = class extends EventEmitter {
63
61
  };
64
62
  this.logger.info("no logger set, enable dev-only logger");
65
63
  }
66
- this.asarPath = getPathFromAppNameAsar();
67
- this.tmpFilePath = `${this.asarPath}.tmp`;
68
64
  }
69
65
  async fetch(format, data) {
70
- if (existsSync(this.tmpFilePath)) {
71
- this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
72
- rmSync(this.tmpFilePath);
73
- }
74
66
  if (typeof data === "object") {
75
67
  if (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer.isBuffer(data)) {
76
68
  return data;
@@ -132,7 +124,7 @@ var Updater = class extends EventEmitter {
132
124
  this.emit("update-available", this.info);
133
125
  return true;
134
126
  }
135
- async download(data, sig) {
127
+ async downloadUpdate(data, sig) {
136
128
  const _sig = sig ?? this.info?.signature;
137
129
  if (!_sig) {
138
130
  this.err("download failed", "param", "no update signature, please call `checkUpdate` first");
@@ -151,8 +143,9 @@ var Updater = class extends EventEmitter {
151
143
  }
152
144
  this.logger?.debug("verify success");
153
145
  try {
154
- this.logger?.debug(`extract to ${this.tmpFilePath}`);
155
- await this.provider.unzipFile(buffer, this.tmpFilePath);
146
+ const tmpFilePath = getPathFromAppNameAsar() + ".tmp";
147
+ this.logger?.debug(`install to ${tmpFilePath}`);
148
+ writeFileSync(tmpFilePath, await this.provider.unzipFile(buffer));
156
149
  this.logger?.info(`download success, version: ${_ver}`);
157
150
  this.info = void 0;
158
151
  this.emit("update-downloaded");
@@ -175,7 +168,8 @@ var Updater = class extends EventEmitter {
175
168
  * @example
176
169
  * updater.setURLHandler((url, isDownloadingAsar) => {
177
170
  * if (isDownloadingAsar) {
178
- * return url.replace('https://raw.githubusercontent.com', 'https://cdn.jsdelivr.net/gh')
171
+ * url.hostname = 'https://cdn.jsdelivr.net/gh'
172
+ * return url
179
173
  * }
180
174
  * })
181
175
  */
package/dist/provider.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ var url = require('url');
3
4
  var electron = require('electron');
4
5
  var crypto = require('crypto');
5
- var fs = require('fs');
6
6
  var zlib = require('zlib');
7
7
 
8
- // src/provider/download.ts
8
+ // src/provider/github.ts
9
9
 
10
10
  // src/utils/version.ts
11
11
  function parseVersion(version) {
@@ -127,14 +127,14 @@ function defaultVerify(buffer, signature, cert) {
127
127
  return void 0;
128
128
  }
129
129
  }
130
- async function defaultUnzipFile(buffer, targetFilePath) {
130
+ async function defaultUnzipFile(buffer) {
131
131
  return new Promise((resolve, reject) => {
132
132
  zlib.brotliDecompress(buffer, (err, buffer2) => {
133
133
  if (err) {
134
134
  reject(err);
135
+ } else {
136
+ resolve(buffer2);
135
137
  }
136
- fs.writeFileSync(targetFilePath, buffer2);
137
- resolve();
138
138
  });
139
139
  });
140
140
  }
@@ -149,11 +149,8 @@ var BaseProvider = class {
149
149
 
150
150
  // src/provider/github.ts
151
151
  var GitHubProvider = class extends BaseProvider {
152
- ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
153
152
  name = "GithubProvider";
154
- urlHandler;
155
- url;
156
- extraHeaders;
153
+ options;
157
154
  /**
158
155
  * Update Provider for Github repo
159
156
  * - download update json from `https://raw.githubusercontent.com/{user}/{repo}/HEAD/{versionPath}`
@@ -164,32 +161,31 @@ var GitHubProvider = class extends BaseProvider {
164
161
  */
165
162
  constructor(options) {
166
163
  super();
167
- this.extraHeaders = options.extraHeaders;
168
- this.urlHandler = options.urlHandler;
169
- if (!options.url.startsWith("https://github.com")) {
170
- throw new Error(`${this.name}: invalid github url: ${options.url}`);
171
- }
172
- this.url = options.url;
173
- if (!this.url.endsWith("/")) {
174
- this.url += "/";
175
- }
164
+ this.options = options;
165
+ }
166
+ get urlHandler() {
167
+ return this.options.urlHandler;
168
+ }
169
+ set urlHandler(handler) {
170
+ this.options.urlHandler = handler;
176
171
  }
177
172
  async parseURL(isDownloadAsar, extraPath) {
178
- const _url = new URL(this.url);
179
- _url.hostname = isDownloadAsar ? "github.com" : "raw.githubusercontent.com";
180
- _url.pathname += extraPath;
181
- return (await this.urlHandler?.(_url, isDownloadAsar) || _url).toString();
173
+ const url$1 = new url.URL(
174
+ `/${this.options.username}/${this.options.repo}/${extraPath}`,
175
+ "https://" + (isDownloadAsar ? "github.com" : "raw.githubusercontent.com")
176
+ );
177
+ return (await this.urlHandler?.(url$1, isDownloadAsar) || url$1).toString();
182
178
  }
183
179
  async downloadJSON(versionPath) {
184
180
  return await defaultDownloadUpdateJSON(
185
181
  await this.parseURL(false, `HEAD/${versionPath}`),
186
- { userAgent: this.ua, accept: "application/json", ...this.extraHeaders }
182
+ { accept: "application/json", ...this.options.extraHeaders }
187
183
  );
188
184
  }
189
185
  async downloadAsar(name, { version, size }, onDownloading) {
190
186
  return await defaultDownloadAsar(
191
187
  await this.parseURL(true, `releases/download/v${version}/${name}-${version}.asar.gz`),
192
- { userAgent: this.ua, accept: "application/octet-stream", ...this.extraHeaders },
188
+ { accept: "application/octet-stream", ...this.options.extraHeaders },
193
189
  size,
194
190
  onDownloading
195
191
  );
@@ -1,6 +1,5 @@
1
- import { d as defaultIsLowerVersion, U as UpdateJSON, a as UpdateInfo } from './version-CemSHimT.cjs';
2
- import { I as IProvider, D as DownloadingInfo, U as URLHandler, O as OnDownloading } from './types-Tequ_V2o.cjs';
3
- import { e as defaultVerify, d as defaultUnzipFile } from './unzip-JjYLjJkH.cjs';
1
+ import { I as IProvider, d as defaultIsLowerVersion, a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, c as URLHandler, O as OnDownloading } from './types-Bz1VD18z.cjs';
2
+ import { f as defaultVerify, a as defaultUnzipFile } from './zip-WRrEMkgp.cjs';
4
3
  import '@subframe7536/type-utils';
5
4
 
6
5
  declare abstract class BaseProvider implements IProvider {
@@ -14,10 +13,13 @@ declare abstract class BaseProvider implements IProvider {
14
13
 
15
14
  interface GitHubProviderOptions {
16
15
  /**
17
- * github repo root url
18
- * @example 'https://github.com/electron/electron/'
16
+ * github user name
19
17
  */
20
- url: string;
18
+ username: string;
19
+ /**
20
+ * github repo name
21
+ */
22
+ repo: string;
21
23
  /**
22
24
  * extra headers
23
25
  */
@@ -38,11 +40,8 @@ interface GitHubProviderOptions {
38
40
  urlHandler?: URLHandler;
39
41
  }
40
42
  declare class GitHubProvider extends BaseProvider {
41
- private ua;
42
43
  name: string;
43
- urlHandler?: URLHandler;
44
- private url;
45
- private extraHeaders?;
44
+ private options;
46
45
  /**
47
46
  * Update Provider for Github repo
48
47
  * - download update json from `https://raw.githubusercontent.com/{user}/{repo}/HEAD/{versionPath}`
@@ -52,6 +51,8 @@ declare class GitHubProvider extends BaseProvider {
52
51
  * @param options provider options
53
52
  */
54
53
  constructor(options: GitHubProviderOptions);
54
+ get urlHandler(): URLHandler | undefined;
55
+ set urlHandler(handler: URLHandler);
55
56
  private parseURL;
56
57
  downloadJSON(versionPath: string): Promise<UpdateJSON>;
57
58
  downloadAsar(name: string, { version, size }: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
@@ -1,6 +1,5 @@
1
- import { d as defaultIsLowerVersion, U as UpdateJSON, a as UpdateInfo } from './version-CemSHimT.js';
2
- import { I as IProvider, D as DownloadingInfo, U as URLHandler, O as OnDownloading } from './types-DxhNaNgR.js';
3
- import { e as defaultVerify, d as defaultUnzipFile } from './unzip-JjYLjJkH.js';
1
+ import { I as IProvider, d as defaultIsLowerVersion, a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, c as URLHandler, O as OnDownloading } from './types-Bz1VD18z.js';
2
+ import { f as defaultVerify, a as defaultUnzipFile } from './zip-WRrEMkgp.js';
4
3
  import '@subframe7536/type-utils';
5
4
 
6
5
  declare abstract class BaseProvider implements IProvider {
@@ -14,10 +13,13 @@ declare abstract class BaseProvider implements IProvider {
14
13
 
15
14
  interface GitHubProviderOptions {
16
15
  /**
17
- * github repo root url
18
- * @example 'https://github.com/electron/electron/'
16
+ * github user name
19
17
  */
20
- url: string;
18
+ username: string;
19
+ /**
20
+ * github repo name
21
+ */
22
+ repo: string;
21
23
  /**
22
24
  * extra headers
23
25
  */
@@ -38,11 +40,8 @@ interface GitHubProviderOptions {
38
40
  urlHandler?: URLHandler;
39
41
  }
40
42
  declare class GitHubProvider extends BaseProvider {
41
- private ua;
42
43
  name: string;
43
- urlHandler?: URLHandler;
44
- private url;
45
- private extraHeaders?;
44
+ private options;
46
45
  /**
47
46
  * Update Provider for Github repo
48
47
  * - download update json from `https://raw.githubusercontent.com/{user}/{repo}/HEAD/{versionPath}`
@@ -52,6 +51,8 @@ declare class GitHubProvider extends BaseProvider {
52
51
  * @param options provider options
53
52
  */
54
53
  constructor(options: GitHubProviderOptions);
54
+ get urlHandler(): URLHandler | undefined;
55
+ set urlHandler(handler: URLHandler);
55
56
  private parseURL;
56
57
  downloadJSON(versionPath: string): Promise<UpdateJSON>;
57
58
  downloadAsar(name: string, { version, size }: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
package/dist/provider.js CHANGED
@@ -1,5 +1,6 @@
1
- import { defaultVerify, defaultUnzipFile } from './chunk-5WFXC5GU.js';
1
+ import { defaultVerify, defaultUnzipFile } from './chunk-JSYIRKTR.js';
2
2
  import { defaultIsLowerVersion, isUpdateJSON } from './chunk-BVFQWBLK.js';
3
+ import { URL } from 'node:url';
3
4
  import { app, net } from 'electron';
4
5
 
5
6
  async function downloadFn(url, headers, onResponse) {
@@ -66,11 +67,8 @@ var BaseProvider = class {
66
67
 
67
68
  // src/provider/github.ts
68
69
  var GitHubProvider = class extends BaseProvider {
69
- ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
70
70
  name = "GithubProvider";
71
- urlHandler;
72
- url;
73
- extraHeaders;
71
+ options;
74
72
  /**
75
73
  * Update Provider for Github repo
76
74
  * - download update json from `https://raw.githubusercontent.com/{user}/{repo}/HEAD/{versionPath}`
@@ -81,32 +79,31 @@ var GitHubProvider = class extends BaseProvider {
81
79
  */
82
80
  constructor(options) {
83
81
  super();
84
- this.extraHeaders = options.extraHeaders;
85
- this.urlHandler = options.urlHandler;
86
- if (!options.url.startsWith("https://github.com")) {
87
- throw new Error(`${this.name}: invalid github url: ${options.url}`);
88
- }
89
- this.url = options.url;
90
- if (!this.url.endsWith("/")) {
91
- this.url += "/";
92
- }
82
+ this.options = options;
83
+ }
84
+ get urlHandler() {
85
+ return this.options.urlHandler;
86
+ }
87
+ set urlHandler(handler) {
88
+ this.options.urlHandler = handler;
93
89
  }
94
90
  async parseURL(isDownloadAsar, extraPath) {
95
- const _url = new URL(this.url);
96
- _url.hostname = isDownloadAsar ? "github.com" : "raw.githubusercontent.com";
97
- _url.pathname += extraPath;
98
- return (await this.urlHandler?.(_url, isDownloadAsar) || _url).toString();
91
+ const url = new URL(
92
+ `/${this.options.username}/${this.options.repo}/${extraPath}`,
93
+ "https://" + (isDownloadAsar ? "github.com" : "raw.githubusercontent.com")
94
+ );
95
+ return (await this.urlHandler?.(url, isDownloadAsar) || url).toString();
99
96
  }
100
97
  async downloadJSON(versionPath) {
101
98
  return await defaultDownloadUpdateJSON(
102
99
  await this.parseURL(false, `HEAD/${versionPath}`),
103
- { userAgent: this.ua, accept: "application/json", ...this.extraHeaders }
100
+ { accept: "application/json", ...this.options.extraHeaders }
104
101
  );
105
102
  }
106
103
  async downloadAsar(name, { version, size }, onDownloading) {
107
104
  return await defaultDownloadAsar(
108
105
  await this.parseURL(true, `releases/download/v${version}/${name}-${version}.asar.gz`),
109
- { userAgent: this.ua, accept: "application/octet-stream", ...this.extraHeaders },
106
+ { accept: "application/octet-stream", ...this.options.extraHeaders },
110
107
  size,
111
108
  onDownloading
112
109
  );
@@ -1,5 +1,36 @@
1
1
  import { Promisable } from '@subframe7536/type-utils';
2
- import { U as UpdateJSON, a as UpdateInfo } from './version-CemSHimT.js';
2
+
3
+ /**
4
+ * handle all unhandled error
5
+ * @param callback callback function
6
+ */
7
+ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
8
+ interface Version {
9
+ major: number;
10
+ minor: number;
11
+ patch: number;
12
+ stage: string;
13
+ stageVersion: number;
14
+ }
15
+ declare function parseVersion(version: string): Version;
16
+ declare function defaultIsLowerVersion(oldVer: string, newVer: string): boolean;
17
+ /**
18
+ * update info json
19
+ */
20
+ type UpdateInfo = {
21
+ signature: string;
22
+ minimumVersion: string;
23
+ version: string;
24
+ size: number;
25
+ };
26
+ /**
27
+ * {@link UpdateInfo} with beta
28
+ */
29
+ type UpdateJSON = UpdateInfo & {
30
+ beta: UpdateInfo;
31
+ };
32
+ declare function isUpdateJSON(json: any): json is UpdateJSON;
33
+ declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minimumVersion: string): UpdateJSON;
3
34
 
4
35
  type URLHandler = (url: URL, isDownloadAsar: boolean) => Promisable<URL | string | undefined | null>;
5
36
  type OnDownloading = (progress: DownloadingInfo) => void;
@@ -57,11 +88,10 @@ interface IProvider {
57
88
  */
58
89
  isLowerVersion: (oldVer: string, newVer: string) => boolean;
59
90
  /**
60
- * unzip file
91
+ * unzip file buffer
61
92
  * @param buffer source buffer
62
- * @param targetFilePath target file path
63
93
  */
64
- unzipFile: (buffer: Buffer, targetFilePath: string) => Promise<void>;
94
+ unzipFile: (buffer: Buffer) => Promise<Buffer>;
65
95
  /**
66
96
  * verify asar signature
67
97
  * @param buffer file buffer
@@ -72,4 +102,4 @@ interface IProvider {
72
102
  verifySignaure: (buffer: Buffer, signature: string, cert: string) => Promisable<string | undefined>;
73
103
  }
74
104
 
75
- export type { DownloadingInfo as D, IProvider as I, OnDownloading as O, URLHandler as U };
105
+ export { type DownloadingInfo as D, type IProvider as I, type OnDownloading as O, type UpdateInfo as U, type Version as V, type UpdateJSON as a, defaultVersionJsonGenerator as b, type URLHandler as c, defaultIsLowerVersion as d, handleUnexpectedErrors as h, isUpdateJSON as i, parseVersion as p };
@@ -1,5 +1,36 @@
1
1
  import { Promisable } from '@subframe7536/type-utils';
2
- import { U as UpdateJSON, a as UpdateInfo } from './version-CemSHimT.cjs';
2
+
3
+ /**
4
+ * handle all unhandled error
5
+ * @param callback callback function
6
+ */
7
+ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
8
+ interface Version {
9
+ major: number;
10
+ minor: number;
11
+ patch: number;
12
+ stage: string;
13
+ stageVersion: number;
14
+ }
15
+ declare function parseVersion(version: string): Version;
16
+ declare function defaultIsLowerVersion(oldVer: string, newVer: string): boolean;
17
+ /**
18
+ * update info json
19
+ */
20
+ type UpdateInfo = {
21
+ signature: string;
22
+ minimumVersion: string;
23
+ version: string;
24
+ size: number;
25
+ };
26
+ /**
27
+ * {@link UpdateInfo} with beta
28
+ */
29
+ type UpdateJSON = UpdateInfo & {
30
+ beta: UpdateInfo;
31
+ };
32
+ declare function isUpdateJSON(json: any): json is UpdateJSON;
33
+ declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minimumVersion: string): UpdateJSON;
3
34
 
4
35
  type URLHandler = (url: URL, isDownloadAsar: boolean) => Promisable<URL | string | undefined | null>;
5
36
  type OnDownloading = (progress: DownloadingInfo) => void;
@@ -57,11 +88,10 @@ interface IProvider {
57
88
  */
58
89
  isLowerVersion: (oldVer: string, newVer: string) => boolean;
59
90
  /**
60
- * unzip file
91
+ * unzip file buffer
61
92
  * @param buffer source buffer
62
- * @param targetFilePath target file path
63
93
  */
64
- unzipFile: (buffer: Buffer, targetFilePath: string) => Promise<void>;
94
+ unzipFile: (buffer: Buffer) => Promise<Buffer>;
65
95
  /**
66
96
  * verify asar signature
67
97
  * @param buffer file buffer
@@ -72,4 +102,4 @@ interface IProvider {
72
102
  verifySignaure: (buffer: Buffer, signature: string, cert: string) => Promisable<string | undefined>;
73
103
  }
74
104
 
75
- export type { DownloadingInfo as D, IProvider as I, OnDownloading as O, URLHandler as U };
105
+ export { type DownloadingInfo as D, type IProvider as I, type OnDownloading as O, type UpdateInfo as U, type Version as V, type UpdateJSON as a, defaultVersionJsonGenerator as b, type URLHandler as c, defaultIsLowerVersion as d, handleUnexpectedErrors as h, isUpdateJSON as i, parseVersion as p };
package/dist/utils.cjs CHANGED
@@ -82,25 +82,25 @@ function getPathFromPublic(...paths) {
82
82
  function getPathFromEntryAsar(...paths) {
83
83
  return path.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
84
84
  }
85
- async function defaultZipFile(buffer, targetFilePath) {
85
+ async function defaultZipFile(buffer) {
86
86
  return new Promise((resolve, reject) => {
87
87
  zlib.brotliCompress(buffer, (err, buffer2) => {
88
88
  if (err) {
89
89
  reject(err);
90
+ } else {
91
+ resolve(buffer2);
90
92
  }
91
- fs.writeFileSync(targetFilePath, buffer2);
92
- resolve();
93
93
  });
94
94
  });
95
95
  }
96
- async function defaultUnzipFile(buffer, targetFilePath) {
96
+ async function defaultUnzipFile(buffer) {
97
97
  return new Promise((resolve, reject) => {
98
98
  zlib.brotliDecompress(buffer, (err, buffer2) => {
99
99
  if (err) {
100
100
  reject(err);
101
+ } else {
102
+ resolve(buffer2);
101
103
  }
102
- fs.writeFileSync(targetFilePath, buffer2);
103
- resolve();
104
104
  });
105
105
  });
106
106
  }
@@ -198,8 +198,16 @@ function defaultVerify(buffer, signature, cert) {
198
198
  }
199
199
  }
200
200
 
201
+ // src/utils/updater.ts
202
+ async function autoUpdate(updater) {
203
+ if (await updater.checkUpdate() && await updater.downloadUpdate()) {
204
+ updater.quitAndInstall();
205
+ }
206
+ }
207
+
201
208
  exports.aesDecrypt = aesDecrypt;
202
209
  exports.aesEncrypt = aesEncrypt;
210
+ exports.autoUpdate = autoUpdate;
203
211
  exports.defaultIsLowerVersion = defaultIsLowerVersion;
204
212
  exports.defaultSignature = defaultSignature;
205
213
  exports.defaultUnzipFile = defaultUnzipFile;
package/dist/utils.d.cts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { BrowserWindow } from 'electron';
2
- export { c as aesDecrypt, a as aesEncrypt, b as defaultSignature, d as defaultUnzipFile, e as defaultVerify, h as hashBuffer } from './unzip-JjYLjJkH.cjs';
3
- export { a as UpdateInfo, U as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseVersion } from './version-CemSHimT.cjs';
2
+ export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerify, d as defaultZipFile, h as hashBuffer } from './zip-WRrEMkgp.cjs';
3
+ export { U as UpdateInfo, a as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseVersion } from './types-Bz1VD18z.cjs';
4
+ import { U as Updater } from './core-CW7TMqi7.cjs';
5
+ import '@subframe7536/type-utils';
6
+ import 'node:events';
4
7
 
5
8
  /**
6
9
  * compile time dev check
@@ -64,6 +67,9 @@ declare function getPathFromPreload(...paths: string[]): string;
64
67
  declare function getPathFromPublic(...paths: string[]): string;
65
68
  declare function getPathFromEntryAsar(...paths: string[]): string;
66
69
 
67
- declare function defaultZipFile(buffer: Buffer, targetFilePath: string): Promise<void>;
70
+ /**
71
+ * auto check update, download and install
72
+ */
73
+ declare function autoUpdate(updater: Updater): Promise<void>;
68
74
 
69
- export { defaultZipFile, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
75
+ export { autoUpdate, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { BrowserWindow } from 'electron';
2
- export { c as aesDecrypt, a as aesEncrypt, b as defaultSignature, d as defaultUnzipFile, e as defaultVerify, h as hashBuffer } from './unzip-JjYLjJkH.js';
3
- export { a as UpdateInfo, U as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseVersion } from './version-CemSHimT.js';
2
+ export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerify, d as defaultZipFile, h as hashBuffer } from './zip-WRrEMkgp.js';
3
+ export { U as UpdateInfo, a as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseVersion } from './types-Bz1VD18z.js';
4
+ import { U as Updater } from './core-D6QlpOgp.js';
5
+ import '@subframe7536/type-utils';
6
+ import 'node:events';
4
7
 
5
8
  /**
6
9
  * compile time dev check
@@ -64,6 +67,9 @@ declare function getPathFromPreload(...paths: string[]): string;
64
67
  declare function getPathFromPublic(...paths: string[]): string;
65
68
  declare function getPathFromEntryAsar(...paths: string[]): string;
66
69
 
67
- declare function defaultZipFile(buffer: Buffer, targetFilePath: string): Promise<void>;
70
+ /**
71
+ * auto check update, download and install
72
+ */
73
+ declare function autoUpdate(updater: Updater): Promise<void>;
68
74
 
69
- export { defaultZipFile, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
75
+ export { autoUpdate, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
package/dist/utils.js CHANGED
@@ -1,19 +1,12 @@
1
1
  export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance } from './chunk-PNYRQYFC.js';
2
- export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerify, hashBuffer } from './chunk-5WFXC5GU.js';
2
+ export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerify, defaultZipFile, hashBuffer } from './chunk-JSYIRKTR.js';
3
3
  export { defaultIsLowerVersion, defaultVersionJsonGenerator, handleUnexpectedErrors, isUpdateJSON, parseVersion } from './chunk-BVFQWBLK.js';
4
- import { writeFileSync } from 'node:fs';
5
- import { brotliCompress } from 'node:zlib';
6
4
 
7
- async function defaultZipFile(buffer, targetFilePath) {
8
- return new Promise((resolve, reject) => {
9
- brotliCompress(buffer, (err, buffer2) => {
10
- if (err) {
11
- reject(err);
12
- }
13
- writeFileSync(targetFilePath, buffer2);
14
- resolve();
15
- });
16
- });
5
+ // src/utils/updater.ts
6
+ async function autoUpdate(updater) {
7
+ if (await updater.checkUpdate() && await updater.downloadUpdate()) {
8
+ updater.quitAndInstall();
9
+ }
17
10
  }
18
11
 
19
- export { defaultZipFile };
12
+ export { autoUpdate };