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

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.
@@ -1,37 +1,63 @@
1
- import { i as isLowerVersionDefault, U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.cjs';
2
- import { v as verifySignatureDefault } from './decrypt-D9WdXYjH.cjs';
3
- import { U as URLHandler, I as IProvider, D as DownloadingInfo, O as OnDownloading } from './types-COqp44eg.cjs';
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';
4
4
  import '@subframe7536/type-utils';
5
5
 
6
+ declare abstract class BaseProvider implements IProvider {
7
+ name: string;
8
+ isLowerVersion: typeof defaultIsLowerVersion;
9
+ verifySignaure: typeof defaultVerify;
10
+ unzipFile: typeof defaultUnzipFile;
11
+ abstract downloadJSON(versionPath: string): Promise<UpdateJSON>;
12
+ abstract downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
13
+ }
14
+
6
15
  interface GitHubProviderOptions {
7
16
  /**
8
17
  * github repo root url
9
- * @example 'https://github.com/electron/electron'
18
+ * @example 'https://github.com/electron/electron/'
10
19
  */
11
20
  url: string;
21
+ /**
22
+ * extra headers
23
+ */
12
24
  extraHeaders?: Record<string, string>;
13
25
  /**
14
26
  * custom url handler
15
27
  *
16
- * for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDN links}
28
+ * for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L40 public CDN links}
29
+ * @example
30
+ * (url, isDownloadAsar) => {
31
+ * if (isDownloadAsar) {
32
+ * url.hostname = 'mirror.ghproxy.com'
33
+ * url.pathname = 'https://github.com' + url.pathname
34
+ * return url
35
+ * }
36
+ * }
17
37
  */
18
38
  urlHandler?: URLHandler;
19
39
  }
20
- declare class GitHubProvider implements IProvider {
40
+ declare class GitHubProvider extends BaseProvider {
21
41
  private ua;
22
42
  name: string;
23
43
  urlHandler?: URLHandler;
24
44
  private url;
25
45
  private extraHeaders?;
46
+ /**
47
+ * Update Provider for Github repo
48
+ * - download update json from `https://raw.githubusercontent.com/{user}/{repo}/HEAD/{versionPath}`
49
+ * - download update asar from `https://github.com/{user}/{repo}/releases/download/v{version}/{name}-{version}.asar.gz`
50
+ *
51
+ * you can setup `urlHandler` in {@link GitHubProviderOptions} or `Updater` to modify url before request
52
+ * @param options provider options
53
+ */
26
54
  constructor(options: GitHubProviderOptions);
27
55
  private parseURL;
28
- isLowerVersion: typeof isLowerVersionDefault;
29
- verifySignaure: typeof verifySignatureDefault;
30
56
  downloadJSON(versionPath: string): Promise<UpdateJSON>;
31
57
  downloadAsar(name: string, { version, size }: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
32
58
  }
33
59
 
34
- declare function downloadUpdateJSONDefault(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
35
- declare function downloadAsarBufferDefault(url: string, headers: Record<string, any>, total: number, onDownloading?: OnDownloading): Promise<Buffer>;
60
+ declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
61
+ declare function defaultDownloadAsar(url: string, headers: Record<string, any>, total: number, onDownloading?: OnDownloading): Promise<Buffer>;
36
62
 
37
- export { DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, downloadAsarBufferDefault, downloadUpdateJSONDefault };
63
+ export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON };
@@ -1,37 +1,63 @@
1
- import { i as isLowerVersionDefault, U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.js';
2
- import { v as verifySignatureDefault } from './decrypt-D9WdXYjH.js';
3
- import { U as URLHandler, I as IProvider, D as DownloadingInfo, O as OnDownloading } from './types-CPq1MrYZ.js';
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';
4
4
  import '@subframe7536/type-utils';
5
5
 
6
+ declare abstract class BaseProvider implements IProvider {
7
+ name: string;
8
+ isLowerVersion: typeof defaultIsLowerVersion;
9
+ verifySignaure: typeof defaultVerify;
10
+ unzipFile: typeof defaultUnzipFile;
11
+ abstract downloadJSON(versionPath: string): Promise<UpdateJSON>;
12
+ abstract downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
13
+ }
14
+
6
15
  interface GitHubProviderOptions {
7
16
  /**
8
17
  * github repo root url
9
- * @example 'https://github.com/electron/electron'
18
+ * @example 'https://github.com/electron/electron/'
10
19
  */
11
20
  url: string;
21
+ /**
22
+ * extra headers
23
+ */
12
24
  extraHeaders?: Record<string, string>;
13
25
  /**
14
26
  * custom url handler
15
27
  *
16
- * for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDN links}
28
+ * for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L40 public CDN links}
29
+ * @example
30
+ * (url, isDownloadAsar) => {
31
+ * if (isDownloadAsar) {
32
+ * url.hostname = 'mirror.ghproxy.com'
33
+ * url.pathname = 'https://github.com' + url.pathname
34
+ * return url
35
+ * }
36
+ * }
17
37
  */
18
38
  urlHandler?: URLHandler;
19
39
  }
20
- declare class GitHubProvider implements IProvider {
40
+ declare class GitHubProvider extends BaseProvider {
21
41
  private ua;
22
42
  name: string;
23
43
  urlHandler?: URLHandler;
24
44
  private url;
25
45
  private extraHeaders?;
46
+ /**
47
+ * Update Provider for Github repo
48
+ * - download update json from `https://raw.githubusercontent.com/{user}/{repo}/HEAD/{versionPath}`
49
+ * - download update asar from `https://github.com/{user}/{repo}/releases/download/v{version}/{name}-{version}.asar.gz`
50
+ *
51
+ * you can setup `urlHandler` in {@link GitHubProviderOptions} or `Updater` to modify url before request
52
+ * @param options provider options
53
+ */
26
54
  constructor(options: GitHubProviderOptions);
27
55
  private parseURL;
28
- isLowerVersion: typeof isLowerVersionDefault;
29
- verifySignaure: typeof verifySignatureDefault;
30
56
  downloadJSON(versionPath: string): Promise<UpdateJSON>;
31
57
  downloadAsar(name: string, { version, size }: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
32
58
  }
33
59
 
34
- declare function downloadUpdateJSONDefault(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
35
- declare function downloadAsarBufferDefault(url: string, headers: Record<string, any>, total: number, onDownloading?: OnDownloading): Promise<Buffer>;
60
+ declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
61
+ declare function defaultDownloadAsar(url: string, headers: Record<string, any>, total: number, onDownloading?: OnDownloading): Promise<Buffer>;
36
62
 
37
- export { DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, downloadAsarBufferDefault, downloadUpdateJSONDefault };
63
+ export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON };
package/dist/provider.js CHANGED
@@ -1,14 +1,9 @@
1
- import {
2
- isLowerVersionDefault,
3
- isUpdateJSON,
4
- verifySignatureDefault,
5
- waitAppReady
6
- } from "./chunk-BG22XZAB.js";
1
+ import { defaultVerify, defaultUnzipFile } from './chunk-5WFXC5GU.js';
2
+ import { defaultIsLowerVersion, isUpdateJSON } from './chunk-BVFQWBLK.js';
3
+ import { app, net } from 'electron';
7
4
 
8
- // src/provider/download.ts
9
- import { net } from "electron";
10
- async function downlaodFn(url, headers, onResponse) {
11
- await waitAppReady();
5
+ async function downloadFn(url, headers, onResponse) {
6
+ await app.whenReady();
12
7
  return new Promise((resolve, reject) => {
13
8
  const request = net.request({ url, method: "GET", redirect: "follow" });
14
9
  Object.keys(headers).forEach((key) => request.setHeader(key, headers[key]));
@@ -21,8 +16,8 @@ async function downlaodFn(url, headers, onResponse) {
21
16
  request.end();
22
17
  });
23
18
  }
24
- async function downloadUpdateJSONDefault(url, headers) {
25
- return await downlaodFn(url, headers, (resp, resolve, reject) => {
19
+ async function defaultDownloadUpdateJSON(url, headers) {
20
+ return await downloadFn(url, headers, (resp, resolve, reject) => {
26
21
  let data = "";
27
22
  resp.on("data", (chunk) => data += chunk);
28
23
  resp.on("end", () => {
@@ -39,10 +34,10 @@ async function downloadUpdateJSONDefault(url, headers) {
39
34
  });
40
35
  });
41
36
  }
42
- async function downloadAsarBufferDefault(url, headers, total, onDownloading) {
37
+ async function defaultDownloadAsar(url, headers, total, onDownloading) {
43
38
  let transferred = 0;
44
39
  let time = Date.now();
45
- return await downlaodFn(url, headers, (resp, resolve) => {
40
+ return await downloadFn(url, headers, (resp, resolve) => {
46
41
  let data = [];
47
42
  resp.on("data", (chunk) => {
48
43
  transferred += chunk.length;
@@ -61,47 +56,61 @@ async function downloadAsarBufferDefault(url, headers, total, onDownloading) {
61
56
  });
62
57
  }
63
58
 
59
+ // src/provider/base.ts
60
+ var BaseProvider = class {
61
+ name = "BaseProvider";
62
+ isLowerVersion = defaultIsLowerVersion;
63
+ verifySignaure = defaultVerify;
64
+ unzipFile = defaultUnzipFile;
65
+ };
66
+
64
67
  // src/provider/github.ts
65
- var GitHubProvider = class {
68
+ var GitHubProvider = class extends BaseProvider {
66
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";
67
70
  name = "GithubProvider";
68
71
  urlHandler;
69
72
  url;
70
73
  extraHeaders;
74
+ /**
75
+ * Update Provider for Github repo
76
+ * - download update json from `https://raw.githubusercontent.com/{user}/{repo}/HEAD/{versionPath}`
77
+ * - download update asar from `https://github.com/{user}/{repo}/releases/download/v{version}/{name}-{version}.asar.gz`
78
+ *
79
+ * you can setup `urlHandler` in {@link GitHubProviderOptions} or `Updater` to modify url before request
80
+ * @param options provider options
81
+ */
71
82
  constructor(options) {
72
- this.url = new URL(options.url);
83
+ super();
73
84
  this.extraHeaders = options.extraHeaders;
74
85
  this.urlHandler = options.urlHandler;
75
- if (this.url.host !== "github.com") {
86
+ if (!options.url.startsWith("https://github.com")) {
76
87
  throw new Error(`${this.name}: invalid github url: ${options.url}`);
77
88
  }
78
- if (!this.url.pathname.endsWith("/")) {
79
- this.url.pathname += "/";
89
+ this.url = options.url;
90
+ if (!this.url.endsWith("/")) {
91
+ this.url += "/";
80
92
  }
81
93
  }
82
- parseURL(isDownloadAsar, path) {
83
- const url = this.url.href + path;
84
- return this.urlHandler ? this.urlHandler(url, isDownloadAsar) : url;
94
+ 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();
85
99
  }
86
- isLowerVersion = isLowerVersionDefault;
87
- verifySignaure = verifySignatureDefault;
88
100
  async downloadJSON(versionPath) {
89
- return await downloadUpdateJSONDefault(
90
- this.parseURL(false, `HEAD/${versionPath}`),
101
+ return await defaultDownloadUpdateJSON(
102
+ await this.parseURL(false, `HEAD/${versionPath}`),
91
103
  { userAgent: this.ua, accept: "application/json", ...this.extraHeaders }
92
104
  );
93
105
  }
94
106
  async downloadAsar(name, { version, size }, onDownloading) {
95
- return await downloadAsarBufferDefault(
96
- this.parseURL(true, `releases/download/v${version}/${name}-${version}.asar.gz`),
107
+ return await defaultDownloadAsar(
108
+ await this.parseURL(true, `releases/download/v${version}/${name}-${version}.asar.gz`),
97
109
  { userAgent: this.ua, accept: "application/octet-stream", ...this.extraHeaders },
98
110
  size,
99
111
  onDownloading
100
112
  );
101
113
  }
102
114
  };
103
- export {
104
- GitHubProvider,
105
- downloadAsarBufferDefault,
106
- downloadUpdateJSONDefault
107
- };
115
+
116
+ export { BaseProvider, GitHubProvider, defaultDownloadAsar, defaultDownloadUpdateJSON };
@@ -1,7 +1,7 @@
1
1
  import { Promisable } from '@subframe7536/type-utils';
2
- import { U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.js';
2
+ import { U as UpdateJSON, a as UpdateInfo } from './version-CemSHimT.js';
3
3
 
4
- type URLHandler = (url: string, isDownloadAsar: boolean) => string;
4
+ type URLHandler = (url: URL, isDownloadAsar: boolean) => Promisable<URL | string | undefined | null>;
5
5
  type OnDownloading = (progress: DownloadingInfo) => void;
6
6
  interface DownloadingInfo {
7
7
  /**
@@ -56,6 +56,12 @@ interface IProvider {
56
56
  * @returns if version1 < version2
57
57
  */
58
58
  isLowerVersion: (oldVer: string, newVer: string) => boolean;
59
+ /**
60
+ * unzip file
61
+ * @param buffer source buffer
62
+ * @param targetFilePath target file path
63
+ */
64
+ unzipFile: (buffer: Buffer, targetFilePath: string) => Promise<void>;
59
65
  /**
60
66
  * verify asar signature
61
67
  * @param buffer file buffer
@@ -1,7 +1,7 @@
1
1
  import { Promisable } from '@subframe7536/type-utils';
2
- import { U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.cjs';
2
+ import { U as UpdateJSON, a as UpdateInfo } from './version-CemSHimT.cjs';
3
3
 
4
- type URLHandler = (url: string, isDownloadAsar: boolean) => string;
4
+ type URLHandler = (url: URL, isDownloadAsar: boolean) => Promisable<URL | string | undefined | null>;
5
5
  type OnDownloading = (progress: DownloadingInfo) => void;
6
6
  interface DownloadingInfo {
7
7
  /**
@@ -56,6 +56,12 @@ interface IProvider {
56
56
  * @returns if version1 < version2
57
57
  */
58
58
  isLowerVersion: (oldVer: string, newVer: string) => boolean;
59
+ /**
60
+ * unzip file
61
+ * @param buffer source buffer
62
+ * @param targetFilePath target file path
63
+ */
64
+ unzipFile: (buffer: Buffer, targetFilePath: string) => Promise<void>;
59
65
  /**
60
66
  * verify asar signature
61
67
  * @param buffer file buffer
@@ -0,0 +1,9 @@
1
+ declare function hashBuffer(data: string | Buffer, length: number): Buffer;
2
+ declare function aesEncrypt(plainText: string, key: Buffer, iv: Buffer): string;
3
+ declare function defaultSignature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
4
+ declare function aesDecrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
5
+ declare function defaultVerify(buffer: Buffer, signature: string, cert: string): string | undefined;
6
+
7
+ declare function defaultUnzipFile(buffer: Buffer, targetFilePath: string): Promise<void>;
8
+
9
+ export { aesEncrypt as a, defaultSignature as b, aesDecrypt as c, defaultUnzipFile as d, defaultVerify as e, hashBuffer as h };
@@ -0,0 +1,9 @@
1
+ declare function hashBuffer(data: string | Buffer, length: number): Buffer;
2
+ declare function aesEncrypt(plainText: string, key: Buffer, iv: Buffer): string;
3
+ declare function defaultSignature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
4
+ declare function aesDecrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
5
+ declare function defaultVerify(buffer: Buffer, signature: string, cert: string): string | undefined;
6
+
7
+ declare function defaultUnzipFile(buffer: Buffer, targetFilePath: string): Promise<void>;
8
+
9
+ export { aesEncrypt as a, defaultSignature as b, aesDecrypt as c, defaultUnzipFile as d, defaultVerify as e, hashBuffer as h };