electron-incremental-update 2.0.0-beta.9 → 2.0.1

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/vite.js CHANGED
@@ -38,7 +38,7 @@ function parseVersion(version) {
38
38
  ret.stageVersion = Number(_v) || -1;
39
39
  }
40
40
  if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
41
- throw new TypeError(`invalid version: ${version}`);
41
+ throw new TypeError(`Invalid version: ${version}`);
42
42
  }
43
43
  return ret;
44
44
  }
@@ -91,7 +91,7 @@ function getElectronPath() {
91
91
  return electronExecPath;
92
92
  }
93
93
  function getBytecodeCompilerPath() {
94
- const scriptPath = path5.join(electronModulePath, "bytenode.cjs");
94
+ const scriptPath = path5.join(electronModulePath, "EIU_bytenode.cjs");
95
95
  if (!fs3.existsSync(scriptPath)) {
96
96
  fs3.writeFileSync(scriptPath, bytecodeGeneratorScript);
97
97
  }
@@ -101,10 +101,9 @@ function toRelativePath(filename, importer) {
101
101
  const relPath = path5.posix.relative(path5.dirname(importer), filename);
102
102
  return relPath.startsWith(".") ? relPath : `./${relPath}`;
103
103
  }
104
- function compileToBytecode(code) {
104
+ function compileToBytecode(code, electronPath = getElectronPath()) {
105
105
  let data = Buffer.from([]);
106
106
  const logErr = (...args) => bytecodeLog.error(args.join(" "), { timestamp: true });
107
- const electronPath = getElectronPath();
108
107
  const bytecodePath = getBytecodeCompilerPath();
109
108
  return new Promise((resolve, reject) => {
110
109
  const proc = cp.spawn(electronPath, [bytecodePath], {
@@ -140,7 +139,7 @@ function convertArrowFunctionAndTemplate(code) {
140
139
  }
141
140
  var decodeFn = ";function _0xstr_(a,b){return String.fromCharCode.apply(0,a.map(function(x){return x-b}))};";
142
141
  function obfuscateString(input, offset = ~~(Math.random() * 16) + 1) {
143
- const hexArray = input.split("").map((c) => "0x" + (c.charCodeAt(0) + offset).toString(16));
142
+ const hexArray = input.split("").map((c) => `0x${(c.charCodeAt(0) + offset).toString(16)}`);
144
143
  return `_0xstr_([${hexArray.join(",")}],${offset})`;
145
144
  }
146
145
  function convertLiteral(code, sourcemap, offset) {
@@ -148,7 +147,7 @@ function convertLiteral(code, sourcemap, offset) {
148
147
  let hasTransformed = false;
149
148
  const ast = babel.parse(code, { ast: true });
150
149
  if (!ast) {
151
- throw new Error("cannot parse code");
150
+ throw new Error("Cannot parse code");
152
151
  }
153
152
  babel.traverse(ast, {
154
153
  StringLiteral(path6) {
@@ -168,6 +167,9 @@ function convertLiteral(code, sourcemap, offset) {
168
167
  if (parent.type.startsWith("Import")) {
169
168
  return;
170
169
  }
170
+ if (parent.type === "ObjectMethod" && parent.key === node) {
171
+ return;
172
+ }
171
173
  if (parent.type === "ObjectProperty" && parent.key === node) {
172
174
  const result2 = `[${obfuscateString(node.value, offset)}]`;
173
175
  const start2 = node.start;
@@ -224,7 +226,7 @@ async function buildAsar({
224
226
  await Asar.createPackage(electronDistPath, asarOutputPath);
225
227
  const buf = await generateGzipFile(fs3.readFileSync(asarOutputPath));
226
228
  fs3.writeFileSync(gzipPath, buf);
227
- log.info(`build update asar to '${gzipPath}' [${readableSize(buf.length)}]`, { timestamp: true });
229
+ log.info(`Build update asar to '${gzipPath}' [${readableSize(buf.length)}]`, { timestamp: true });
228
230
  return buf;
229
231
  }
230
232
  async function buildVersion({
@@ -252,7 +254,7 @@ async function buildVersion({
252
254
  if (isUpdateJSON(oldVersionJson)) {
253
255
  _json = oldVersionJson;
254
256
  } else {
255
- log.warn("old version json is invalid, ignore it", { timestamp: true });
257
+ log.warn("Old version json is invalid, ignore it", { timestamp: true });
256
258
  }
257
259
  } catch {
258
260
  }
@@ -260,7 +262,7 @@ async function buildVersion({
260
262
  const sig = await generateSignature(asarBuffer, privateKey, cert, version);
261
263
  _json = await generateVersionJson(_json, sig, version, minimumVersion);
262
264
  if (!isUpdateJSON(_json)) {
263
- throw new Error("invalid version info");
265
+ throw new Error("Invalid version info");
264
266
  }
265
267
  fs3.writeFileSync(versionPath, JSON.stringify(_json, null, 2));
266
268
  log.info(`build version info to '${versionPath}'`, { timestamp: true });
@@ -272,7 +274,7 @@ async function buildEntry({
272
274
  entryOutputDirPath,
273
275
  nativeModuleEntryMap,
274
276
  overrideEsbuildOptions
275
- }, define, bytecodeOptions) {
277
+ }, isESM, define, bytecodeOptions) {
276
278
  const option = mergeConfig(
277
279
  {
278
280
  entryPoints: {
@@ -292,7 +294,8 @@ async function buildEntry({
292
294
  loader: {
293
295
  ".node": "empty"
294
296
  },
295
- define
297
+ define,
298
+ format: isESM ? "esm" : "cjs"
296
299
  },
297
300
  overrideEsbuildOptions ?? {}
298
301
  );
@@ -312,7 +315,7 @@ async function buildEntry({
312
315
  transformedCode = result;
313
316
  }
314
317
  }
315
- const buffer = await compileToBytecode(transformedCode);
318
+ const buffer = await compileToBytecode(transformedCode, bytecodeOptions.electronPath);
316
319
  fs3.writeFileSync(
317
320
  filePath,
318
321
  `${isEntry ? bytecodeModuleLoaderCode : useStrict}${isEntry ? "" : "module.exports = "}require("./${fileName}c")`
@@ -376,14 +379,14 @@ function parseKeys({
376
379
  let privateKey = process.env.UPDATER_PK;
377
380
  let cert = process.env.UPDATER_CERT;
378
381
  if (privateKey && cert) {
379
- log.info("use UPDATER_PK and UPDATER_CERT from environment variables", { timestamp: true });
382
+ log.info("Use `UPDATER_PK` and `UPDATER_CERT` from environment variables", { timestamp: true });
380
383
  return { privateKey, cert };
381
384
  }
382
385
  if (!fs3.existsSync(keysDir)) {
383
386
  fs3.mkdirSync(keysDir);
384
387
  }
385
388
  if (!fs3.existsSync(privateKeyPath) || !fs3.existsSync(certPath)) {
386
- log.info("no key pair found, generate new key pair", { timestamp: true });
389
+ log.info("No key pair found, generate new key pair", { timestamp: true });
387
390
  generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
388
391
  }
389
392
  privateKey = fs3.readFileSync(privateKeyPath, "utf-8");
@@ -470,13 +473,14 @@ function bytecodePlugin(env, options) {
470
473
  const {
471
474
  enable,
472
475
  preload = false,
476
+ electronPath,
473
477
  beforeCompile
474
478
  } = options;
475
479
  if (!enable) {
476
480
  return null;
477
481
  }
478
482
  if (!preload && env === "preload") {
479
- bytecodeLog.warn('bytecodePlugin is skiped in preload. To enable in preload, please manually set the "enablePreload" option to true and set `sandbox: false` when creating the window', { timestamp: true });
483
+ bytecodeLog.warn('`bytecodePlugin` is skiped in preload. To enable in preload, please manually set the "enablePreload" option to true and set `sandbox: false` when creating the window', { timestamp: true });
480
484
  return null;
481
485
  }
482
486
  const filter = createFilter(/\.(m?[jt]s|[jt]sx)$/);
@@ -499,7 +503,8 @@ function bytecodePlugin(env, options) {
499
503
  if (options2.format !== "es" && bytecodeRequired) {
500
504
  this.emitFile({
501
505
  type: "asset",
502
- source: bytecodeModuleLoaderCode + "\n",
506
+ source: `${bytecodeModuleLoaderCode}
507
+ `,
503
508
  name: "Bytecode Loader File",
504
509
  fileName: bytecodeModuleLoader
505
510
  });
@@ -508,7 +513,7 @@ function bytecodePlugin(env, options) {
508
513
  renderChunk(code, chunk, options2) {
509
514
  if (options2.format === "es") {
510
515
  bytecodeLog.warn(
511
- 'bytecodePlugin does not support ES module, please remove "type": "module" in package.json or set the "build.rollupOptions.output.format" option to "cjs".',
516
+ '`bytecodePlugin` does not support ES module, please set "build.rollupOptions.output.format" option to "cjs"',
512
517
  { timestamp: true }
513
518
  );
514
519
  return null;
@@ -541,8 +546,9 @@ function bytecodePlugin(env, options) {
541
546
  const chunk = output[name];
542
547
  if (chunk.type === "chunk") {
543
548
  let _code = chunk.code;
549
+ const chunkFilePath = path5.resolve(outDir, name);
544
550
  if (beforeCompile) {
545
- const cbResult = await beforeCompile(_code, chunk.fileName);
551
+ const cbResult = await beforeCompile(_code, chunkFilePath);
546
552
  if (cbResult) {
547
553
  _code = cbResult;
548
554
  }
@@ -553,19 +559,18 @@ function bytecodePlugin(env, options) {
553
559
  while (match = bytecodeRE.exec(_code)) {
554
560
  const [prefix, chunkName] = match;
555
561
  const len = prefix.length + chunkName.length;
556
- s.overwrite(match.index, match.index + len, prefix + chunkName + "c", {
562
+ s.overwrite(match.index, match.index + len, `${prefix + chunkName}c`, {
557
563
  contentOnly: true
558
564
  });
559
565
  }
560
566
  _code = s.toString();
561
567
  }
562
- const chunkFilePath = path5.resolve(outDir, name);
563
568
  if (bytecodeChunks.includes(name)) {
564
- const bytecodeBuffer = await compileToBytecode(_code);
565
- fs3.writeFileSync(chunkFilePath + "c", bytecodeBuffer);
569
+ const bytecodeBuffer = await compileToBytecode(_code, electronPath);
570
+ fs3.writeFileSync(`${chunkFilePath}c`, bytecodeBuffer);
566
571
  if (chunk.isEntry) {
567
572
  const bytecodeLoaderBlock = getBytecodeLoaderBlock(chunk.fileName);
568
- const bytecodeModuleBlock = `require("./${path5.basename(name) + "c"}");`;
573
+ const bytecodeModuleBlock = `require("./${`${path5.basename(name)}c`}");`;
569
574
  const code = `${useStrict}
570
575
  ${bytecodeLoaderBlock}
571
576
  module.exports=${bytecodeModuleBlock}
@@ -574,7 +579,7 @@ module.exports=${bytecodeModuleBlock}
574
579
  } else {
575
580
  fs3.unlinkSync(chunkFilePath);
576
581
  }
577
- bytecodeFiles.push({ name: name + "c", size: bytecodeBuffer.length });
582
+ bytecodeFiles.push({ name: `${name}c`, size: bytecodeBuffer.length });
578
583
  } else {
579
584
  if (chunk.isEntry) {
580
585
  let hasBytecodeMoudle = false;
@@ -638,12 +643,13 @@ function getMainFilePath(options) {
638
643
  }
639
644
  mainFilePath = options?.index ? "index.js" : "main.js";
640
645
  }
646
+ log.info(`Using "${mainFilePath}" as main file`, { timestamp: true });
641
647
  return mainFilePath.replace(/\.[cm]?ts$/, ".js");
642
648
  }
643
649
  function parseVersionPath(versionPath) {
644
650
  versionPath = normalizePath(versionPath);
645
651
  if (!versionPath.startsWith("./")) {
646
- versionPath = "./" + versionPath;
652
+ versionPath = `./${versionPath}`;
647
653
  }
648
654
  return new URL(versionPath, "file://").pathname.slice(1);
649
655
  }
@@ -661,33 +667,43 @@ async function electronWithUpdater(options) {
661
667
  useNotBundle = true,
662
668
  logParsedOptions
663
669
  } = options;
664
- if (!pkg) {
665
- log.error(`package.json not found`, { timestamp: true });
670
+ if (!pkg || !pkg.version || !pkg.name || !pkg.main) {
671
+ log.error("package.json not found or invalid", { timestamp: true });
666
672
  return void 0;
667
673
  }
668
- if (!pkg.version || !pkg.name || !pkg.main) {
669
- log.error(`package.json not valid`, { timestamp: true });
670
- return void 0;
674
+ const isESM = pkg.type === "module";
675
+ let bytecodeOptions = typeof bytecode === "object" ? bytecode : bytecode === true ? { enable: true } : void 0;
676
+ if (isESM && bytecodeOptions?.enable) {
677
+ bytecodeLog.warn(
678
+ '`bytecodePlugin` does not support ES module, please remove "type": "module" in package.json',
679
+ { timestamp: true }
680
+ );
681
+ bytecodeOptions = void 0;
671
682
  }
672
- const _options = parseOptions(pkg, sourcemap, minify, updater);
673
- const bytecodeOptions = typeof bytecode === "object" ? bytecode : bytecode === true ? { enable: true } : void 0;
683
+ const {
684
+ buildAsarOption,
685
+ buildEntryOption,
686
+ buildVersionOption,
687
+ postBuild,
688
+ cert
689
+ } = parseOptions(pkg, sourcemap, minify, updater);
690
+ const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath } = buildEntryOption;
674
691
  try {
675
- fs3.rmSync(_options.buildAsarOption.electronDistPath, { recursive: true, force: true });
676
- fs3.rmSync(_options.buildEntryOption.entryOutputDirPath, { recursive: true, force: true });
692
+ fs3.rmSync(buildAsarOption.electronDistPath, { recursive: true, force: true });
693
+ fs3.rmSync(entryOutputDirPath, { recursive: true, force: true });
677
694
  } catch {
678
695
  }
679
- log.info(`remove old files`, { timestamp: true });
680
- const { buildAsarOption, buildEntryOption, buildVersionOption, postBuild, cert } = _options;
681
- const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath } = buildEntryOption;
696
+ log.info(`Clear cache files`, { timestamp: true });
682
697
  sourcemap ??= isBuild || !!process.env.VSCODE_DEBUG;
683
698
  const _appPath = normalizePath(path5.join(entryOutputDirPath, "entry.js"));
684
699
  if (path5.resolve(normalizePath(pkg.main)) !== path5.resolve(_appPath)) {
685
- throw new Error(`wrong "main" field in package.json: "${pkg.main}", it should be "${_appPath}"`);
700
+ throw new Error(`Wrong "main" field in package.json: "${pkg.main}", it should be "${_appPath}"`);
686
701
  }
687
702
  const define = {
688
703
  __EIU_ELECTRON_DIST_PATH__: JSON.stringify(buildAsarOption.electronDistPath),
689
704
  __EIU_ENTRY_DIST_PATH__: JSON.stringify(buildEntryOption.entryOutputDirPath),
690
705
  __EIU_IS_DEV__: JSON.stringify(!isBuild),
706
+ __EIU_IS_ESM__: JSON.stringify(isESM),
691
707
  __EIU_MAIN_DEV_DIR__: JSON.stringify(buildAsarOption.electronDistPath),
692
708
  __EIU_MAIN_FILE__: JSON.stringify(getMainFilePath(_main.files)),
693
709
  __EIU_SIGNATURE_CERT__: JSON.stringify(cert),
@@ -696,10 +712,11 @@ async function electronWithUpdater(options) {
696
712
  const _buildEntry = async () => {
697
713
  await buildEntry(
698
714
  buildEntryOption,
715
+ isESM,
699
716
  define,
700
717
  bytecodeOptions
701
718
  );
702
- log.info(`vite build entry to '${entryOutputDirPath}'`, { timestamp: true });
719
+ log.info(`Build entry to '${entryOutputDirPath}'`, { timestamp: true });
703
720
  };
704
721
  const _postBuild = postBuild ? async () => await postBuild({
705
722
  getPathFromEntryOutputDir(...paths) {
@@ -712,7 +729,7 @@ async function electronWithUpdater(options) {
712
729
  try {
713
730
  fs3.cpSync(from, target);
714
731
  } catch (error) {
715
- log.warn(`copy failed: ${error}`);
732
+ log.warn(`Copy failed: ${error}`, { timestamp: true });
716
733
  }
717
734
  }
718
735
  }
@@ -774,7 +791,7 @@ async function electronWithUpdater(options) {
774
791
  await _postBuild();
775
792
  const buffer = await buildAsar(buildAsarOption);
776
793
  if (!buildVersionJson && !isCI) {
777
- log.warn("no `buildVersionJson` setup, skip build version json. Will build in CI by default", { timestamp: true });
794
+ log.warn("No `buildVersionJson` setup, skip build version json. Will build in CI by default", { timestamp: true });
778
795
  } else {
779
796
  await buildVersion(buildVersionOption, buffer);
780
797
  }
@@ -800,7 +817,7 @@ async function electronWithUpdater(options) {
800
817
  ...electronPluginOptions,
801
818
  updater: { buildAsarOption, buildEntryOption, buildVersionOption }
802
819
  },
803
- (key, value) => (key === "privateKey" || key === "cert") && !(typeof logParsedOptions === "object" && logParsedOptions.showKeys === true) ? "***" : value,
820
+ (key, value) => ["privateKey", "cert", "define"].includes(key) && !(typeof logParsedOptions === "object" && logParsedOptions.showKeys === true) ? "***" : value,
804
821
  2
805
822
  ),
806
823
  { timestamp: true }
@@ -831,5 +848,6 @@ async function electronWithUpdater(options) {
831
848
  }
832
849
  return [ElectronSimple(electronPluginOptions), extraHmrPlugin];
833
850
  }
851
+ var vite_default = electronWithUpdater;
834
852
 
835
- export { debugStartup, electronWithUpdater };
853
+ export { debugStartup, vite_default as default, electronWithUpdater };
@@ -1,10 +1,33 @@
1
1
  declare function hashBuffer(data: string | Buffer, length: number): Buffer;
2
2
  declare function aesEncrypt(plainText: string, key: Buffer, iv: Buffer): string;
3
+ /**
4
+ * Default function to generate asar signature, returns generated signature
5
+ * @param buffer file buffer
6
+ * @param privateKey primary key
7
+ * @param cert certificate
8
+ * @param version target version
9
+ */
3
10
  declare function defaultSignature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
4
11
  declare function aesDecrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
12
+ /**
13
+ * Default function to verify asar signature,
14
+ * if signature is valid, returns the version, otherwise returns `undefined`
15
+ * @param buffer file buffer
16
+ * @param version target version
17
+ * @param signature signature
18
+ * @param cert certificate
19
+ */
5
20
  declare function defaultVerifySignature(buffer: Buffer, version: string, signature: string, cert: string): boolean;
6
21
 
22
+ /**
23
+ * Default function to compress file using brotli
24
+ * @param buffer uncompressed file buffer
25
+ */
7
26
  declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
27
+ /**
28
+ * Default function to decompress file using brotli
29
+ * @param buffer compressed file buffer
30
+ */
8
31
  declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
9
32
 
10
33
  export { defaultUnzipFile as a, aesEncrypt as b, defaultSignature as c, defaultZipFile as d, aesDecrypt as e, defaultVerifySignature as f, hashBuffer as h };
@@ -1,10 +1,33 @@
1
1
  declare function hashBuffer(data: string | Buffer, length: number): Buffer;
2
2
  declare function aesEncrypt(plainText: string, key: Buffer, iv: Buffer): string;
3
+ /**
4
+ * Default function to generate asar signature, returns generated signature
5
+ * @param buffer file buffer
6
+ * @param privateKey primary key
7
+ * @param cert certificate
8
+ * @param version target version
9
+ */
3
10
  declare function defaultSignature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
4
11
  declare function aesDecrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
12
+ /**
13
+ * Default function to verify asar signature,
14
+ * if signature is valid, returns the version, otherwise returns `undefined`
15
+ * @param buffer file buffer
16
+ * @param version target version
17
+ * @param signature signature
18
+ * @param cert certificate
19
+ */
5
20
  declare function defaultVerifySignature(buffer: Buffer, version: string, signature: string, cert: string): boolean;
6
21
 
22
+ /**
23
+ * Default function to compress file using brotli
24
+ * @param buffer uncompressed file buffer
25
+ */
7
26
  declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
27
+ /**
28
+ * Default function to decompress file using brotli
29
+ * @param buffer compressed file buffer
30
+ */
8
31
  declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
9
32
 
10
33
  export { defaultUnzipFile as a, aesEncrypt as b, defaultSignature as c, defaultZipFile as d, aesDecrypt as e, defaultVerifySignature as f, hashBuffer as h };
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.9",
5
- "description": "electron incremental update tools, powered by vite",
4
+ "version": "2.0.1",
5
+ "description": "Electron incremental update tools with Vite plugin, support bytecode protection",
6
6
  "author": "subframe7536",
7
7
  "license": "MIT",
8
- "repository": "https://github.com/subframe7536/electron-incremental-update",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/subframe7536/electron-incremental-update.git"
11
+ },
9
12
  "keywords": [
10
13
  "electron",
11
14
  "incremental update",
@@ -70,15 +73,15 @@
70
73
  "devDependencies": {
71
74
  "@subframe7536/eslint-config": "^0.7.3",
72
75
  "@types/babel__core": "^7.20.5",
73
- "@types/node": "^20.14.11",
76
+ "@types/node": "^20.14.12",
74
77
  "bumpp": "^9.4.1",
75
78
  "electron": "28.2.10",
76
79
  "eslint": "^9.7.0",
77
80
  "esno": "^4.7.0",
78
- "tsup": "^8.2.1",
79
- "typescript": "^5.5.3",
81
+ "tsup": "^8.2.2",
82
+ "typescript": "^5.5.4",
80
83
  "vite": "^5.3.4",
81
84
  "vite-plugin-electron": "^0.28.7",
82
- "vitest": "^2.0.3"
85
+ "vitest": "^2.0.4"
83
86
  }
84
87
  }
@@ -1,81 +0,0 @@
1
- import { __require } from './chunk-72ZAJ7AF.js';
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- import { app } from 'electron';
5
-
6
- var isDev = __EIU_IS_DEV__;
7
- var isWin = process.platform === "win32";
8
- var isMac = process.platform === "darwin";
9
- var isLinux = process.platform === "linux";
10
- function getPathFromAppNameAsar(...paths) {
11
- return isDev ? "DEV.asar" : path.join(path.dirname(app.getAppPath()), `${app.name}.asar`, ...paths);
12
- }
13
- function getAppVersion() {
14
- return isDev ? getEntryVersion() : fs.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
15
- }
16
- function getEntryVersion() {
17
- return app.getVersion();
18
- }
19
- function requireNative(moduleName) {
20
- return __require(path.join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
21
- }
22
- function restartApp() {
23
- app.relaunch();
24
- app.quit();
25
- }
26
- function setAppUserModelId(id) {
27
- if (isWin) {
28
- app.setAppUserModelId(id ?? `org.${app.name}`);
29
- }
30
- }
31
- function disableHWAccForWin7() {
32
- if (__require("node:os").release().startsWith("6.1")) {
33
- app.disableHardwareAcceleration();
34
- }
35
- }
36
- function singleInstance(window) {
37
- const result = app.requestSingleInstanceLock();
38
- if (result) {
39
- app.on("second-instance", () => {
40
- if (window) {
41
- window.show();
42
- if (window.isMinimized()) {
43
- window.restore();
44
- }
45
- window.focus();
46
- }
47
- });
48
- } else {
49
- app.quit();
50
- }
51
- return result;
52
- }
53
- function setPortableAppDataPath(dirName = "data") {
54
- const portablePath = path.join(path.dirname(app.getPath("exe")), dirName);
55
- if (!fs.existsSync(portablePath)) {
56
- fs.mkdirSync(portablePath);
57
- }
58
- app.setPath("appData", portablePath);
59
- }
60
- function loadPage(win, htmlFilePath = "index.html") {
61
- if (isDev) {
62
- win.loadURL(process.env.VITE_DEV_SERVER_URL + htmlFilePath);
63
- } else {
64
- win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
65
- }
66
- }
67
- function getPathFromPreload(...paths) {
68
- return isDev ? path.join(app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
69
- }
70
- function getPathFromPublic(...paths) {
71
- return isDev ? path.join(app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
72
- }
73
- function getPathFromEntryAsar(...paths) {
74
- return path.join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
75
- }
76
- function handleUnexpectedErrors(callback) {
77
- process.on("uncaughtException", callback);
78
- process.on("unhandledRejection", callback);
79
- }
80
-
81
- export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
@@ -1,27 +0,0 @@
1
- interface Version {
2
- major: number;
3
- minor: number;
4
- patch: number;
5
- stage: string;
6
- stageVersion: number;
7
- }
8
- declare function parseVersion(version: string): Version;
9
- declare function defaultIsLowerVersion(oldVer: string, newVer: string): boolean;
10
- /**
11
- * update info json
12
- */
13
- type UpdateInfo = {
14
- signature: string;
15
- minimumVersion: string;
16
- version: string;
17
- };
18
- /**
19
- * {@link UpdateInfo} with beta
20
- */
21
- type UpdateJSON = UpdateInfo & {
22
- beta: UpdateInfo;
23
- };
24
- declare function isUpdateJSON(json: any): json is UpdateJSON;
25
- declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
26
-
27
- export { type UpdateJSON as U, type Version as V, type UpdateInfo as a, defaultVersionJsonGenerator as b, defaultIsLowerVersion as d, isUpdateJSON as i, parseVersion as p };
@@ -1,27 +0,0 @@
1
- interface Version {
2
- major: number;
3
- minor: number;
4
- patch: number;
5
- stage: string;
6
- stageVersion: number;
7
- }
8
- declare function parseVersion(version: string): Version;
9
- declare function defaultIsLowerVersion(oldVer: string, newVer: string): boolean;
10
- /**
11
- * update info json
12
- */
13
- type UpdateInfo = {
14
- signature: string;
15
- minimumVersion: string;
16
- version: string;
17
- };
18
- /**
19
- * {@link UpdateInfo} with beta
20
- */
21
- type UpdateJSON = UpdateInfo & {
22
- beta: UpdateInfo;
23
- };
24
- declare function isUpdateJSON(json: any): json is UpdateJSON;
25
- declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
26
-
27
- export { type UpdateJSON as U, type Version as V, type UpdateInfo as a, defaultVersionJsonGenerator as b, defaultIsLowerVersion as d, isUpdateJSON as i, parseVersion as p };