electron-incremental-update 0.9.0 → 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/dist/utils.js CHANGED
@@ -20,93 +20,155 @@ 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
- getAppVersion: () => getAppVersion,
26
- getElectronVersion: () => getElectronVersion,
27
- getLocale: () => getLocale,
28
- getProductAsarPath: () => getProductAsarPath,
23
+ disableHWAccForWin7: () => disableHWAccForWin7,
24
+ getPathFromAppNameAsar: () => getPathFromAppNameAsar,
25
+ getPaths: () => getPaths,
26
+ getVersions: () => getVersions,
29
27
  handleUnexpectedErrors: () => handleUnexpectedErrors,
30
28
  is: () => is,
31
- isNoSuchNativeModuleError: () => isNoSuchNativeModuleError,
29
+ isUpdateJSON: () => isUpdateJSON,
30
+ loadNativeModuleFromEntry: () => loadNativeModuleFromEntry,
32
31
  parseGithubCdnURL: () => parseGithubCdnURL,
33
32
  parseVersion: () => parseVersion,
34
- requireNative: () => requireNative,
35
33
  restartApp: () => restartApp,
36
34
  setAppUserModelId: () => setAppUserModelId,
37
35
  setPortableAppDataPath: () => setPortableAppDataPath,
36
+ singleInstance: () => singleInstance,
38
37
  unzipFile: () => unzipFile,
39
38
  waitAppReady: () => waitAppReady,
40
39
  zipFile: () => zipFile
41
40
  });
42
41
  module.exports = __toCommonJS(utils_exports);
43
42
 
44
- // src/utils/core.ts
43
+ // src/utils/electron.ts
45
44
  var import_node_fs = require("fs");
46
45
  var import_node_path = require("path");
46
+ var import_node_os = require("os");
47
47
  var import_electron = require("electron");
48
- var DEFAULT_APP_NAME = "product";
49
48
  var is = {
50
49
  dev: !import_electron.app.isPackaged,
51
50
  win: process.platform === "win32",
52
51
  mac: process.platform === "darwin",
53
52
  linux: process.platform === "linux"
54
53
  };
55
- function getLocale() {
56
- return import_electron.app.isReady() ? import_electron.app.getLocale() : void 0;
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);
57
56
  }
58
- function getProductAsarPath(name = DEFAULT_APP_NAME) {
59
- return !import_electron.app.isPackaged ? (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`) : "DEV.asar";
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
+ };
60
66
  }
61
- function getElectronVersion() {
62
- return import_electron.app.getVersion();
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
+ };
63
76
  }
64
- function getAppVersion(name = DEFAULT_APP_NAME) {
65
- return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getElectronVersion();
77
+ function restartApp() {
78
+ import_electron.app.relaunch();
79
+ import_electron.app.quit();
66
80
  }
67
- var NoSuchNativeModuleError = class extends Error {
68
- moduleName;
69
- constructor(moduleName) {
70
- super(`no such native module: ${moduleName}`);
71
- this.moduleName = moduleName;
72
- }
73
- };
74
- function isNoSuchNativeModuleError(e) {
75
- return e instanceof NoSuchNativeModuleError;
76
- }
77
- function requireNative(packageName) {
78
- const path = import_electron.app.isPackaged ? (0, import_node_path.join)(import_electron.app.getAppPath(), "node_modules", packageName) : packageName;
79
- try {
80
- return require(path);
81
- } catch (error) {
82
- return new NoSuchNativeModuleError(packageName);
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();
83
87
  }
84
88
  }
85
-
86
- // src/utils/version.ts
87
- function parseVersion(version) {
88
- const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
89
- const match = semver.exec(version);
90
- if (!match) {
91
- throw new TypeError(`invalid version: ${version}`);
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);
92
106
  }
93
- const [major, minor, patch] = match.slice(1, 4).map(Number);
94
- const ret = {
95
- major,
96
- minor,
97
- patch,
98
- stage: "",
99
- stageVersion: -1
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
+ }
100
171
  };
101
- if (match[4]) {
102
- let [stage, _v] = match[4].split(".");
103
- ret.stage = stage;
104
- ret.stageVersion = Number(_v) || -1;
105
- }
106
- if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
107
- throw new TypeError(`invalid version: ${version}`);
108
- }
109
- return ret;
110
172
  }
111
173
 
112
174
  // src/utils/zip.ts
@@ -144,10 +206,7 @@ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
144
206
  });
145
207
  }
146
208
 
147
- // src/utils/utils.ts
148
- var import_node_path2 = require("path");
149
- var import_node_fs3 = require("fs");
150
- var import_electron2 = require("electron");
209
+ // src/utils/noDep.ts
151
210
  function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
152
211
  if (!originRepoURL.startsWith("https://github.com/")) {
153
212
  throw new Error("origin url must start with https://github.com/");
@@ -157,59 +216,54 @@ function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
157
216
  cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
158
217
  return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
159
218
  }
160
- function restartApp() {
161
- import_electron2.app.relaunch();
162
- import_electron2.app.quit();
163
- }
164
- function setAppUserModelId(id) {
165
- is.win && import_electron2.app.setAppUserModelId(is.dev ? process.execPath : id);
219
+ function handleUnexpectedErrors(callback) {
220
+ process.on("uncaughtException", callback);
221
+ process.on("unhandledRejection", callback);
166
222
  }
167
- function setPortableAppDataPath(dirName = "data", create) {
168
- if (!is.win) {
169
- return;
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}`);
170
228
  }
171
- const portablePath = (0, import_node_path2.join)((0, import_node_path2.dirname)(import_electron2.app.getPath("exe")), dirName);
172
- let exists = (0, import_node_fs3.existsSync)(portablePath);
173
- if (create && !exists) {
174
- (0, import_node_fs3.mkdirSync)(portablePath);
175
- exists = true;
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;
176
241
  }
177
- if (exists) {
178
- import_electron2.app.setPath("appData", portablePath);
242
+ if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
243
+ throw new TypeError(`invalid version: ${version}`);
179
244
  }
245
+ return ret;
180
246
  }
181
- function waitAppReady(timeout = 1e3) {
182
- return import_electron2.app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
183
- const _ = setTimeout(() => {
184
- reject(new Error("app is not ready"));
185
- }, timeout);
186
- import_electron2.app.whenReady().then(() => {
187
- clearTimeout(_);
188
- resolve();
189
- });
190
- });
191
- }
192
- function handleUnexpectedErrors(callback) {
193
- process.on("uncaughtException", callback);
194
- process.on("unhandledRejection", callback);
247
+ function isUpdateJSON(json) {
248
+ const is2 = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
249
+ return is2(json) && is2(json?.beta);
195
250
  }
196
251
  // Annotate the CommonJS export names for ESM import in node:
197
252
  0 && (module.exports = {
198
- DEFAULT_APP_NAME,
199
- NoSuchNativeModuleError,
200
- getAppVersion,
201
- getElectronVersion,
202
- getLocale,
203
- getProductAsarPath,
253
+ disableHWAccForWin7,
254
+ getPathFromAppNameAsar,
255
+ getPaths,
256
+ getVersions,
204
257
  handleUnexpectedErrors,
205
258
  is,
206
- isNoSuchNativeModuleError,
259
+ isUpdateJSON,
260
+ loadNativeModuleFromEntry,
207
261
  parseGithubCdnURL,
208
262
  parseVersion,
209
- requireNative,
210
263
  restartApp,
211
264
  setAppUserModelId,
212
265
  setPortableAppDataPath,
266
+ singleInstance,
213
267
  unzipFile,
214
268
  waitAppReady,
215
269
  zipFile
package/dist/utils.mjs CHANGED
@@ -1,41 +1,39 @@
1
1
  import {
2
- DEFAULT_APP_NAME,
3
- NoSuchNativeModuleError,
4
- getAppVersion,
5
- getElectronVersion,
6
- getLocale,
7
- getProductAsarPath,
8
- handleUnexpectedErrors,
2
+ disableHWAccForWin7,
3
+ getPathFromAppNameAsar,
4
+ getPaths,
5
+ getVersions,
9
6
  is,
10
- isNoSuchNativeModuleError,
11
- parseGithubCdnURL,
12
- requireNative,
7
+ loadNativeModuleFromEntry,
13
8
  restartApp,
14
9
  setAppUserModelId,
15
10
  setPortableAppDataPath,
11
+ singleInstance,
16
12
  waitAppReady
17
- } from "./chunk-6UZHBPFT.mjs";
13
+ } from "./chunk-OUZLSVQC.mjs";
18
14
  import {
15
+ handleUnexpectedErrors,
16
+ isUpdateJSON,
17
+ parseGithubCdnURL,
19
18
  parseVersion,
20
19
  unzipFile,
21
20
  zipFile
22
- } from "./chunk-CMBFI77K.mjs";
21
+ } from "./chunk-GB6VLKJZ.mjs";
23
22
  export {
24
- DEFAULT_APP_NAME,
25
- NoSuchNativeModuleError,
26
- getAppVersion,
27
- getElectronVersion,
28
- getLocale,
29
- getProductAsarPath,
23
+ disableHWAccForWin7,
24
+ getPathFromAppNameAsar,
25
+ getPaths,
26
+ getVersions,
30
27
  handleUnexpectedErrors,
31
28
  is,
32
- isNoSuchNativeModuleError,
29
+ isUpdateJSON,
30
+ loadNativeModuleFromEntry,
33
31
  parseGithubCdnURL,
34
32
  parseVersion,
35
- requireNative,
36
33
  restartApp,
37
34
  setAppUserModelId,
38
35
  setPortableAppDataPath,
36
+ singleInstance,
39
37
  unzipFile,
40
38
  waitAppReady,
41
39
  zipFile