electron-incremental-update 0.9.1 → 1.0.0
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/README.md +159 -111
- package/dist/{chunk-CMBFI77K.mjs → chunk-GB6VLKJZ.mjs} +48 -28
- package/dist/{chunk-5BZLJPHJ.mjs → chunk-GXZSAUBR.mjs} +1 -8
- package/dist/chunk-OUZLSVQC.mjs +148 -0
- package/dist/index.d.mts +102 -80
- package/dist/index.d.ts +102 -80
- package/dist/index.js +134 -71
- package/dist/index.mjs +97 -43
- package/dist/noDep-TvZoKVF8.d.mts +31 -0
- package/dist/noDep-TvZoKVF8.d.ts +31 -0
- package/dist/utils.d.mts +85 -48
- package/dist/utils.d.ts +85 -48
- package/dist/utils.js +127 -86
- package/dist/utils.mjs +14 -20
- package/dist/vite.d.mts +208 -41
- package/dist/vite.d.ts +208 -41
- package/dist/vite.js +243 -122
- package/dist/vite.mjs +220 -98
- package/package.json +18 -11
- package/dist/chunk-SPZL37O5.mjs +0 -124
- package/dist/updateJson-synsK-Pt.d.mts +0 -11
- package/dist/updateJson-synsK-Pt.d.ts +0 -11
package/dist/utils.d.mts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { BrowserWindow } from 'electron';
|
|
2
|
+
export { U as UpdateInfo, a as UpdateJSON, V as Version, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseGithubCdnURL, b as parseVersion } from './noDep-TvZoKVF8.mjs';
|
|
3
|
+
|
|
2
4
|
type Is = {
|
|
3
5
|
dev: boolean;
|
|
4
6
|
win: boolean;
|
|
@@ -9,83 +11,118 @@ type Is = {
|
|
|
9
11
|
* get app info
|
|
10
12
|
*/
|
|
11
13
|
declare const is: Is;
|
|
12
|
-
declare function getLocale(): string | undefined;
|
|
13
14
|
/**
|
|
14
|
-
* get the
|
|
15
|
+
* get the absolute path of `${app.name}.asar` (not `app.asar`)
|
|
16
|
+
*
|
|
15
17
|
* if is in dev, return `'DEV.asar'`
|
|
16
|
-
* @
|
|
18
|
+
* @todo change a better function name or merge into {@link getPaths}
|
|
17
19
|
*/
|
|
18
|
-
declare function
|
|
20
|
+
declare function getPathFromAppNameAsar(...path: string[]): string;
|
|
19
21
|
/**
|
|
20
|
-
* get
|
|
22
|
+
* get versions of App, Entry, Electron, Node and System
|
|
23
|
+
*
|
|
24
|
+
* App version is read from `version` file in `${app.name}.asar`
|
|
25
|
+
*
|
|
26
|
+
* Entry version is read from `package.json`
|
|
27
|
+
*
|
|
28
|
+
* SystemVersion: `${platform} ${os.release()}`
|
|
21
29
|
*/
|
|
22
|
-
declare function
|
|
30
|
+
declare function getVersions(): {
|
|
31
|
+
appVersion: string;
|
|
32
|
+
entryVersion: string;
|
|
33
|
+
electronVersion: string;
|
|
34
|
+
nodeVersion: string;
|
|
35
|
+
systemVersion: string;
|
|
36
|
+
};
|
|
23
37
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* if is dev, return {@link getElectronVersion}
|
|
27
|
-
* @param name - The name of the application
|
|
38
|
+
* load native module from entry
|
|
39
|
+
* @param moduleName file name in entry
|
|
28
40
|
*/
|
|
29
|
-
|
|
30
|
-
declare class NoSuchNativeModuleError extends Error {
|
|
31
|
-
moduleName: string;
|
|
32
|
-
constructor(moduleName: string);
|
|
33
|
-
}
|
|
34
|
-
declare function isNoSuchNativeModuleError(e: unknown): e is NoSuchNativeModuleError;
|
|
41
|
+
type RequireNative = <T = any>(moduleName: string) => T;
|
|
35
42
|
/**
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
43
|
+
* load module from entry, **only for main and preload**
|
|
44
|
+
* @remark use `require`, only support **CommonJS**
|
|
45
|
+
* @param devEntryDirPath entry directory path when dev, default `../../dist-entry`
|
|
46
|
+
* @param entryDirPath entry directory path when not dev, default `join(app.getAppPath(), basename(devEntryDirPath))`
|
|
47
|
+
* @example
|
|
48
|
+
* const requireNative = loadNativeModuleFromEntry()
|
|
49
|
+
* const db = requireNative<typeof import('../native/db')>('db')
|
|
50
|
+
* db.test()
|
|
38
51
|
*/
|
|
39
|
-
declare function
|
|
52
|
+
declare function loadNativeModuleFromEntry(devEntryDirPath?: string, entryDirPath?: string): RequireNative;
|
|
40
53
|
/**
|
|
41
54
|
* Restarts the Electron app.
|
|
42
55
|
*/
|
|
43
56
|
declare function restartApp(): void;
|
|
44
57
|
/**
|
|
45
58
|
* fix app use model id, only for Windows
|
|
46
|
-
* @param id app id
|
|
59
|
+
* @param id app id @default `org.${app.name}`
|
|
47
60
|
*/
|
|
48
|
-
declare function setAppUserModelId(id
|
|
61
|
+
declare function setAppUserModelId(id?: string): void;
|
|
49
62
|
/**
|
|
50
63
|
* disable hardware acceleration for Windows 7
|
|
51
64
|
*/
|
|
52
65
|
declare function disableHWAccForWin7(): void;
|
|
53
66
|
/**
|
|
54
|
-
* keep single electron instance
|
|
67
|
+
* keep single electron instance and auto restore window on `second-instance` event
|
|
68
|
+
* @param window brwoser window to show
|
|
69
|
+
* @returns `false` if the app is running
|
|
55
70
|
*/
|
|
56
|
-
declare function singleInstance():
|
|
71
|
+
declare function singleInstance(window?: BrowserWindow): boolean;
|
|
57
72
|
/**
|
|
58
|
-
* set AppData dir
|
|
73
|
+
* set `AppData` dir to the dir of .exe file
|
|
74
|
+
*
|
|
75
|
+
* useful for portable Windows app
|
|
76
|
+
* @param dirName dir name, default to `data`
|
|
59
77
|
*/
|
|
60
|
-
declare function setPortableAppDataPath(dirName?: string
|
|
78
|
+
declare function setPortableAppDataPath(dirName?: string): void;
|
|
61
79
|
/**
|
|
62
80
|
* ensure app is ready.
|
|
63
81
|
* @param timeout wait timeout, @default 1000
|
|
64
82
|
*/
|
|
65
83
|
declare function waitAppReady(timeout?: number): Promise<void>;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
/**
|
|
85
|
+
* get paths, **only for main and preload**
|
|
86
|
+
* @param entryDirName entry dir name, default to `dist-entry`
|
|
87
|
+
*/
|
|
88
|
+
declare function getPaths(entryDirName?: string): {
|
|
89
|
+
/**
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* devServerURL && win.loadURL(devServerURL)
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
devServerURL: string | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* win.loadFile(indexHTMLPath)
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
indexHTMLPath: string;
|
|
103
|
+
/**
|
|
104
|
+
* get path inside entry asar
|
|
105
|
+
* @param paths joined path
|
|
106
|
+
*/
|
|
107
|
+
getPathFromEntryAsar(...paths: string[]): string;
|
|
108
|
+
/**
|
|
109
|
+
* get path inside `${app.name}.asar/main`
|
|
110
|
+
* @param paths joined path
|
|
111
|
+
*/
|
|
112
|
+
getPathFromMain(...paths: string[]): string;
|
|
113
|
+
/**
|
|
114
|
+
* get path inside `${app.name}.asar/preload`
|
|
115
|
+
* @param paths joined path
|
|
116
|
+
*/
|
|
117
|
+
getPathFromPreload(...paths: string[]): string;
|
|
118
|
+
/**
|
|
119
|
+
* get path inside public dir
|
|
120
|
+
* @param paths joined path
|
|
121
|
+
*/
|
|
122
|
+
getPathFromPublic(...paths: string[]): string;
|
|
123
|
+
};
|
|
75
124
|
|
|
76
125
|
declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
|
|
77
126
|
declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
|
|
78
127
|
|
|
79
|
-
|
|
80
|
-
* parse Github CDN URL for accelerating the speed of downloading
|
|
81
|
-
*
|
|
82
|
-
* {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 some public CDN links}
|
|
83
|
-
*/
|
|
84
|
-
declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, relativeFilePath: string): string;
|
|
85
|
-
/**
|
|
86
|
-
* handle all unhandled error
|
|
87
|
-
* @param callback callback function
|
|
88
|
-
*/
|
|
89
|
-
declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
|
|
90
|
-
|
|
91
|
-
export { DEFAULT_APP_NAME, NoSuchNativeModuleError, type Version, disableHWAccForWin7, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, is, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance, unzipFile, waitAppReady, zipFile };
|
|
128
|
+
export { disableHWAccForWin7, getPathFromAppNameAsar, getPaths, getVersions, is, loadNativeModuleFromEntry, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance, unzipFile, waitAppReady, zipFile };
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { BrowserWindow } from 'electron';
|
|
2
|
+
export { U as UpdateInfo, a as UpdateJSON, V as Version, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseGithubCdnURL, b as parseVersion } from './noDep-TvZoKVF8.js';
|
|
3
|
+
|
|
2
4
|
type Is = {
|
|
3
5
|
dev: boolean;
|
|
4
6
|
win: boolean;
|
|
@@ -9,83 +11,118 @@ type Is = {
|
|
|
9
11
|
* get app info
|
|
10
12
|
*/
|
|
11
13
|
declare const is: Is;
|
|
12
|
-
declare function getLocale(): string | undefined;
|
|
13
14
|
/**
|
|
14
|
-
* get the
|
|
15
|
+
* get the absolute path of `${app.name}.asar` (not `app.asar`)
|
|
16
|
+
*
|
|
15
17
|
* if is in dev, return `'DEV.asar'`
|
|
16
|
-
* @
|
|
18
|
+
* @todo change a better function name or merge into {@link getPaths}
|
|
17
19
|
*/
|
|
18
|
-
declare function
|
|
20
|
+
declare function getPathFromAppNameAsar(...path: string[]): string;
|
|
19
21
|
/**
|
|
20
|
-
* get
|
|
22
|
+
* get versions of App, Entry, Electron, Node and System
|
|
23
|
+
*
|
|
24
|
+
* App version is read from `version` file in `${app.name}.asar`
|
|
25
|
+
*
|
|
26
|
+
* Entry version is read from `package.json`
|
|
27
|
+
*
|
|
28
|
+
* SystemVersion: `${platform} ${os.release()}`
|
|
21
29
|
*/
|
|
22
|
-
declare function
|
|
30
|
+
declare function getVersions(): {
|
|
31
|
+
appVersion: string;
|
|
32
|
+
entryVersion: string;
|
|
33
|
+
electronVersion: string;
|
|
34
|
+
nodeVersion: string;
|
|
35
|
+
systemVersion: string;
|
|
36
|
+
};
|
|
23
37
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* if is dev, return {@link getElectronVersion}
|
|
27
|
-
* @param name - The name of the application
|
|
38
|
+
* load native module from entry
|
|
39
|
+
* @param moduleName file name in entry
|
|
28
40
|
*/
|
|
29
|
-
|
|
30
|
-
declare class NoSuchNativeModuleError extends Error {
|
|
31
|
-
moduleName: string;
|
|
32
|
-
constructor(moduleName: string);
|
|
33
|
-
}
|
|
34
|
-
declare function isNoSuchNativeModuleError(e: unknown): e is NoSuchNativeModuleError;
|
|
41
|
+
type RequireNative = <T = any>(moduleName: string) => T;
|
|
35
42
|
/**
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
43
|
+
* load module from entry, **only for main and preload**
|
|
44
|
+
* @remark use `require`, only support **CommonJS**
|
|
45
|
+
* @param devEntryDirPath entry directory path when dev, default `../../dist-entry`
|
|
46
|
+
* @param entryDirPath entry directory path when not dev, default `join(app.getAppPath(), basename(devEntryDirPath))`
|
|
47
|
+
* @example
|
|
48
|
+
* const requireNative = loadNativeModuleFromEntry()
|
|
49
|
+
* const db = requireNative<typeof import('../native/db')>('db')
|
|
50
|
+
* db.test()
|
|
38
51
|
*/
|
|
39
|
-
declare function
|
|
52
|
+
declare function loadNativeModuleFromEntry(devEntryDirPath?: string, entryDirPath?: string): RequireNative;
|
|
40
53
|
/**
|
|
41
54
|
* Restarts the Electron app.
|
|
42
55
|
*/
|
|
43
56
|
declare function restartApp(): void;
|
|
44
57
|
/**
|
|
45
58
|
* fix app use model id, only for Windows
|
|
46
|
-
* @param id app id
|
|
59
|
+
* @param id app id @default `org.${app.name}`
|
|
47
60
|
*/
|
|
48
|
-
declare function setAppUserModelId(id
|
|
61
|
+
declare function setAppUserModelId(id?: string): void;
|
|
49
62
|
/**
|
|
50
63
|
* disable hardware acceleration for Windows 7
|
|
51
64
|
*/
|
|
52
65
|
declare function disableHWAccForWin7(): void;
|
|
53
66
|
/**
|
|
54
|
-
* keep single electron instance
|
|
67
|
+
* keep single electron instance and auto restore window on `second-instance` event
|
|
68
|
+
* @param window brwoser window to show
|
|
69
|
+
* @returns `false` if the app is running
|
|
55
70
|
*/
|
|
56
|
-
declare function singleInstance():
|
|
71
|
+
declare function singleInstance(window?: BrowserWindow): boolean;
|
|
57
72
|
/**
|
|
58
|
-
* set AppData dir
|
|
73
|
+
* set `AppData` dir to the dir of .exe file
|
|
74
|
+
*
|
|
75
|
+
* useful for portable Windows app
|
|
76
|
+
* @param dirName dir name, default to `data`
|
|
59
77
|
*/
|
|
60
|
-
declare function setPortableAppDataPath(dirName?: string
|
|
78
|
+
declare function setPortableAppDataPath(dirName?: string): void;
|
|
61
79
|
/**
|
|
62
80
|
* ensure app is ready.
|
|
63
81
|
* @param timeout wait timeout, @default 1000
|
|
64
82
|
*/
|
|
65
83
|
declare function waitAppReady(timeout?: number): Promise<void>;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
/**
|
|
85
|
+
* get paths, **only for main and preload**
|
|
86
|
+
* @param entryDirName entry dir name, default to `dist-entry`
|
|
87
|
+
*/
|
|
88
|
+
declare function getPaths(entryDirName?: string): {
|
|
89
|
+
/**
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* devServerURL && win.loadURL(devServerURL)
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
devServerURL: string | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* win.loadFile(indexHTMLPath)
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
indexHTMLPath: string;
|
|
103
|
+
/**
|
|
104
|
+
* get path inside entry asar
|
|
105
|
+
* @param paths joined path
|
|
106
|
+
*/
|
|
107
|
+
getPathFromEntryAsar(...paths: string[]): string;
|
|
108
|
+
/**
|
|
109
|
+
* get path inside `${app.name}.asar/main`
|
|
110
|
+
* @param paths joined path
|
|
111
|
+
*/
|
|
112
|
+
getPathFromMain(...paths: string[]): string;
|
|
113
|
+
/**
|
|
114
|
+
* get path inside `${app.name}.asar/preload`
|
|
115
|
+
* @param paths joined path
|
|
116
|
+
*/
|
|
117
|
+
getPathFromPreload(...paths: string[]): string;
|
|
118
|
+
/**
|
|
119
|
+
* get path inside public dir
|
|
120
|
+
* @param paths joined path
|
|
121
|
+
*/
|
|
122
|
+
getPathFromPublic(...paths: string[]): string;
|
|
123
|
+
};
|
|
75
124
|
|
|
76
125
|
declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
|
|
77
126
|
declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
|
|
78
127
|
|
|
79
|
-
|
|
80
|
-
* parse Github CDN URL for accelerating the speed of downloading
|
|
81
|
-
*
|
|
82
|
-
* {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 some public CDN links}
|
|
83
|
-
*/
|
|
84
|
-
declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, relativeFilePath: string): string;
|
|
85
|
-
/**
|
|
86
|
-
* handle all unhandled error
|
|
87
|
-
* @param callback callback function
|
|
88
|
-
*/
|
|
89
|
-
declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
|
|
90
|
-
|
|
91
|
-
export { DEFAULT_APP_NAME, NoSuchNativeModuleError, type Version, disableHWAccForWin7, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, is, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance, unzipFile, waitAppReady, zipFile };
|
|
128
|
+
export { disableHWAccForWin7, getPathFromAppNameAsar, getPaths, getVersions, is, loadNativeModuleFromEntry, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance, unzipFile, waitAppReady, zipFile };
|
package/dist/utils.js
CHANGED
|
@@ -20,19 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/utils/index.ts
|
|
21
21
|
var utils_exports = {};
|
|
22
22
|
__export(utils_exports, {
|
|
23
|
-
DEFAULT_APP_NAME: () => DEFAULT_APP_NAME,
|
|
24
|
-
NoSuchNativeModuleError: () => NoSuchNativeModuleError,
|
|
25
23
|
disableHWAccForWin7: () => disableHWAccForWin7,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
getProductAsarPath: () => getProductAsarPath,
|
|
24
|
+
getPathFromAppNameAsar: () => getPathFromAppNameAsar,
|
|
25
|
+
getPaths: () => getPaths,
|
|
26
|
+
getVersions: () => getVersions,
|
|
30
27
|
handleUnexpectedErrors: () => handleUnexpectedErrors,
|
|
31
28
|
is: () => is,
|
|
32
|
-
|
|
29
|
+
isUpdateJSON: () => isUpdateJSON,
|
|
30
|
+
loadNativeModuleFromEntry: () => loadNativeModuleFromEntry,
|
|
33
31
|
parseGithubCdnURL: () => parseGithubCdnURL,
|
|
34
32
|
parseVersion: () => parseVersion,
|
|
35
|
-
requireNative: () => requireNative,
|
|
36
33
|
restartApp: () => restartApp,
|
|
37
34
|
setAppUserModelId: () => setAppUserModelId,
|
|
38
35
|
setPortableAppDataPath: () => setPortableAppDataPath,
|
|
@@ -43,79 +40,71 @@ __export(utils_exports, {
|
|
|
43
40
|
});
|
|
44
41
|
module.exports = __toCommonJS(utils_exports);
|
|
45
42
|
|
|
46
|
-
// src/utils/
|
|
43
|
+
// src/utils/electron.ts
|
|
47
44
|
var import_node_fs = require("fs");
|
|
48
45
|
var import_node_path = require("path");
|
|
49
46
|
var import_node_os = require("os");
|
|
50
47
|
var import_electron = require("electron");
|
|
51
|
-
var DEFAULT_APP_NAME = "product";
|
|
52
48
|
var is = {
|
|
53
49
|
dev: !import_electron.app.isPackaged,
|
|
54
50
|
win: process.platform === "win32",
|
|
55
51
|
mac: process.platform === "darwin",
|
|
56
52
|
linux: process.platform === "linux"
|
|
57
53
|
};
|
|
58
|
-
function
|
|
59
|
-
return
|
|
54
|
+
function getPathFromAppNameAsar(...path) {
|
|
55
|
+
return is.dev ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${import_electron.app.name}.asar`, ...path);
|
|
60
56
|
}
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
57
|
+
function getVersions() {
|
|
58
|
+
const platform = is.win ? "Windows" : is.mac ? "MacOS" : process.platform.toUpperCase();
|
|
59
|
+
return {
|
|
60
|
+
appVersion: is.dev ? import_electron.app.getVersion() : (0, import_node_fs.readFileSync)(getPathFromAppNameAsar("version"), "utf-8"),
|
|
61
|
+
entryVersion: import_electron.app.getVersion(),
|
|
62
|
+
electronVersion: process.versions.electron,
|
|
63
|
+
nodeVersion: process.versions.node,
|
|
64
|
+
systemVersion: `${platform} ${(0, import_node_os.release)()}`
|
|
65
|
+
};
|
|
69
66
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
function requireNative(packageName) {
|
|
81
|
-
const path = import_electron.app.isPackaged ? (0, import_node_path.join)(import_electron.app.getAppPath(), "node_modules", packageName) : packageName;
|
|
82
|
-
try {
|
|
83
|
-
return require(path);
|
|
84
|
-
} catch (error) {
|
|
85
|
-
return new NoSuchNativeModuleError(packageName);
|
|
86
|
-
}
|
|
67
|
+
function loadNativeModuleFromEntry(devEntryDirPath = "../../dist-entry", entryDirPath = (0, import_node_path.join)(import_electron.app.getAppPath(), (0, import_node_path.basename)(devEntryDirPath))) {
|
|
68
|
+
const path = is.dev ? devEntryDirPath : entryDirPath;
|
|
69
|
+
return (moduleName) => {
|
|
70
|
+
try {
|
|
71
|
+
return require((0, import_node_path.join)(path, moduleName));
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error("fail to load module", error);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
87
76
|
}
|
|
88
77
|
function restartApp() {
|
|
89
78
|
import_electron.app.relaunch();
|
|
90
79
|
import_electron.app.quit();
|
|
91
80
|
}
|
|
92
81
|
function setAppUserModelId(id) {
|
|
93
|
-
|
|
82
|
+
import_electron.app.setAppUserModelId(is.dev ? process.execPath : id ?? `org.${import_electron.app.name}`);
|
|
94
83
|
}
|
|
95
84
|
function disableHWAccForWin7() {
|
|
96
85
|
if ((0, import_node_os.release)().startsWith("6.1")) {
|
|
97
86
|
import_electron.app.disableHardwareAcceleration();
|
|
98
87
|
}
|
|
99
88
|
}
|
|
100
|
-
function singleInstance() {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
89
|
+
function singleInstance(window) {
|
|
90
|
+
const result = import_electron.app.requestSingleInstanceLock();
|
|
91
|
+
result ? import_electron.app.on("second-instance", () => {
|
|
92
|
+
if (window) {
|
|
93
|
+
window.show();
|
|
94
|
+
if (window.isMinimized()) {
|
|
95
|
+
window.restore();
|
|
96
|
+
}
|
|
97
|
+
window.focus();
|
|
98
|
+
}
|
|
99
|
+
}) : import_electron.app.quit();
|
|
100
|
+
return result;
|
|
105
101
|
}
|
|
106
|
-
function setPortableAppDataPath(dirName = "data"
|
|
107
|
-
if (!is.win) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
102
|
+
function setPortableAppDataPath(dirName = "data") {
|
|
110
103
|
const portablePath = (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getPath("exe")), dirName);
|
|
111
|
-
|
|
112
|
-
if (create && !exists) {
|
|
104
|
+
if (!(0, import_node_fs.existsSync)(portablePath)) {
|
|
113
105
|
(0, import_node_fs.mkdirSync)(portablePath);
|
|
114
|
-
exists = true;
|
|
115
|
-
}
|
|
116
|
-
if (exists) {
|
|
117
|
-
import_electron.app.setPath("appData", portablePath);
|
|
118
106
|
}
|
|
107
|
+
import_electron.app.setPath("appData", portablePath);
|
|
119
108
|
}
|
|
120
109
|
function waitAppReady(timeout = 1e3) {
|
|
121
110
|
return import_electron.app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
|
|
@@ -128,31 +117,58 @@ function waitAppReady(timeout = 1e3) {
|
|
|
128
117
|
});
|
|
129
118
|
});
|
|
130
119
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
120
|
+
function getPaths(entryDirName = "dist-entry") {
|
|
121
|
+
const root = (0, import_node_path.join)(__dirname, "..");
|
|
122
|
+
const mainDirPath = (0, import_node_path.join)(root, "main");
|
|
123
|
+
const preloadDirPath = (0, import_node_path.join)(root, "preload");
|
|
124
|
+
const rendererDirPath = (0, import_node_path.join)(root, "renderer");
|
|
125
|
+
const devServerURL = process.env.VITE_DEV_SERVER_URL;
|
|
126
|
+
const indexHTMLPath = (0, import_node_path.join)(rendererDirPath, "index.html");
|
|
127
|
+
const publicDirPath = devServerURL ? (0, import_node_path.join)(root, "../public") : rendererDirPath;
|
|
128
|
+
return {
|
|
129
|
+
/**
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* devServerURL && win.loadURL(devServerURL)
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
devServerURL,
|
|
136
|
+
/**
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* win.loadFile(indexHTMLPath)
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
indexHTMLPath,
|
|
143
|
+
/**
|
|
144
|
+
* get path inside entry asar
|
|
145
|
+
* @param paths joined path
|
|
146
|
+
*/
|
|
147
|
+
getPathFromEntryAsar(...paths) {
|
|
148
|
+
return (0, import_node_path.join)(import_electron.app.getAppPath(), entryDirName, ...paths);
|
|
149
|
+
},
|
|
150
|
+
/**
|
|
151
|
+
* get path inside `${app.name}.asar/main`
|
|
152
|
+
* @param paths joined path
|
|
153
|
+
*/
|
|
154
|
+
getPathFromMain(...paths) {
|
|
155
|
+
return (0, import_node_path.join)(mainDirPath, ...paths);
|
|
156
|
+
},
|
|
157
|
+
/**
|
|
158
|
+
* get path inside `${app.name}.asar/preload`
|
|
159
|
+
* @param paths joined path
|
|
160
|
+
*/
|
|
161
|
+
getPathFromPreload(...paths) {
|
|
162
|
+
return (0, import_node_path.join)(preloadDirPath, ...paths);
|
|
163
|
+
},
|
|
164
|
+
/**
|
|
165
|
+
* get path inside public dir
|
|
166
|
+
* @param paths joined path
|
|
167
|
+
*/
|
|
168
|
+
getPathFromPublic(...paths) {
|
|
169
|
+
return (0, import_node_path.join)(publicDirPath, ...paths);
|
|
170
|
+
}
|
|
146
171
|
};
|
|
147
|
-
if (match[4]) {
|
|
148
|
-
let [stage, _v] = match[4].split(".");
|
|
149
|
-
ret.stage = stage;
|
|
150
|
-
ret.stageVersion = Number(_v) || -1;
|
|
151
|
-
}
|
|
152
|
-
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
153
|
-
throw new TypeError(`invalid version: ${version}`);
|
|
154
|
-
}
|
|
155
|
-
return ret;
|
|
156
172
|
}
|
|
157
173
|
|
|
158
174
|
// src/utils/zip.ts
|
|
@@ -190,7 +206,7 @@ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
|
190
206
|
});
|
|
191
207
|
}
|
|
192
208
|
|
|
193
|
-
// src/utils/
|
|
209
|
+
// src/utils/noDep.ts
|
|
194
210
|
function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
195
211
|
if (!originRepoURL.startsWith("https://github.com/")) {
|
|
196
212
|
throw new Error("origin url must start with https://github.com/");
|
|
@@ -204,21 +220,46 @@ function handleUnexpectedErrors(callback) {
|
|
|
204
220
|
process.on("uncaughtException", callback);
|
|
205
221
|
process.on("unhandledRejection", callback);
|
|
206
222
|
}
|
|
223
|
+
function parseVersion(version) {
|
|
224
|
+
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
|
|
225
|
+
const match = semver.exec(version);
|
|
226
|
+
if (!match) {
|
|
227
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
228
|
+
}
|
|
229
|
+
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
230
|
+
const ret = {
|
|
231
|
+
major,
|
|
232
|
+
minor,
|
|
233
|
+
patch,
|
|
234
|
+
stage: "",
|
|
235
|
+
stageVersion: -1
|
|
236
|
+
};
|
|
237
|
+
if (match[4]) {
|
|
238
|
+
let [stage, _v] = match[4].split(".");
|
|
239
|
+
ret.stage = stage;
|
|
240
|
+
ret.stageVersion = Number(_v) || -1;
|
|
241
|
+
}
|
|
242
|
+
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
243
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
244
|
+
}
|
|
245
|
+
return ret;
|
|
246
|
+
}
|
|
247
|
+
function isUpdateJSON(json) {
|
|
248
|
+
const is2 = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
|
|
249
|
+
return is2(json) && is2(json?.beta);
|
|
250
|
+
}
|
|
207
251
|
// Annotate the CommonJS export names for ESM import in node:
|
|
208
252
|
0 && (module.exports = {
|
|
209
|
-
DEFAULT_APP_NAME,
|
|
210
|
-
NoSuchNativeModuleError,
|
|
211
253
|
disableHWAccForWin7,
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
getProductAsarPath,
|
|
254
|
+
getPathFromAppNameAsar,
|
|
255
|
+
getPaths,
|
|
256
|
+
getVersions,
|
|
216
257
|
handleUnexpectedErrors,
|
|
217
258
|
is,
|
|
218
|
-
|
|
259
|
+
isUpdateJSON,
|
|
260
|
+
loadNativeModuleFromEntry,
|
|
219
261
|
parseGithubCdnURL,
|
|
220
262
|
parseVersion,
|
|
221
|
-
requireNative,
|
|
222
263
|
restartApp,
|
|
223
264
|
setAppUserModelId,
|
|
224
265
|
setPortableAppDataPath,
|