electron-incremental-update 2.0.0-beta.6 → 2.0.0-beta.8
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/{chunk-DFNDKSE6.js → chunk-4MH6ZXCY.js} +12 -12
- package/dist/{chunk-N77WQ5WB.js → chunk-KZSYEXLO.js} +9 -9
- package/dist/core-DJdvtwvU.d.ts +134 -0
- package/dist/core-ZUlLHadf.d.cts +134 -0
- package/dist/index.cjs +15 -10
- package/dist/index.d.cts +78 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +9 -9
- package/dist/provider.cjs +9 -4
- package/dist/provider.d.cts +76 -0
- package/dist/provider.d.ts +76 -0
- package/dist/provider.js +1 -1
- package/dist/types-CItP6bL-.d.cts +104 -0
- package/dist/types-CItP6bL-.d.ts +104 -0
- package/dist/utils.cjs +24 -22
- package/dist/utils.d.cts +80 -0
- package/dist/utils.d.ts +80 -0
- package/dist/utils.js +2 -3
- package/dist/vite.d.ts +405 -0
- package/dist/vite.js +166 -118
- package/dist/zip-DPF5IFkK.d.cts +10 -0
- package/dist/zip-DPF5IFkK.d.ts +10 -0
- package/package.json +8 -6
package/dist/provider.cjs
CHANGED
|
@@ -5,6 +5,11 @@ var electron = require('electron');
|
|
|
5
5
|
var crypto = require('crypto');
|
|
6
6
|
var zlib = require('zlib');
|
|
7
7
|
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
11
|
+
var zlib__default = /*#__PURE__*/_interopDefault(zlib);
|
|
12
|
+
|
|
8
13
|
// src/provider/github.ts
|
|
9
14
|
|
|
10
15
|
// src/utils/version.ts
|
|
@@ -121,11 +126,11 @@ async function defaultDownloadAsar(url, headers, onDownloading) {
|
|
|
121
126
|
});
|
|
122
127
|
}
|
|
123
128
|
function hashBuffer(data, length) {
|
|
124
|
-
const hash =
|
|
129
|
+
const hash = crypto__default.default.createHash("SHA256").update(data).digest("binary");
|
|
125
130
|
return Buffer.from(hash).subarray(0, length);
|
|
126
131
|
}
|
|
127
132
|
function aesDecrypt(encryptedText, key, iv) {
|
|
128
|
-
const decipher =
|
|
133
|
+
const decipher = crypto__default.default.createDecipheriv("aes-256-cbc", key, iv);
|
|
129
134
|
return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
|
|
130
135
|
}
|
|
131
136
|
function defaultVerifySignature(buffer, version, signature, cert) {
|
|
@@ -134,14 +139,14 @@ function defaultVerifySignature(buffer, version, signature, cert) {
|
|
|
134
139
|
if (ver !== version) {
|
|
135
140
|
return false;
|
|
136
141
|
}
|
|
137
|
-
return
|
|
142
|
+
return crypto__default.default.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
138
143
|
} catch {
|
|
139
144
|
return false;
|
|
140
145
|
}
|
|
141
146
|
}
|
|
142
147
|
async function defaultUnzipFile(buffer) {
|
|
143
148
|
return new Promise((resolve, reject) => {
|
|
144
|
-
|
|
149
|
+
zlib__default.default.brotliDecompress(buffer, (err, buffer2) => {
|
|
145
150
|
if (err) {
|
|
146
151
|
reject(err);
|
|
147
152
|
} else {
|
|
@@ -0,0 +1,76 @@
|
|
|
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-CItP6bL-.cjs';
|
|
2
|
+
import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-DPF5IFkK.cjs';
|
|
3
|
+
import { Arrayable } from '@subframe7536/type-utils';
|
|
4
|
+
|
|
5
|
+
declare abstract class BaseProvider implements IProvider {
|
|
6
|
+
name: string;
|
|
7
|
+
isLowerVersion: typeof defaultIsLowerVersion;
|
|
8
|
+
verifySignaure: typeof defaultVerifySignature;
|
|
9
|
+
unzipFile: typeof defaultUnzipFile;
|
|
10
|
+
abstract downloadJSON(versionPath: string): Promise<UpdateJSON>;
|
|
11
|
+
abstract downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface GitHubProviderOptions {
|
|
15
|
+
/**
|
|
16
|
+
* github user name
|
|
17
|
+
*/
|
|
18
|
+
username: string;
|
|
19
|
+
/**
|
|
20
|
+
* github repo name
|
|
21
|
+
*/
|
|
22
|
+
repo: string;
|
|
23
|
+
/**
|
|
24
|
+
* github branch name that fetch version
|
|
25
|
+
* @default 'HEAD'
|
|
26
|
+
*/
|
|
27
|
+
branch?: string;
|
|
28
|
+
/**
|
|
29
|
+
* extra headers
|
|
30
|
+
*/
|
|
31
|
+
extraHeaders?: Record<string, string>;
|
|
32
|
+
/**
|
|
33
|
+
* custom url handler
|
|
34
|
+
*
|
|
35
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L40 public CDN links}
|
|
36
|
+
* @example
|
|
37
|
+
* (url, isDownloadAsar) => {
|
|
38
|
+
* if (isDownloadAsar) {
|
|
39
|
+
* url.hostname = 'mirror.ghproxy.com'
|
|
40
|
+
* url.pathname = 'https://github.com' + url.pathname
|
|
41
|
+
* return url
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
*/
|
|
45
|
+
urlHandler?: URLHandler;
|
|
46
|
+
}
|
|
47
|
+
declare class GitHubProvider extends BaseProvider {
|
|
48
|
+
name: string;
|
|
49
|
+
private options;
|
|
50
|
+
/**
|
|
51
|
+
* Update Provider for Github repo
|
|
52
|
+
* - download update json from `https://raw.githubusercontent.com/{user}/{repo}/HEAD/{versionPath}`
|
|
53
|
+
* - download update asar from `https://github.com/{user}/{repo}/releases/download/v{version}/{name}-{version}.asar.gz`
|
|
54
|
+
*
|
|
55
|
+
* you can setup `urlHandler` in {@link GitHubProviderOptions} or `Updater` to modify url before request
|
|
56
|
+
* @param options provider options
|
|
57
|
+
*/
|
|
58
|
+
constructor(options: GitHubProviderOptions);
|
|
59
|
+
get urlHandler(): URLHandler | undefined;
|
|
60
|
+
set urlHandler(handler: URLHandler);
|
|
61
|
+
private parseURL;
|
|
62
|
+
downloadJSON(versionPath: string): Promise<UpdateJSON>;
|
|
63
|
+
downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare function getHeader(response: Record<string, Arrayable<string>>, headerKey: any): any;
|
|
67
|
+
/**
|
|
68
|
+
* download json and parse UpdateJson
|
|
69
|
+
*/
|
|
70
|
+
declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
|
|
71
|
+
/**
|
|
72
|
+
* download asar buffer, get total size from `Content-Length` header
|
|
73
|
+
*/
|
|
74
|
+
declare function defaultDownloadAsar(url: string, headers: Record<string, any>, onDownloading?: OnDownloading): Promise<Buffer>;
|
|
75
|
+
|
|
76
|
+
export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON, getHeader };
|
|
@@ -0,0 +1,76 @@
|
|
|
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-CItP6bL-.js';
|
|
2
|
+
import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-DPF5IFkK.js';
|
|
3
|
+
import { Arrayable } from '@subframe7536/type-utils';
|
|
4
|
+
|
|
5
|
+
declare abstract class BaseProvider implements IProvider {
|
|
6
|
+
name: string;
|
|
7
|
+
isLowerVersion: typeof defaultIsLowerVersion;
|
|
8
|
+
verifySignaure: typeof defaultVerifySignature;
|
|
9
|
+
unzipFile: typeof defaultUnzipFile;
|
|
10
|
+
abstract downloadJSON(versionPath: string): Promise<UpdateJSON>;
|
|
11
|
+
abstract downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface GitHubProviderOptions {
|
|
15
|
+
/**
|
|
16
|
+
* github user name
|
|
17
|
+
*/
|
|
18
|
+
username: string;
|
|
19
|
+
/**
|
|
20
|
+
* github repo name
|
|
21
|
+
*/
|
|
22
|
+
repo: string;
|
|
23
|
+
/**
|
|
24
|
+
* github branch name that fetch version
|
|
25
|
+
* @default 'HEAD'
|
|
26
|
+
*/
|
|
27
|
+
branch?: string;
|
|
28
|
+
/**
|
|
29
|
+
* extra headers
|
|
30
|
+
*/
|
|
31
|
+
extraHeaders?: Record<string, string>;
|
|
32
|
+
/**
|
|
33
|
+
* custom url handler
|
|
34
|
+
*
|
|
35
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L40 public CDN links}
|
|
36
|
+
* @example
|
|
37
|
+
* (url, isDownloadAsar) => {
|
|
38
|
+
* if (isDownloadAsar) {
|
|
39
|
+
* url.hostname = 'mirror.ghproxy.com'
|
|
40
|
+
* url.pathname = 'https://github.com' + url.pathname
|
|
41
|
+
* return url
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
*/
|
|
45
|
+
urlHandler?: URLHandler;
|
|
46
|
+
}
|
|
47
|
+
declare class GitHubProvider extends BaseProvider {
|
|
48
|
+
name: string;
|
|
49
|
+
private options;
|
|
50
|
+
/**
|
|
51
|
+
* Update Provider for Github repo
|
|
52
|
+
* - download update json from `https://raw.githubusercontent.com/{user}/{repo}/HEAD/{versionPath}`
|
|
53
|
+
* - download update asar from `https://github.com/{user}/{repo}/releases/download/v{version}/{name}-{version}.asar.gz`
|
|
54
|
+
*
|
|
55
|
+
* you can setup `urlHandler` in {@link GitHubProviderOptions} or `Updater` to modify url before request
|
|
56
|
+
* @param options provider options
|
|
57
|
+
*/
|
|
58
|
+
constructor(options: GitHubProviderOptions);
|
|
59
|
+
get urlHandler(): URLHandler | undefined;
|
|
60
|
+
set urlHandler(handler: URLHandler);
|
|
61
|
+
private parseURL;
|
|
62
|
+
downloadJSON(versionPath: string): Promise<UpdateJSON>;
|
|
63
|
+
downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare function getHeader(response: Record<string, Arrayable<string>>, headerKey: any): any;
|
|
67
|
+
/**
|
|
68
|
+
* download json and parse UpdateJson
|
|
69
|
+
*/
|
|
70
|
+
declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
|
|
71
|
+
/**
|
|
72
|
+
* download asar buffer, get total size from `Content-Length` header
|
|
73
|
+
*/
|
|
74
|
+
declare function defaultDownloadAsar(url: string, headers: Record<string, any>, onDownloading?: OnDownloading): Promise<Buffer>;
|
|
75
|
+
|
|
76
|
+
export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON, getHeader };
|
package/dist/provider.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defaultVerifySignature, defaultUnzipFile } from './chunk-
|
|
1
|
+
import { defaultVerifySignature, defaultUnzipFile } from './chunk-KZSYEXLO.js';
|
|
2
2
|
import { defaultIsLowerVersion, isUpdateJSON } from './chunk-72ZAJ7AF.js';
|
|
3
3
|
import { URL } from 'node:url';
|
|
4
4
|
import { app, net } from 'electron';
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Promisable } from '@subframe7536/type-utils';
|
|
2
|
+
|
|
3
|
+
interface Version {
|
|
4
|
+
major: number;
|
|
5
|
+
minor: number;
|
|
6
|
+
patch: number;
|
|
7
|
+
stage: string;
|
|
8
|
+
stageVersion: number;
|
|
9
|
+
}
|
|
10
|
+
declare function parseVersion(version: string): Version;
|
|
11
|
+
declare function defaultIsLowerVersion(oldVer: string, newVer: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* update info json
|
|
14
|
+
*/
|
|
15
|
+
type UpdateInfo = {
|
|
16
|
+
signature: string;
|
|
17
|
+
minimumVersion: string;
|
|
18
|
+
version: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* {@link UpdateInfo} with beta
|
|
22
|
+
*/
|
|
23
|
+
type UpdateJSON = UpdateInfo & {
|
|
24
|
+
beta: UpdateInfo;
|
|
25
|
+
};
|
|
26
|
+
declare function isUpdateJSON(json: any): json is UpdateJSON;
|
|
27
|
+
declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
|
|
28
|
+
|
|
29
|
+
type URLHandler = (url: URL, isDownloadAsar: boolean) => Promisable<URL | string | undefined | null>;
|
|
30
|
+
type OnDownloading = (progress: DownloadingInfo) => void;
|
|
31
|
+
interface DownloadingInfo {
|
|
32
|
+
/**
|
|
33
|
+
* download delta
|
|
34
|
+
*/
|
|
35
|
+
delta: number;
|
|
36
|
+
/**
|
|
37
|
+
* downloaded percent, 0 ~ 100
|
|
38
|
+
*
|
|
39
|
+
* If not `Content-Length` header, will be nagative
|
|
40
|
+
*/
|
|
41
|
+
percent: number;
|
|
42
|
+
/**
|
|
43
|
+
* total size
|
|
44
|
+
*
|
|
45
|
+
* If not `Content-Length` header, will be -1
|
|
46
|
+
*/
|
|
47
|
+
total: number;
|
|
48
|
+
/**
|
|
49
|
+
* downloaded size
|
|
50
|
+
*/
|
|
51
|
+
transferred: number;
|
|
52
|
+
/**
|
|
53
|
+
* download speed, bytes per second
|
|
54
|
+
*/
|
|
55
|
+
bps: number;
|
|
56
|
+
}
|
|
57
|
+
interface IProvider {
|
|
58
|
+
/**
|
|
59
|
+
* provider name
|
|
60
|
+
*/
|
|
61
|
+
name: string;
|
|
62
|
+
/**
|
|
63
|
+
* custom url handler
|
|
64
|
+
*
|
|
65
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDN links}
|
|
66
|
+
*/
|
|
67
|
+
urlHandler?: URLHandler;
|
|
68
|
+
onDownloading?: OnDownloading;
|
|
69
|
+
/**
|
|
70
|
+
* download update json
|
|
71
|
+
* @param versionPath parsed version path
|
|
72
|
+
*/
|
|
73
|
+
downloadJSON: (versionPath: string) => Promise<UpdateJSON>;
|
|
74
|
+
/**
|
|
75
|
+
* download update asar
|
|
76
|
+
* @param name app name
|
|
77
|
+
* @param updateInfo existing update info
|
|
78
|
+
* @param onDownloading hook for on downloading
|
|
79
|
+
*/
|
|
80
|
+
downloadAsar: (name: string, updateInfo: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void) => Promise<Buffer>;
|
|
81
|
+
/**
|
|
82
|
+
* compare version
|
|
83
|
+
* @param oldVer old version string
|
|
84
|
+
* @param newVer new version string
|
|
85
|
+
* @returns if version1 < version2
|
|
86
|
+
*/
|
|
87
|
+
isLowerVersion: (oldVer: string, newVer: string) => boolean;
|
|
88
|
+
/**
|
|
89
|
+
* unzip file buffer
|
|
90
|
+
* @param buffer source buffer
|
|
91
|
+
*/
|
|
92
|
+
unzipFile: (buffer: Buffer) => Promise<Buffer>;
|
|
93
|
+
/**
|
|
94
|
+
* verify asar signature
|
|
95
|
+
* @param buffer file buffer
|
|
96
|
+
* @param version target version
|
|
97
|
+
* @param signature signature
|
|
98
|
+
* @param cert certificate
|
|
99
|
+
* @returns if signature is valid, returns the version, otherwise returns `undefined`
|
|
100
|
+
*/
|
|
101
|
+
verifySignaure: (buffer: Buffer, version: string, signature: string, cert: string) => Promisable<boolean>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
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, isUpdateJSON as i, parseVersion as p };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Promisable } from '@subframe7536/type-utils';
|
|
2
|
+
|
|
3
|
+
interface Version {
|
|
4
|
+
major: number;
|
|
5
|
+
minor: number;
|
|
6
|
+
patch: number;
|
|
7
|
+
stage: string;
|
|
8
|
+
stageVersion: number;
|
|
9
|
+
}
|
|
10
|
+
declare function parseVersion(version: string): Version;
|
|
11
|
+
declare function defaultIsLowerVersion(oldVer: string, newVer: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* update info json
|
|
14
|
+
*/
|
|
15
|
+
type UpdateInfo = {
|
|
16
|
+
signature: string;
|
|
17
|
+
minimumVersion: string;
|
|
18
|
+
version: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* {@link UpdateInfo} with beta
|
|
22
|
+
*/
|
|
23
|
+
type UpdateJSON = UpdateInfo & {
|
|
24
|
+
beta: UpdateInfo;
|
|
25
|
+
};
|
|
26
|
+
declare function isUpdateJSON(json: any): json is UpdateJSON;
|
|
27
|
+
declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
|
|
28
|
+
|
|
29
|
+
type URLHandler = (url: URL, isDownloadAsar: boolean) => Promisable<URL | string | undefined | null>;
|
|
30
|
+
type OnDownloading = (progress: DownloadingInfo) => void;
|
|
31
|
+
interface DownloadingInfo {
|
|
32
|
+
/**
|
|
33
|
+
* download delta
|
|
34
|
+
*/
|
|
35
|
+
delta: number;
|
|
36
|
+
/**
|
|
37
|
+
* downloaded percent, 0 ~ 100
|
|
38
|
+
*
|
|
39
|
+
* If not `Content-Length` header, will be nagative
|
|
40
|
+
*/
|
|
41
|
+
percent: number;
|
|
42
|
+
/**
|
|
43
|
+
* total size
|
|
44
|
+
*
|
|
45
|
+
* If not `Content-Length` header, will be -1
|
|
46
|
+
*/
|
|
47
|
+
total: number;
|
|
48
|
+
/**
|
|
49
|
+
* downloaded size
|
|
50
|
+
*/
|
|
51
|
+
transferred: number;
|
|
52
|
+
/**
|
|
53
|
+
* download speed, bytes per second
|
|
54
|
+
*/
|
|
55
|
+
bps: number;
|
|
56
|
+
}
|
|
57
|
+
interface IProvider {
|
|
58
|
+
/**
|
|
59
|
+
* provider name
|
|
60
|
+
*/
|
|
61
|
+
name: string;
|
|
62
|
+
/**
|
|
63
|
+
* custom url handler
|
|
64
|
+
*
|
|
65
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDN links}
|
|
66
|
+
*/
|
|
67
|
+
urlHandler?: URLHandler;
|
|
68
|
+
onDownloading?: OnDownloading;
|
|
69
|
+
/**
|
|
70
|
+
* download update json
|
|
71
|
+
* @param versionPath parsed version path
|
|
72
|
+
*/
|
|
73
|
+
downloadJSON: (versionPath: string) => Promise<UpdateJSON>;
|
|
74
|
+
/**
|
|
75
|
+
* download update asar
|
|
76
|
+
* @param name app name
|
|
77
|
+
* @param updateInfo existing update info
|
|
78
|
+
* @param onDownloading hook for on downloading
|
|
79
|
+
*/
|
|
80
|
+
downloadAsar: (name: string, updateInfo: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void) => Promise<Buffer>;
|
|
81
|
+
/**
|
|
82
|
+
* compare version
|
|
83
|
+
* @param oldVer old version string
|
|
84
|
+
* @param newVer new version string
|
|
85
|
+
* @returns if version1 < version2
|
|
86
|
+
*/
|
|
87
|
+
isLowerVersion: (oldVer: string, newVer: string) => boolean;
|
|
88
|
+
/**
|
|
89
|
+
* unzip file buffer
|
|
90
|
+
* @param buffer source buffer
|
|
91
|
+
*/
|
|
92
|
+
unzipFile: (buffer: Buffer) => Promise<Buffer>;
|
|
93
|
+
/**
|
|
94
|
+
* verify asar signature
|
|
95
|
+
* @param buffer file buffer
|
|
96
|
+
* @param version target version
|
|
97
|
+
* @param signature signature
|
|
98
|
+
* @param cert certificate
|
|
99
|
+
* @returns if signature is valid, returns the version, otherwise returns `undefined`
|
|
100
|
+
*/
|
|
101
|
+
verifySignaure: (buffer: Buffer, version: string, signature: string, cert: string) => Promisable<boolean>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
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, isUpdateJSON as i, parseVersion as p };
|
package/dist/utils.cjs
CHANGED
|
@@ -5,7 +5,13 @@ var path = require('path');
|
|
|
5
5
|
var electron = require('electron');
|
|
6
6
|
var zlib = require('zlib');
|
|
7
7
|
var crypto = require('crypto');
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
12
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
13
|
+
var zlib__default = /*#__PURE__*/_interopDefault(zlib);
|
|
14
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
9
15
|
|
|
10
16
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
11
17
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -17,17 +23,17 @@ var isDev = __EIU_IS_DEV__;
|
|
|
17
23
|
var isWin = process.platform === "win32";
|
|
18
24
|
var isMac = process.platform === "darwin";
|
|
19
25
|
var isLinux = process.platform === "linux";
|
|
20
|
-
function getPathFromAppNameAsar(...
|
|
21
|
-
return isDev ? "DEV.asar" :
|
|
26
|
+
function getPathFromAppNameAsar(...paths) {
|
|
27
|
+
return isDev ? "DEV.asar" : path__default.default.join(path__default.default.dirname(electron.app.getAppPath()), `${electron.app.name}.asar`, ...paths);
|
|
22
28
|
}
|
|
23
29
|
function getAppVersion() {
|
|
24
|
-
return isDev ? getEntryVersion() :
|
|
30
|
+
return isDev ? getEntryVersion() : fs__default.default.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
25
31
|
}
|
|
26
32
|
function getEntryVersion() {
|
|
27
33
|
return electron.app.getVersion();
|
|
28
34
|
}
|
|
29
35
|
function requireNative(moduleName) {
|
|
30
|
-
return __require(
|
|
36
|
+
return __require(path__default.default.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
|
|
31
37
|
}
|
|
32
38
|
function restartApp() {
|
|
33
39
|
electron.app.relaunch();
|
|
@@ -61,9 +67,9 @@ function singleInstance(window) {
|
|
|
61
67
|
return result;
|
|
62
68
|
}
|
|
63
69
|
function setPortableAppDataPath(dirName = "data") {
|
|
64
|
-
const portablePath =
|
|
65
|
-
if (!
|
|
66
|
-
|
|
70
|
+
const portablePath = path__default.default.join(path__default.default.dirname(electron.app.getPath("exe")), dirName);
|
|
71
|
+
if (!fs__default.default.existsSync(portablePath)) {
|
|
72
|
+
fs__default.default.mkdirSync(portablePath);
|
|
67
73
|
}
|
|
68
74
|
electron.app.setPath("appData", portablePath);
|
|
69
75
|
}
|
|
@@ -75,13 +81,13 @@ function loadPage(win, htmlFilePath = "index.html") {
|
|
|
75
81
|
}
|
|
76
82
|
}
|
|
77
83
|
function getPathFromPreload(...paths) {
|
|
78
|
-
return isDev ?
|
|
84
|
+
return isDev ? path__default.default.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
|
|
79
85
|
}
|
|
80
86
|
function getPathFromPublic(...paths) {
|
|
81
|
-
return isDev ?
|
|
87
|
+
return isDev ? path__default.default.join(electron.app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
|
|
82
88
|
}
|
|
83
89
|
function getPathFromEntryAsar(...paths) {
|
|
84
|
-
return
|
|
90
|
+
return path__default.default.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
|
|
85
91
|
}
|
|
86
92
|
function handleUnexpectedErrors(callback) {
|
|
87
93
|
process.on("uncaughtException", callback);
|
|
@@ -89,7 +95,7 @@ function handleUnexpectedErrors(callback) {
|
|
|
89
95
|
}
|
|
90
96
|
async function defaultZipFile(buffer) {
|
|
91
97
|
return new Promise((resolve, reject) => {
|
|
92
|
-
|
|
98
|
+
zlib__default.default.brotliCompress(buffer, (err, buffer2) => {
|
|
93
99
|
if (err) {
|
|
94
100
|
reject(err);
|
|
95
101
|
} else {
|
|
@@ -100,7 +106,7 @@ async function defaultZipFile(buffer) {
|
|
|
100
106
|
}
|
|
101
107
|
async function defaultUnzipFile(buffer) {
|
|
102
108
|
return new Promise((resolve, reject) => {
|
|
103
|
-
|
|
109
|
+
zlib__default.default.brotliDecompress(buffer, (err, buffer2) => {
|
|
104
110
|
if (err) {
|
|
105
111
|
reject(err);
|
|
106
112
|
} else {
|
|
@@ -172,19 +178,19 @@ function defaultVersionJsonGenerator(existingJson, signature, version, minimumVe
|
|
|
172
178
|
return existingJson;
|
|
173
179
|
}
|
|
174
180
|
function hashBuffer(data, length) {
|
|
175
|
-
const hash =
|
|
181
|
+
const hash = crypto__default.default.createHash("SHA256").update(data).digest("binary");
|
|
176
182
|
return Buffer.from(hash).subarray(0, length);
|
|
177
183
|
}
|
|
178
184
|
function aesEncrypt(plainText, key, iv) {
|
|
179
|
-
const cipher =
|
|
185
|
+
const cipher = crypto__default.default.createCipheriv("aes-256-cbc", key, iv);
|
|
180
186
|
return cipher.update(plainText, "utf8", "base64url") + cipher.final("base64url");
|
|
181
187
|
}
|
|
182
188
|
function defaultSignature(buffer, privateKey, cert, version) {
|
|
183
|
-
const sig =
|
|
189
|
+
const sig = crypto__default.default.createSign("RSA-SHA256").update(buffer).sign(crypto__default.default.createPrivateKey(privateKey), "base64");
|
|
184
190
|
return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
|
|
185
191
|
}
|
|
186
192
|
function aesDecrypt(encryptedText, key, iv) {
|
|
187
|
-
const decipher =
|
|
193
|
+
const decipher = crypto__default.default.createDecipheriv("aes-256-cbc", key, iv);
|
|
188
194
|
return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
|
|
189
195
|
}
|
|
190
196
|
function defaultVerifySignature(buffer, version, signature, cert) {
|
|
@@ -193,7 +199,7 @@ function defaultVerifySignature(buffer, version, signature, cert) {
|
|
|
193
199
|
if (ver !== version) {
|
|
194
200
|
return false;
|
|
195
201
|
}
|
|
196
|
-
return
|
|
202
|
+
return crypto__default.default.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
197
203
|
} catch {
|
|
198
204
|
return false;
|
|
199
205
|
}
|
|
@@ -206,10 +212,6 @@ async function autoUpdate(updater) {
|
|
|
206
212
|
}
|
|
207
213
|
}
|
|
208
214
|
|
|
209
|
-
Object.defineProperty(exports, "isCI", {
|
|
210
|
-
enumerable: true,
|
|
211
|
-
get: function () { return ciInfo.isCI; }
|
|
212
|
-
});
|
|
213
215
|
exports.aesDecrypt = aesDecrypt;
|
|
214
216
|
exports.aesEncrypt = aesEncrypt;
|
|
215
217
|
exports.autoUpdate = autoUpdate;
|
package/dist/utils.d.cts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { BrowserWindow } from 'electron';
|
|
2
|
+
export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerifySignature, d as defaultZipFile, h as hashBuffer } from './zip-DPF5IFkK.cjs';
|
|
3
|
+
export { U as UpdateInfo, a as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, i as isUpdateJSON, p as parseVersion } from './types-CItP6bL-.cjs';
|
|
4
|
+
import { U as Updater } from './core-ZUlLHadf.cjs';
|
|
5
|
+
import '@subframe7536/type-utils';
|
|
6
|
+
import 'node:events';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* compile time dev check
|
|
10
|
+
*/
|
|
11
|
+
declare const isDev: boolean;
|
|
12
|
+
declare const isWin: boolean;
|
|
13
|
+
declare const isMac: boolean;
|
|
14
|
+
declare const isLinux: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* get the absolute path of `${electron.app.name}.asar` (not `app.asar`)
|
|
17
|
+
*
|
|
18
|
+
* if is in dev, **always** return `'DEV.asar'`
|
|
19
|
+
*/
|
|
20
|
+
declare function getPathFromAppNameAsar(...paths: string[]): string;
|
|
21
|
+
/**
|
|
22
|
+
* get app version, if is in dev, return `getEntryVersion()`
|
|
23
|
+
*/
|
|
24
|
+
declare function getAppVersion(): string;
|
|
25
|
+
/**
|
|
26
|
+
* get entry version
|
|
27
|
+
*/
|
|
28
|
+
declare function getEntryVersion(): string;
|
|
29
|
+
/**
|
|
30
|
+
* use `require` to load native module from entry
|
|
31
|
+
* @param moduleName file name in entry
|
|
32
|
+
*/
|
|
33
|
+
declare function requireNative<T = any>(moduleName: string): T;
|
|
34
|
+
/**
|
|
35
|
+
* Restarts the Electron app.
|
|
36
|
+
*/
|
|
37
|
+
declare function restartApp(): void;
|
|
38
|
+
/**
|
|
39
|
+
* fix app use model id, only for Windows
|
|
40
|
+
* @param id app id, default is `org.${electron.app.name}`
|
|
41
|
+
*/
|
|
42
|
+
declare function setAppUserModelId(id?: string): void;
|
|
43
|
+
/**
|
|
44
|
+
* disable hardware acceleration for Windows 7
|
|
45
|
+
*/
|
|
46
|
+
declare function disableHWAccForWin7(): void;
|
|
47
|
+
/**
|
|
48
|
+
* keep single electron instance and auto restore window on `second-instance` event
|
|
49
|
+
* @param window brwoser window to show
|
|
50
|
+
* @returns `false` if the app is running
|
|
51
|
+
*/
|
|
52
|
+
declare function singleInstance(window?: BrowserWindow): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* set `AppData` dir to the dir of .exe file
|
|
55
|
+
*
|
|
56
|
+
* useful for portable Windows app
|
|
57
|
+
* @param dirName dir name, default to `data`
|
|
58
|
+
*/
|
|
59
|
+
declare function setPortableAppDataPath(dirName?: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* load `process.env.VITE_DEV_SERVER_URL` when dev, else load html file
|
|
62
|
+
* @param win window
|
|
63
|
+
* @param htmlFilePath html file path, default is `index.html`
|
|
64
|
+
*/
|
|
65
|
+
declare function loadPage(win: BrowserWindow, htmlFilePath?: string): void;
|
|
66
|
+
declare function getPathFromPreload(...paths: string[]): string;
|
|
67
|
+
declare function getPathFromPublic(...paths: string[]): string;
|
|
68
|
+
declare function getPathFromEntryAsar(...paths: string[]): string;
|
|
69
|
+
/**
|
|
70
|
+
* handle all unhandled error
|
|
71
|
+
* @param callback callback function
|
|
72
|
+
*/
|
|
73
|
+
declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* auto check update, download and install
|
|
77
|
+
*/
|
|
78
|
+
declare function autoUpdate(updater: Updater): Promise<void>;
|
|
79
|
+
|
|
80
|
+
export { autoUpdate, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
|