electron-incremental-update 0.8.4 → 0.8.6

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
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,27 +15,20 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
- // src/utils.ts
20
+ // src/utils/index.ts
31
21
  var utils_exports = {};
32
22
  __export(utils_exports, {
33
23
  NoSuchNativeModuleError: () => NoSuchNativeModuleError,
34
- getEntryVersion: () => getEntryVersion,
24
+ getAppInfo: () => getAppInfo,
25
+ getAppVersion: () => getAppVersion,
26
+ getElectronVersion: () => getElectronVersion,
35
27
  getGithubFileCdnGroup: () => getGithubFileCdnGroup,
36
28
  getGithubReleaseCdnGroup: () => getGithubReleaseCdnGroup,
37
29
  getProductAsarPath: () => getProductAsarPath,
38
- getProductVersion: () => getProductVersion,
39
30
  handleUnexpectedErrors: () => handleUnexpectedErrors,
40
- info: () => info,
31
+ isNoSuchNativeModuleError: () => isNoSuchNativeModuleError,
41
32
  parseGithubCdnURL: () => parseGithubCdnURL,
42
33
  parseVersion: () => parseVersion,
43
34
  requireNative: () => requireNative,
@@ -47,23 +38,31 @@ __export(utils_exports, {
47
38
  zipFile: () => zipFile
48
39
  });
49
40
  module.exports = __toCommonJS(utils_exports);
41
+
42
+ // src/utils/core.ts
50
43
  var import_node_fs = require("fs");
51
44
  var import_node_path = require("path");
52
- var import_node_zlib = require("zlib");
53
- var import_electron = __toESM(require("electron"));
54
- var info = {
55
- dev: !import_electron.default.app?.isPackaged,
56
- platform: process.platform === "win32" ? "win" : process.platform === "darwin" ? "mac" : "linux",
57
- appPath: import_electron.default.app?.getAppPath()
58
- };
45
+ var import_node_os = require("os");
46
+ var import_electron = require("electron");
47
+ function getAppInfo() {
48
+ return {
49
+ dev: !import_electron.app.isPackaged,
50
+ win: process.platform === "win32",
51
+ mac: process.platform === "darwin",
52
+ linux: process.platform === "linux",
53
+ electronVersion: getElectronVersion(),
54
+ system: (0, import_node_os.release)(),
55
+ locale: import_electron.app.isReady() ? import_electron.app.getLocale() : void 0
56
+ };
57
+ }
59
58
  function getProductAsarPath(name) {
60
- return info.dev ? "dev.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(info.appPath), `${name}.asar`);
59
+ return !import_electron.app.isPackaged ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`);
61
60
  }
62
- function getEntryVersion() {
63
- return import_electron.default.app.getVersion();
61
+ function getElectronVersion() {
62
+ return import_electron.app.getVersion();
64
63
  }
65
- function getProductVersion(name) {
66
- return info.dev ? getEntryVersion() : (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8");
64
+ function getAppVersion(name) {
65
+ return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getElectronVersion();
67
66
  }
68
67
  var NoSuchNativeModuleError = class extends Error {
69
68
  moduleName;
@@ -72,12 +71,15 @@ var NoSuchNativeModuleError = class extends Error {
72
71
  this.moduleName = moduleName;
73
72
  }
74
73
  };
74
+ function isNoSuchNativeModuleError(e) {
75
+ return e instanceof NoSuchNativeModuleError;
76
+ }
75
77
  function requireNative(packageName) {
76
- const path = info.dev ? packageName : (0, import_node_path.join)(info.appPath, "node_modules", packageName);
78
+ const path = import_electron.app.isPackaged ? (0, import_node_path.join)(import_electron.app.getAppPath(), "node_modules", packageName) : packageName;
77
79
  try {
78
80
  return require(path);
79
81
  } catch (error) {
80
- throw new NoSuchNativeModuleError(packageName);
82
+ return new NoSuchNativeModuleError(packageName);
81
83
  }
82
84
  }
83
85
  function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
@@ -117,59 +119,26 @@ function getGithubReleaseCdnGroup() {
117
119
  ];
118
120
  }
119
121
  function restartApp() {
120
- import_electron.default.app.relaunch();
121
- import_electron.default.app.quit();
122
+ import_electron.app.relaunch();
123
+ import_electron.app.quit();
122
124
  }
123
125
  function waitAppReady(duration = 1e3) {
124
126
  return new Promise((resolve, reject) => {
125
127
  const timeout = setTimeout(() => {
126
128
  reject(new Error("app is not ready"));
127
129
  }, duration);
128
- import_electron.default.app.whenReady().then(() => {
130
+ import_electron.app.whenReady().then(() => {
129
131
  clearTimeout(timeout);
130
132
  resolve();
131
133
  });
132
134
  });
133
135
  }
134
- async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
135
- if (!(0, import_node_fs.existsSync)(gzipPath)) {
136
- throw new Error(`path to zipped file not exist: ${gzipPath}`);
137
- }
138
- const compressedBuffer = (0, import_node_fs.readFileSync)(gzipPath);
139
- return new Promise((resolve, reject) => {
140
- (0, import_node_zlib.gunzip)(compressedBuffer, (err, buffer) => {
141
- (0, import_node_fs.rmSync)(gzipPath);
142
- if (err) {
143
- reject(err);
144
- }
145
- (0, import_node_fs.writeFileSync)(targetFilePath, buffer);
146
- resolve(null);
147
- });
148
- });
149
- }
150
- async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
151
- if (!(0, import_node_fs.existsSync)(filePath)) {
152
- throw new Error(`path to be zipped not exist: ${filePath}`);
153
- }
154
- const buffer = (0, import_node_fs.readFileSync)(filePath);
155
- return new Promise((resolve, reject) => {
156
- (0, import_node_zlib.gzip)(buffer, (err, buffer2) => {
157
- if (err) {
158
- reject(err);
159
- }
160
- (0, import_node_fs.writeFileSync)(targetFilePath, buffer2);
161
- resolve(null);
162
- });
163
- });
164
- }
165
136
  function handleUnexpectedErrors(callback) {
166
- const listener = (err) => {
167
- const e = err instanceof Error ? err : new Error(typeof err === "string" ? err : JSON.stringify(err));
168
- callback(e);
169
- };
170
- process.on("uncaughtException", listener);
171
- process.on("unhandledRejection", listener);
137
+ process.on("uncaughtException", callback);
138
+ process.on("unhandledRejection", callback);
172
139
  }
140
+
141
+ // src/utils/version.ts
173
142
  function parseVersion(version) {
174
143
  const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
175
144
  const match = semver.exec(version);
@@ -194,16 +163,52 @@ function parseVersion(version) {
194
163
  }
195
164
  return ret;
196
165
  }
166
+
167
+ // src/utils/zip.ts
168
+ var import_node_fs2 = require("fs");
169
+ var import_node_zlib = require("zlib");
170
+ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
171
+ if (!(0, import_node_fs2.existsSync)(gzipPath)) {
172
+ throw new Error(`path to zipped file not exist: ${gzipPath}`);
173
+ }
174
+ const compressedBuffer = (0, import_node_fs2.readFileSync)(gzipPath);
175
+ return new Promise((resolve, reject) => {
176
+ (0, import_node_zlib.gunzip)(compressedBuffer, (err, buffer) => {
177
+ (0, import_node_fs2.rmSync)(gzipPath);
178
+ if (err) {
179
+ reject(err);
180
+ }
181
+ (0, import_node_fs2.writeFileSync)(targetFilePath, buffer);
182
+ resolve(null);
183
+ });
184
+ });
185
+ }
186
+ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
187
+ if (!(0, import_node_fs2.existsSync)(filePath)) {
188
+ throw new Error(`path to be zipped not exist: ${filePath}`);
189
+ }
190
+ const buffer = (0, import_node_fs2.readFileSync)(filePath);
191
+ return new Promise((resolve, reject) => {
192
+ (0, import_node_zlib.gzip)(buffer, (err, buffer2) => {
193
+ if (err) {
194
+ reject(err);
195
+ }
196
+ (0, import_node_fs2.writeFileSync)(targetFilePath, buffer2);
197
+ resolve(null);
198
+ });
199
+ });
200
+ }
197
201
  // Annotate the CommonJS export names for ESM import in node:
198
202
  0 && (module.exports = {
199
203
  NoSuchNativeModuleError,
200
- getEntryVersion,
204
+ getAppInfo,
205
+ getAppVersion,
206
+ getElectronVersion,
201
207
  getGithubFileCdnGroup,
202
208
  getGithubReleaseCdnGroup,
203
209
  getProductAsarPath,
204
- getProductVersion,
205
210
  handleUnexpectedErrors,
206
- info,
211
+ isNoSuchNativeModuleError,
207
212
  parseGithubCdnURL,
208
213
  parseVersion,
209
214
  requireNative,
package/dist/utils.mjs CHANGED
@@ -1,30 +1,33 @@
1
1
  import {
2
2
  NoSuchNativeModuleError,
3
- getEntryVersion,
3
+ getAppInfo,
4
+ getAppVersion,
5
+ getElectronVersion,
4
6
  getGithubFileCdnGroup,
5
7
  getGithubReleaseCdnGroup,
6
8
  getProductAsarPath,
7
- getProductVersion,
8
9
  handleUnexpectedErrors,
9
- info,
10
+ isNoSuchNativeModuleError,
10
11
  parseGithubCdnURL,
11
- parseVersion,
12
12
  requireNative,
13
13
  restartApp,
14
+ waitAppReady
15
+ } from "./chunk-MFFH2NRM.mjs";
16
+ import {
17
+ parseVersion,
14
18
  unzipFile,
15
- waitAppReady,
16
19
  zipFile
17
- } from "./chunk-CR6HTU6P.mjs";
18
- import "./chunk-ZFXKCRJC.mjs";
20
+ } from "./chunk-CMBFI77K.mjs";
19
21
  export {
20
22
  NoSuchNativeModuleError,
21
- getEntryVersion,
23
+ getAppInfo,
24
+ getAppVersion,
25
+ getElectronVersion,
22
26
  getGithubFileCdnGroup,
23
27
  getGithubReleaseCdnGroup,
24
28
  getProductAsarPath,
25
- getProductVersion,
26
29
  handleUnexpectedErrors,
27
- info,
30
+ isNoSuchNativeModuleError,
28
31
  parseGithubCdnURL,
29
32
  parseVersion,
30
33
  requireNative,
package/dist/vite.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
- import { UpdateJSON } from './updateJson.mjs';
2
+ import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
3
3
 
4
4
  type DistinguishedName = {
5
5
  countryName?: string;
package/dist/vite.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
- import { UpdateJSON } from './updateJson.js';
2
+ import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
3
3
 
4
4
  type DistinguishedName = {
5
5
  countryName?: string;
package/dist/vite.js CHANGED
@@ -58,16 +58,9 @@ var signature = (buffer, privateKey, cert, version) => {
58
58
  return encrypt(`${sig}%${version}`, key(cert, 32), key(buffer, 16));
59
59
  };
60
60
 
61
- // src/utils.ts
61
+ // src/utils/zip.ts
62
62
  var import_node_fs = require("fs");
63
- var import_node_path = require("path");
64
63
  var import_node_zlib = require("zlib");
65
- var import_electron = __toESM(require("electron"));
66
- var info = {
67
- dev: !import_electron.default.app?.isPackaged,
68
- platform: process.platform === "win32" ? "win" : process.platform === "darwin" ? "mac" : "linux",
69
- appPath: import_electron.default.app?.getAppPath()
70
- };
71
64
  async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
72
65
  if (!(0, import_node_fs.existsSync)(filePath)) {
73
66
  throw new Error(`path to be zipped not exist: ${filePath}`);
@@ -83,6 +76,8 @@ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
83
76
  });
84
77
  });
85
78
  }
79
+
80
+ // src/utils/version.ts
86
81
  function parseVersion(version) {
87
82
  const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
88
83
  const match = semver.exec(version);
@@ -199,13 +194,12 @@ var import_ci_info = require("ci-info");
199
194
 
200
195
  // src/build-plugins/key.ts
201
196
  var import_node_fs3 = require("fs");
202
- var import_node_path2 = require("path");
203
- var import_node_os = require("os");
197
+ var import_node_path = require("path");
204
198
  var import_selfsigned = require("selfsigned");
205
199
  function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
206
- const privateKeyDir = (0, import_node_path2.dirname)(privateKeyPath);
200
+ const privateKeyDir = (0, import_node_path.dirname)(privateKeyPath);
207
201
  (0, import_node_fs3.existsSync)(privateKeyDir) || (0, import_node_fs3.mkdirSync)(privateKeyDir, { recursive: true });
208
- const certDir = (0, import_node_path2.dirname)(certPath);
202
+ const certDir = (0, import_node_path.dirname)(certPath);
209
203
  (0, import_node_fs3.existsSync)(certDir) || (0, import_node_fs3.mkdirSync)(certDir, { recursive: true });
210
204
  const { cert, private: privateKey } = (0, import_selfsigned.generate)(subject, {
211
205
  keySize: keyLength,
@@ -217,15 +211,18 @@ function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
217
211
  }
218
212
  function writeCertToMain(entryPath, cert) {
219
213
  const file = (0, import_node_fs3.readFileSync)(entryPath, "utf-8");
220
- const regex = /const SIGNATURE_CERT\s*=\s*['"`][\s\S]*?['"`]/;
221
- const replacement = `const SIGNATURE_CERT = \`${cert}\``;
214
+ const initRegex = /(?<=const SIGNATURE_CERT\s*=\s*)['"]{2}/m;
215
+ const existRegex = /(?<=const SIGNATURE_CERT\s*=\s*)(['"]-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n['"])/m;
216
+ const eol = file.includes("\r") ? "\r\n" : "\n";
217
+ const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join(`${eol}+ `);
222
218
  let replaced = file;
223
- const signaturePubExists = regex.test(file);
224
- if (signaturePubExists) {
225
- replaced = file.replace(regex, replacement);
219
+ if (initRegex.test(file)) {
220
+ replaced = file.replace(initRegex, replacement);
221
+ } else if (existRegex.test(file)) {
222
+ replaced = file.replace(existRegex, replacement);
226
223
  } else {
227
- const lines = file.split(import_node_os.EOL);
228
- const r = `${import_node_os.EOL}${replacement}${import_node_os.EOL}`;
224
+ const lines = file.split(eol);
225
+ const r = `${eol}const SIGNATURE_CERT = ${replacement}${eol}`;
229
226
  let isMatched = false;
230
227
  for (let i = 0; i < lines.length; i++) {
231
228
  const line = lines[i];
@@ -236,9 +233,10 @@ function writeCertToMain(entryPath, cert) {
236
233
  }
237
234
  }
238
235
  !isMatched && lines.push(r);
239
- replaced = lines.join(import_node_os.EOL);
236
+ replaced = lines.join(eol);
240
237
  }
241
- (0, import_node_fs3.writeFileSync)(entryPath, replaced.replace(/\r\n?/g, "\n"));
238
+ console.log(JSON.stringify(replaced));
239
+ (0, import_node_fs3.writeFileSync)(entryPath, replaced);
242
240
  }
243
241
  function parseKeys({
244
242
  keyLength,
@@ -248,7 +246,7 @@ function parseKeys({
248
246
  subject,
249
247
  days
250
248
  }) {
251
- const keysDir = (0, import_node_path2.dirname)(privateKeyPath);
249
+ const keysDir = (0, import_node_path.dirname)(privateKeyPath);
252
250
  !(0, import_node_fs3.existsSync)(keysDir) && (0, import_node_fs3.mkdirSync)(keysDir);
253
251
  if (!(0, import_node_fs3.existsSync)(privateKeyPath) || !(0, import_node_fs3.existsSync)(certPath)) {
254
252
  generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
package/dist/vite.mjs CHANGED
@@ -1,14 +1,11 @@
1
1
  import {
2
+ isUpdateJSON,
2
3
  signature
3
- } from "./chunk-GXZSAUBR.mjs";
4
+ } from "./chunk-5BZLJPHJ.mjs";
4
5
  import {
5
6
  parseVersion,
6
7
  zipFile
7
- } from "./chunk-CR6HTU6P.mjs";
8
- import {
9
- isUpdateJSON
10
- } from "./chunk-2JVXVTC5.mjs";
11
- import "./chunk-ZFXKCRJC.mjs";
8
+ } from "./chunk-CMBFI77K.mjs";
12
9
 
13
10
  // src/vite.ts
14
11
  import { createLogger } from "vite";
@@ -103,7 +100,6 @@ import { isCI } from "ci-info";
103
100
  // src/build-plugins/key.ts
104
101
  import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "node:fs";
105
102
  import { dirname } from "node:path";
106
- import { EOL } from "node:os";
107
103
  import { generate } from "selfsigned";
108
104
  function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
109
105
  const privateKeyDir = dirname(privateKeyPath);
@@ -120,15 +116,18 @@ function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
120
116
  }
121
117
  function writeCertToMain(entryPath, cert) {
122
118
  const file = readFileSync(entryPath, "utf-8");
123
- const regex = /const SIGNATURE_CERT\s*=\s*['"`][\s\S]*?['"`]/;
124
- const replacement = `const SIGNATURE_CERT = \`${cert}\``;
119
+ const initRegex = /(?<=const SIGNATURE_CERT\s*=\s*)['"]{2}/m;
120
+ const existRegex = /(?<=const SIGNATURE_CERT\s*=\s*)(['"]-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n['"])/m;
121
+ const eol = file.includes("\r") ? "\r\n" : "\n";
122
+ const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join(`${eol}+ `);
125
123
  let replaced = file;
126
- const signaturePubExists = regex.test(file);
127
- if (signaturePubExists) {
128
- replaced = file.replace(regex, replacement);
124
+ if (initRegex.test(file)) {
125
+ replaced = file.replace(initRegex, replacement);
126
+ } else if (existRegex.test(file)) {
127
+ replaced = file.replace(existRegex, replacement);
129
128
  } else {
130
- const lines = file.split(EOL);
131
- const r = `${EOL}${replacement}${EOL}`;
129
+ const lines = file.split(eol);
130
+ const r = `${eol}const SIGNATURE_CERT = ${replacement}${eol}`;
132
131
  let isMatched = false;
133
132
  for (let i = 0; i < lines.length; i++) {
134
133
  const line = lines[i];
@@ -139,9 +138,10 @@ function writeCertToMain(entryPath, cert) {
139
138
  }
140
139
  }
141
140
  !isMatched && lines.push(r);
142
- replaced = lines.join(EOL);
141
+ replaced = lines.join(eol);
143
142
  }
144
- writeFileSync(entryPath, replaced.replace(/\r\n?/g, "\n"));
143
+ console.log(JSON.stringify(replaced));
144
+ writeFileSync(entryPath, replaced);
145
145
  }
146
146
  function parseKeys({
147
147
  keyLength,
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
3
  "author": "subframe7536",
4
- "version": "0.8.4",
4
+ "version": "0.8.6",
5
5
  "description": "electron incremental update tools, powered by vite",
6
6
  "scripts": {
7
7
  "build": "tsup && node fix-module.js",
8
8
  "release": "pnpm test && pnpm run build && bumpp --all && npm publish",
9
- "test": "vitest --run"
9
+ "test": "vitest --run",
10
+ "lint": "eslint . --fix"
10
11
  },
11
12
  "publishConfig": {
12
13
  "access": "public",
@@ -43,14 +44,14 @@
43
44
  "updater"
44
45
  ],
45
46
  "devDependencies": {
46
- "@subframe7536/eslint-config": "^0.2.5",
47
- "@types/node": "^20.5.1",
48
- "bumpp": "^9.1.1",
49
- "electron": "^26.0.0",
50
- "eslint": "^8.47.0",
47
+ "@subframe7536/eslint-config": "^0.2.9",
48
+ "@types/node": "^20.6.0",
49
+ "bumpp": "^9.2.0",
50
+ "electron": "^26.2.0",
51
+ "eslint": "^8.49.0",
51
52
  "tsup": "^7.2.0",
52
- "typescript": "^5.1.6",
53
- "vitest": "^0.34.2"
53
+ "typescript": "^5.2.2",
54
+ "vitest": "^0.34.4"
54
55
  },
55
56
  "dependencies": {
56
57
  "@electron/asar": "^3.2.4",
@@ -1,9 +0,0 @@
1
- // src/updateJson.ts
2
- function isUpdateJSON(json) {
3
- const is = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
4
- return is(json) && "beta" in json && is(json.beta);
5
- }
6
-
7
- export {
8
- isUpdateJSON
9
- };
@@ -1,170 +0,0 @@
1
- import {
2
- __require
3
- } from "./chunk-ZFXKCRJC.mjs";
4
-
5
- // src/utils.ts
6
- import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
7
- import { dirname, join } from "node:path";
8
- import { gunzip, gzip } from "node:zlib";
9
- import Electron from "electron";
10
- var info = {
11
- dev: !Electron.app?.isPackaged,
12
- platform: process.platform === "win32" ? "win" : process.platform === "darwin" ? "mac" : "linux",
13
- appPath: Electron.app?.getAppPath()
14
- };
15
- function getProductAsarPath(name) {
16
- return info.dev ? "dev.asar" : join(dirname(info.appPath), `${name}.asar`);
17
- }
18
- function getEntryVersion() {
19
- return Electron.app.getVersion();
20
- }
21
- function getProductVersion(name) {
22
- return info.dev ? getEntryVersion() : readFileSync(join(getProductAsarPath(name), "version"), "utf-8");
23
- }
24
- var NoSuchNativeModuleError = class extends Error {
25
- moduleName;
26
- constructor(moduleName) {
27
- super(`no such native module: ${moduleName}`);
28
- this.moduleName = moduleName;
29
- }
30
- };
31
- function requireNative(packageName) {
32
- const path = info.dev ? packageName : join(info.appPath, "node_modules", packageName);
33
- try {
34
- return __require(path);
35
- } catch (error) {
36
- throw new NoSuchNativeModuleError(packageName);
37
- }
38
- }
39
- function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
40
- if (!repository.startsWith("https://github.com/")) {
41
- throw new Error("url must start with https://github.com/");
42
- }
43
- repository = repository.trim().replace(/\/?$/, "/").trim();
44
- relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
45
- cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
46
- return repository.replace("github.com", cdnPrefix) + relativeFilePath;
47
- }
48
- function getGithubFileCdnGroup() {
49
- return [
50
- { cdnPrefix: "cdn.jsdelivr.net/gh", source: "jsdelivr" },
51
- { cdnPrefix: "fastly.jsdelivr.net/gh", source: "jsdelivr-fastly" },
52
- { cdnPrefix: "cdn.statically.io/gh", source: "statically" },
53
- { cdnPrefix: "rawcdn.githack.com/gh", source: "githack" },
54
- { cdnPrefix: "raw.githack.com/gh", source: "githack-dev" }
55
- ];
56
- }
57
- function getGithubReleaseCdnGroup() {
58
- return [
59
- { cdnPrefix: "gh.gh2233.ml", source: "@X.I.U/XIU2" },
60
- { cdnPrefix: "ghproxy.com", source: "gh-proxy" },
61
- { cdnPrefix: "gh.ddlc.top", source: "@mtr-static-official" },
62
- { cdnPrefix: "ghdl.feizhuqwq.cf", source: "feizhuqwq.com" },
63
- { cdnPrefix: "slink.ltd", source: "\u77E5\u4E86\u5C0F\u7AD9" },
64
- { cdnPrefix: "git.xfj0.cn", source: "anonymous1" },
65
- { cdnPrefix: "gh.con.sh", source: "anonymous2" },
66
- { cdnPrefix: "ghps.cc", source: "anonymous3" },
67
- { cdnPrefix: "cors.isteed.cc/github.com", source: "Lufs's" },
68
- { cdnPrefix: "hub.gitmirror.com", source: "GitMirror" },
69
- { cdnPrefix: "js.xxooo.ml", source: "\u996D\u592A\u786C" },
70
- { cdnPrefix: "download.njuu.cf", source: "LibraryCloud-njuu" },
71
- { cdnPrefix: "download.yzuu.cf", source: "LibraryCloud-yzuu" },
72
- { cdnPrefix: "download.nuaa.cf", source: "LibraryCloud-nuaa" }
73
- ];
74
- }
75
- function restartApp() {
76
- Electron.app.relaunch();
77
- Electron.app.quit();
78
- }
79
- function waitAppReady(duration = 1e3) {
80
- return new Promise((resolve, reject) => {
81
- const timeout = setTimeout(() => {
82
- reject(new Error("app is not ready"));
83
- }, duration);
84
- Electron.app.whenReady().then(() => {
85
- clearTimeout(timeout);
86
- resolve();
87
- });
88
- });
89
- }
90
- async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
91
- if (!existsSync(gzipPath)) {
92
- throw new Error(`path to zipped file not exist: ${gzipPath}`);
93
- }
94
- const compressedBuffer = readFileSync(gzipPath);
95
- return new Promise((resolve, reject) => {
96
- gunzip(compressedBuffer, (err, buffer) => {
97
- rmSync(gzipPath);
98
- if (err) {
99
- reject(err);
100
- }
101
- writeFileSync(targetFilePath, buffer);
102
- resolve(null);
103
- });
104
- });
105
- }
106
- async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
107
- if (!existsSync(filePath)) {
108
- throw new Error(`path to be zipped not exist: ${filePath}`);
109
- }
110
- const buffer = readFileSync(filePath);
111
- return new Promise((resolve, reject) => {
112
- gzip(buffer, (err, buffer2) => {
113
- if (err) {
114
- reject(err);
115
- }
116
- writeFileSync(targetFilePath, buffer2);
117
- resolve(null);
118
- });
119
- });
120
- }
121
- function handleUnexpectedErrors(callback) {
122
- const listener = (err) => {
123
- const e = err instanceof Error ? err : new Error(typeof err === "string" ? err : JSON.stringify(err));
124
- callback(e);
125
- };
126
- process.on("uncaughtException", listener);
127
- process.on("unhandledRejection", listener);
128
- }
129
- function parseVersion(version) {
130
- const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
131
- const match = semver.exec(version);
132
- if (!match) {
133
- throw new TypeError(`invalid version: ${version}`);
134
- }
135
- const [major, minor, patch] = match.slice(1, 4).map(Number);
136
- const ret = {
137
- major,
138
- minor,
139
- patch,
140
- stage: "",
141
- stageVersion: -1
142
- };
143
- if (match[4]) {
144
- let [stage, _v] = match[4].split(".");
145
- ret.stage = stage;
146
- ret.stageVersion = Number(_v) || -1;
147
- }
148
- if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
149
- throw new TypeError(`invalid version: ${version}`);
150
- }
151
- return ret;
152
- }
153
-
154
- export {
155
- info,
156
- getProductAsarPath,
157
- getEntryVersion,
158
- getProductVersion,
159
- NoSuchNativeModuleError,
160
- requireNative,
161
- parseGithubCdnURL,
162
- getGithubFileCdnGroup,
163
- getGithubReleaseCdnGroup,
164
- restartApp,
165
- waitAppReady,
166
- unzipFile,
167
- zipFile,
168
- handleUnexpectedErrors,
169
- parseVersion
170
- };
@@ -1,11 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
- export {
10
- __require
11
- };