electron-incremental-update 1.0.3 → 1.2.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 +569 -535
- package/dist/chunk-7ET4GMTZ.js +236 -0
- package/dist/{chunk-OUZLSVQC.mjs → chunk-CXHA5TF7.js} +92 -4
- package/dist/chunk-HWUYTDEF.js +236 -0
- package/dist/chunk-RQCTJY4L.js +236 -0
- package/dist/{index.mjs → index.cjs} +197 -70
- package/dist/{index.d.mts → index.d.cts} +19 -28
- package/dist/index.d.ts +19 -28
- package/dist/index.js +78 -189
- package/dist/utils.cjs +270 -0
- package/dist/{utils.d.mts → utils.d.cts} +13 -15
- package/dist/utils.d.ts +13 -15
- package/dist/utils.js +21 -253
- package/dist/vite.d.ts +59 -16
- package/dist/vite.js +528 -180
- package/package.json +30 -28
- package/utils.js +1 -1
- package/dist/chunk-GB6VLKJZ.mjs +0 -95
- package/dist/chunk-GXZSAUBR.mjs +0 -36
- package/dist/utils.mjs +0 -40
- package/dist/vite.d.mts +0 -329
- package/dist/vite.mjs +0 -404
- /package/dist/{noDep-TvZoKVF8.d.mts → pure-GoN_3MEj.d.cts} +0 -0
- /package/dist/{noDep-TvZoKVF8.d.ts → pure-GoN_3MEj.d.ts} +0 -0
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/utils/index.ts
|
|
21
|
+
var utils_exports = {};
|
|
22
|
+
__export(utils_exports, {
|
|
23
|
+
disableHWAccForWin7: () => disableHWAccForWin7,
|
|
24
|
+
getPathFromAppNameAsar: () => getPathFromAppNameAsar,
|
|
25
|
+
getPaths: () => getPaths,
|
|
26
|
+
getVersions: () => getVersions,
|
|
27
|
+
handleUnexpectedErrors: () => handleUnexpectedErrors,
|
|
28
|
+
is: () => is,
|
|
29
|
+
isUpdateJSON: () => isUpdateJSON,
|
|
30
|
+
loadNativeModuleFromEntry: () => loadNativeModuleFromEntry,
|
|
31
|
+
parseGithubCdnURL: () => parseGithubCdnURL,
|
|
32
|
+
parseVersion: () => parseVersion,
|
|
33
|
+
restartApp: () => restartApp,
|
|
34
|
+
setAppUserModelId: () => setAppUserModelId,
|
|
35
|
+
setPortableAppDataPath: () => setPortableAppDataPath,
|
|
36
|
+
singleInstance: () => singleInstance,
|
|
37
|
+
unzipFile: () => unzipFile,
|
|
38
|
+
waitAppReady: () => waitAppReady,
|
|
39
|
+
zipFile: () => zipFile
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(utils_exports);
|
|
42
|
+
|
|
43
|
+
// src/utils/electron.ts
|
|
44
|
+
var import_node_fs = require("fs");
|
|
45
|
+
var import_node_path = require("path");
|
|
46
|
+
var import_node_os = require("os");
|
|
47
|
+
var import_electron = require("electron");
|
|
48
|
+
var is = {
|
|
49
|
+
dev: !import_electron.app.isPackaged,
|
|
50
|
+
win: process.platform === "win32",
|
|
51
|
+
mac: process.platform === "darwin",
|
|
52
|
+
linux: process.platform === "linux"
|
|
53
|
+
};
|
|
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);
|
|
56
|
+
}
|
|
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
|
+
};
|
|
66
|
+
}
|
|
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
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function restartApp() {
|
|
78
|
+
import_electron.app.relaunch();
|
|
79
|
+
import_electron.app.quit();
|
|
80
|
+
}
|
|
81
|
+
function setAppUserModelId(id) {
|
|
82
|
+
import_electron.app.setAppUserModelId(is.dev ? process.execPath : id ?? `org.${import_electron.app.name}`);
|
|
83
|
+
}
|
|
84
|
+
function disableHWAccForWin7() {
|
|
85
|
+
if ((0, import_node_os.release)().startsWith("6.1")) {
|
|
86
|
+
import_electron.app.disableHardwareAcceleration();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
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;
|
|
101
|
+
}
|
|
102
|
+
function setPortableAppDataPath(dirName = "data") {
|
|
103
|
+
const portablePath = (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getPath("exe")), dirName);
|
|
104
|
+
if (!(0, import_node_fs.existsSync)(portablePath)) {
|
|
105
|
+
(0, import_node_fs.mkdirSync)(portablePath);
|
|
106
|
+
}
|
|
107
|
+
import_electron.app.setPath("appData", portablePath);
|
|
108
|
+
}
|
|
109
|
+
function waitAppReady(timeout = 1e3) {
|
|
110
|
+
return import_electron.app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
|
|
111
|
+
const _ = setTimeout(() => {
|
|
112
|
+
reject(new Error("app is not ready"));
|
|
113
|
+
}, timeout);
|
|
114
|
+
import_electron.app.whenReady().then(() => {
|
|
115
|
+
clearTimeout(_);
|
|
116
|
+
resolve();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
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 `${electron.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 `${electron.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
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/utils/zip.ts
|
|
175
|
+
var import_node_fs2 = require("fs");
|
|
176
|
+
var import_node_zlib = require("zlib");
|
|
177
|
+
async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
178
|
+
if (!(0, import_node_fs2.existsSync)(gzipPath)) {
|
|
179
|
+
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
180
|
+
}
|
|
181
|
+
const compressedBuffer = (0, import_node_fs2.readFileSync)(gzipPath);
|
|
182
|
+
return new Promise((resolve, reject) => {
|
|
183
|
+
(0, import_node_zlib.brotliDecompress)(compressedBuffer, (err, buffer) => {
|
|
184
|
+
(0, import_node_fs2.rmSync)(gzipPath);
|
|
185
|
+
if (err) {
|
|
186
|
+
reject(err);
|
|
187
|
+
}
|
|
188
|
+
(0, import_node_fs2.writeFileSync)(targetFilePath, buffer);
|
|
189
|
+
resolve(null);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
194
|
+
if (!(0, import_node_fs2.existsSync)(filePath)) {
|
|
195
|
+
throw new Error(`path to be zipped not exist: ${filePath}`);
|
|
196
|
+
}
|
|
197
|
+
const buffer = (0, import_node_fs2.readFileSync)(filePath);
|
|
198
|
+
return new Promise((resolve, reject) => {
|
|
199
|
+
(0, import_node_zlib.brotliCompress)(buffer, (err, buffer2) => {
|
|
200
|
+
if (err) {
|
|
201
|
+
reject(err);
|
|
202
|
+
}
|
|
203
|
+
(0, import_node_fs2.writeFileSync)(targetFilePath, buffer2);
|
|
204
|
+
resolve(null);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/utils/pure.ts
|
|
210
|
+
function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
211
|
+
if (!originRepoURL.startsWith("https://github.com/")) {
|
|
212
|
+
throw new Error("origin url must start with https://github.com/");
|
|
213
|
+
}
|
|
214
|
+
originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
|
|
215
|
+
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
216
|
+
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
217
|
+
return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
218
|
+
}
|
|
219
|
+
function handleUnexpectedErrors(callback) {
|
|
220
|
+
process.on("uncaughtException", callback);
|
|
221
|
+
process.on("unhandledRejection", callback);
|
|
222
|
+
}
|
|
223
|
+
function parseVersion(version) {
|
|
224
|
+
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-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
|
+
}
|
|
251
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
252
|
+
0 && (module.exports = {
|
|
253
|
+
disableHWAccForWin7,
|
|
254
|
+
getPathFromAppNameAsar,
|
|
255
|
+
getPaths,
|
|
256
|
+
getVersions,
|
|
257
|
+
handleUnexpectedErrors,
|
|
258
|
+
is,
|
|
259
|
+
isUpdateJSON,
|
|
260
|
+
loadNativeModuleFromEntry,
|
|
261
|
+
parseGithubCdnURL,
|
|
262
|
+
parseVersion,
|
|
263
|
+
restartApp,
|
|
264
|
+
setAppUserModelId,
|
|
265
|
+
setPortableAppDataPath,
|
|
266
|
+
singleInstance,
|
|
267
|
+
unzipFile,
|
|
268
|
+
waitAppReady,
|
|
269
|
+
zipFile
|
|
270
|
+
});
|
|
@@ -1,27 +1,25 @@
|
|
|
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 './
|
|
2
|
+
export { U as UpdateInfo, a as UpdateJSON, V as Version, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseGithubCdnURL, b as parseVersion } from './pure-GoN_3MEj.cjs';
|
|
3
3
|
|
|
4
|
-
type Is = {
|
|
5
|
-
dev: boolean;
|
|
6
|
-
win: boolean;
|
|
7
|
-
mac: boolean;
|
|
8
|
-
linux: boolean;
|
|
9
|
-
};
|
|
10
4
|
/**
|
|
11
|
-
*
|
|
5
|
+
* app info
|
|
12
6
|
*/
|
|
13
|
-
declare const is:
|
|
7
|
+
declare const is: {
|
|
8
|
+
readonly dev: boolean;
|
|
9
|
+
readonly win: boolean;
|
|
10
|
+
readonly mac: boolean;
|
|
11
|
+
readonly linux: boolean;
|
|
12
|
+
};
|
|
14
13
|
/**
|
|
15
|
-
* get the absolute path of `${app.name}.asar` (not `app.asar`)
|
|
14
|
+
* get the absolute path of `${electron.app.name}.asar` (not `app.asar`)
|
|
16
15
|
*
|
|
17
16
|
* if is in dev, return `'DEV.asar'`
|
|
18
|
-
* @todo change a better function name or merge into {@link getPaths}
|
|
19
17
|
*/
|
|
20
18
|
declare function getPathFromAppNameAsar(...path: string[]): string;
|
|
21
19
|
/**
|
|
22
20
|
* get versions of App, Entry, Electron, Node and System
|
|
23
21
|
*
|
|
24
|
-
* App version is read from `version` file in `${app.name}.asar`
|
|
22
|
+
* App version is read from `version` file in `${electron.app.name}.asar`
|
|
25
23
|
*
|
|
26
24
|
* Entry version is read from `package.json`
|
|
27
25
|
*
|
|
@@ -56,7 +54,7 @@ declare function loadNativeModuleFromEntry(devEntryDirPath?: string, entryDirPat
|
|
|
56
54
|
declare function restartApp(): void;
|
|
57
55
|
/**
|
|
58
56
|
* fix app use model id, only for Windows
|
|
59
|
-
* @param id app id @default `org.${app.name}`
|
|
57
|
+
* @param id app id @default `org.${electron.app.name}`
|
|
60
58
|
*/
|
|
61
59
|
declare function setAppUserModelId(id?: string): void;
|
|
62
60
|
/**
|
|
@@ -106,12 +104,12 @@ declare function getPaths(entryDirName?: string): {
|
|
|
106
104
|
*/
|
|
107
105
|
getPathFromEntryAsar(...paths: string[]): string;
|
|
108
106
|
/**
|
|
109
|
-
* get path inside `${app.name}.asar/main`
|
|
107
|
+
* get path inside `${electron.app.name}.asar/main`
|
|
110
108
|
* @param paths joined path
|
|
111
109
|
*/
|
|
112
110
|
getPathFromMain(...paths: string[]): string;
|
|
113
111
|
/**
|
|
114
|
-
* get path inside `${app.name}.asar/preload`
|
|
112
|
+
* get path inside `${electron.app.name}.asar/preload`
|
|
115
113
|
* @param paths joined path
|
|
116
114
|
*/
|
|
117
115
|
getPathFromPreload(...paths: string[]): string;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
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 './
|
|
2
|
+
export { U as UpdateInfo, a as UpdateJSON, V as Version, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseGithubCdnURL, b as parseVersion } from './pure-GoN_3MEj.js';
|
|
3
3
|
|
|
4
|
-
type Is = {
|
|
5
|
-
dev: boolean;
|
|
6
|
-
win: boolean;
|
|
7
|
-
mac: boolean;
|
|
8
|
-
linux: boolean;
|
|
9
|
-
};
|
|
10
4
|
/**
|
|
11
|
-
*
|
|
5
|
+
* app info
|
|
12
6
|
*/
|
|
13
|
-
declare const is:
|
|
7
|
+
declare const is: {
|
|
8
|
+
readonly dev: boolean;
|
|
9
|
+
readonly win: boolean;
|
|
10
|
+
readonly mac: boolean;
|
|
11
|
+
readonly linux: boolean;
|
|
12
|
+
};
|
|
14
13
|
/**
|
|
15
|
-
* get the absolute path of `${app.name}.asar` (not `app.asar`)
|
|
14
|
+
* get the absolute path of `${electron.app.name}.asar` (not `app.asar`)
|
|
16
15
|
*
|
|
17
16
|
* if is in dev, return `'DEV.asar'`
|
|
18
|
-
* @todo change a better function name or merge into {@link getPaths}
|
|
19
17
|
*/
|
|
20
18
|
declare function getPathFromAppNameAsar(...path: string[]): string;
|
|
21
19
|
/**
|
|
22
20
|
* get versions of App, Entry, Electron, Node and System
|
|
23
21
|
*
|
|
24
|
-
* App version is read from `version` file in `${app.name}.asar`
|
|
22
|
+
* App version is read from `version` file in `${electron.app.name}.asar`
|
|
25
23
|
*
|
|
26
24
|
* Entry version is read from `package.json`
|
|
27
25
|
*
|
|
@@ -56,7 +54,7 @@ declare function loadNativeModuleFromEntry(devEntryDirPath?: string, entryDirPat
|
|
|
56
54
|
declare function restartApp(): void;
|
|
57
55
|
/**
|
|
58
56
|
* fix app use model id, only for Windows
|
|
59
|
-
* @param id app id @default `org.${app.name}`
|
|
57
|
+
* @param id app id @default `org.${electron.app.name}`
|
|
60
58
|
*/
|
|
61
59
|
declare function setAppUserModelId(id?: string): void;
|
|
62
60
|
/**
|
|
@@ -106,12 +104,12 @@ declare function getPaths(entryDirName?: string): {
|
|
|
106
104
|
*/
|
|
107
105
|
getPathFromEntryAsar(...paths: string[]): string;
|
|
108
106
|
/**
|
|
109
|
-
* get path inside `${app.name}.asar/main`
|
|
107
|
+
* get path inside `${electron.app.name}.asar/main`
|
|
110
108
|
* @param paths joined path
|
|
111
109
|
*/
|
|
112
110
|
getPathFromMain(...paths: string[]): string;
|
|
113
111
|
/**
|
|
114
|
-
* get path inside `${app.name}.asar/preload`
|
|
112
|
+
* get path inside `${electron.app.name}.asar/preload`
|
|
115
113
|
* @param paths joined path
|
|
116
114
|
*/
|
|
117
115
|
getPathFromPreload(...paths: string[]): string;
|
package/dist/utils.js
CHANGED
|
@@ -1,255 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/utils/index.ts
|
|
21
|
-
var utils_exports = {};
|
|
22
|
-
__export(utils_exports, {
|
|
23
|
-
disableHWAccForWin7: () => disableHWAccForWin7,
|
|
24
|
-
getPathFromAppNameAsar: () => getPathFromAppNameAsar,
|
|
25
|
-
getPaths: () => getPaths,
|
|
26
|
-
getVersions: () => getVersions,
|
|
27
|
-
handleUnexpectedErrors: () => handleUnexpectedErrors,
|
|
28
|
-
is: () => is,
|
|
29
|
-
isUpdateJSON: () => isUpdateJSON,
|
|
30
|
-
loadNativeModuleFromEntry: () => loadNativeModuleFromEntry,
|
|
31
|
-
parseGithubCdnURL: () => parseGithubCdnURL,
|
|
32
|
-
parseVersion: () => parseVersion,
|
|
33
|
-
restartApp: () => restartApp,
|
|
34
|
-
setAppUserModelId: () => setAppUserModelId,
|
|
35
|
-
setPortableAppDataPath: () => setPortableAppDataPath,
|
|
36
|
-
singleInstance: () => singleInstance,
|
|
37
|
-
unzipFile: () => unzipFile,
|
|
38
|
-
waitAppReady: () => waitAppReady,
|
|
39
|
-
zipFile: () => zipFile
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(utils_exports);
|
|
42
|
-
|
|
43
|
-
// src/utils/electron.ts
|
|
44
|
-
var import_node_fs = require("fs");
|
|
45
|
-
var import_node_path = require("path");
|
|
46
|
-
var import_node_os = require("os");
|
|
47
|
-
var import_electron = require("electron");
|
|
48
|
-
var is = {
|
|
49
|
-
dev: !import_electron.app.isPackaged,
|
|
50
|
-
win: process.platform === "win32",
|
|
51
|
-
mac: process.platform === "darwin",
|
|
52
|
-
linux: process.platform === "linux"
|
|
53
|
-
};
|
|
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);
|
|
56
|
-
}
|
|
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
|
-
};
|
|
66
|
-
}
|
|
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
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function restartApp() {
|
|
78
|
-
import_electron.app.relaunch();
|
|
79
|
-
import_electron.app.quit();
|
|
80
|
-
}
|
|
81
|
-
function setAppUserModelId(id) {
|
|
82
|
-
import_electron.app.setAppUserModelId(is.dev ? process.execPath : id ?? `org.${import_electron.app.name}`);
|
|
83
|
-
}
|
|
84
|
-
function disableHWAccForWin7() {
|
|
85
|
-
if ((0, import_node_os.release)().startsWith("6.1")) {
|
|
86
|
-
import_electron.app.disableHardwareAcceleration();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
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;
|
|
101
|
-
}
|
|
102
|
-
function setPortableAppDataPath(dirName = "data") {
|
|
103
|
-
const portablePath = (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getPath("exe")), dirName);
|
|
104
|
-
if (!(0, import_node_fs.existsSync)(portablePath)) {
|
|
105
|
-
(0, import_node_fs.mkdirSync)(portablePath);
|
|
106
|
-
}
|
|
107
|
-
import_electron.app.setPath("appData", portablePath);
|
|
108
|
-
}
|
|
109
|
-
function waitAppReady(timeout = 1e3) {
|
|
110
|
-
return import_electron.app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
|
|
111
|
-
const _ = setTimeout(() => {
|
|
112
|
-
reject(new Error("app is not ready"));
|
|
113
|
-
}, timeout);
|
|
114
|
-
import_electron.app.whenReady().then(() => {
|
|
115
|
-
clearTimeout(_);
|
|
116
|
-
resolve();
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
}
|
|
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
|
-
}
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// src/utils/zip.ts
|
|
175
|
-
var import_node_fs2 = require("fs");
|
|
176
|
-
var import_node_zlib = require("zlib");
|
|
177
|
-
async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
178
|
-
if (!(0, import_node_fs2.existsSync)(gzipPath)) {
|
|
179
|
-
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
180
|
-
}
|
|
181
|
-
const compressedBuffer = (0, import_node_fs2.readFileSync)(gzipPath);
|
|
182
|
-
return new Promise((resolve, reject) => {
|
|
183
|
-
(0, import_node_zlib.gunzip)(compressedBuffer, (err, buffer) => {
|
|
184
|
-
(0, import_node_fs2.rmSync)(gzipPath);
|
|
185
|
-
if (err) {
|
|
186
|
-
reject(err);
|
|
187
|
-
}
|
|
188
|
-
(0, import_node_fs2.writeFileSync)(targetFilePath, buffer);
|
|
189
|
-
resolve(null);
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
194
|
-
if (!(0, import_node_fs2.existsSync)(filePath)) {
|
|
195
|
-
throw new Error(`path to be zipped not exist: ${filePath}`);
|
|
196
|
-
}
|
|
197
|
-
const buffer = (0, import_node_fs2.readFileSync)(filePath);
|
|
198
|
-
return new Promise((resolve, reject) => {
|
|
199
|
-
(0, import_node_zlib.gzip)(buffer, (err, buffer2) => {
|
|
200
|
-
if (err) {
|
|
201
|
-
reject(err);
|
|
202
|
-
}
|
|
203
|
-
(0, import_node_fs2.writeFileSync)(targetFilePath, buffer2);
|
|
204
|
-
resolve(null);
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// src/utils/noDep.ts
|
|
210
|
-
function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
211
|
-
if (!originRepoURL.startsWith("https://github.com/")) {
|
|
212
|
-
throw new Error("origin url must start with https://github.com/");
|
|
213
|
-
}
|
|
214
|
-
originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
|
|
215
|
-
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
216
|
-
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
217
|
-
return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
218
|
-
}
|
|
219
|
-
function handleUnexpectedErrors(callback) {
|
|
220
|
-
process.on("uncaughtException", callback);
|
|
221
|
-
process.on("unhandledRejection", callback);
|
|
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
|
-
}
|
|
251
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
252
|
-
0 && (module.exports = {
|
|
1
|
+
import {
|
|
253
2
|
disableHWAccForWin7,
|
|
254
3
|
getPathFromAppNameAsar,
|
|
255
4
|
getPaths,
|
|
@@ -267,4 +16,23 @@ function isUpdateJSON(json) {
|
|
|
267
16
|
unzipFile,
|
|
268
17
|
waitAppReady,
|
|
269
18
|
zipFile
|
|
270
|
-
}
|
|
19
|
+
} from "./chunk-RQCTJY4L.js";
|
|
20
|
+
export {
|
|
21
|
+
disableHWAccForWin7,
|
|
22
|
+
getPathFromAppNameAsar,
|
|
23
|
+
getPaths,
|
|
24
|
+
getVersions,
|
|
25
|
+
handleUnexpectedErrors,
|
|
26
|
+
is,
|
|
27
|
+
isUpdateJSON,
|
|
28
|
+
loadNativeModuleFromEntry,
|
|
29
|
+
parseGithubCdnURL,
|
|
30
|
+
parseVersion,
|
|
31
|
+
restartApp,
|
|
32
|
+
setAppUserModelId,
|
|
33
|
+
setPortableAppDataPath,
|
|
34
|
+
singleInstance,
|
|
35
|
+
unzipFile,
|
|
36
|
+
waitAppReady,
|
|
37
|
+
zipFile
|
|
38
|
+
};
|