electron-incremental-update 2.0.0-beta.1 → 2.0.0-beta.11

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 CHANGED
@@ -181,7 +181,7 @@ initApp({
181
181
  in `electron/main/index.ts`
182
182
 
183
183
  ```ts
184
- import { startupWithUpdater, UpdaterError } from 'electron-incremental-update'
184
+ import { UpdaterError, startupWithUpdater } from 'electron-incremental-update'
185
185
  import { getPathFromAppNameAsar, getVersions } from 'electron-incremental-update/utils'
186
186
  import { app } from 'electron'
187
187
 
@@ -199,7 +199,7 @@ export default startupWithUpdater((updater) => {
199
199
  }
200
200
  updater.logger = console
201
201
  updater.receiveBeta = true
202
-
202
+
203
203
  updater.checkUpdate().then(async (result) => {
204
204
  if (result === undefined) {
205
205
  console.log('Update Unavailable')
@@ -276,7 +276,7 @@ import Database from 'better-sqlite3'
276
276
 
277
277
  const db = new Database(':memory:', { nativeBinding: './better_sqlite3.node' })
278
278
 
279
- export function test() {
279
+ export function test(): void {
280
280
  db.exec(
281
281
  'DROP TABLE IF EXISTS employees; '
282
282
  + 'CREATE TABLE IF NOT EXISTS employees (name TEXT, salary INTEGER)',
@@ -0,0 +1,87 @@
1
+ import { __require } from './chunk-RCRKUKFX.js';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import electron 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(electron.app.getAppPath()), `${electron.app.name}.asar`, ...paths);
12
+ }
13
+ function getAppVersion() {
14
+ return isDev ? getEntryVersion() : fs.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
15
+ }
16
+ function getEntryVersion() {
17
+ return electron.app.getVersion();
18
+ }
19
+ function requireNative(moduleName) {
20
+ if (__EIU_IS_ESM__) {
21
+ throw new Error(`Cannot require "${path.join(__EIU_ENTRY_DIST_PATH__, moduleName)}", \`requireNative\` only support CommonJS`);
22
+ }
23
+ return __require(path.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
24
+ }
25
+ function restartApp() {
26
+ electron.app.relaunch();
27
+ electron.app.quit();
28
+ }
29
+ function setAppUserModelId(id) {
30
+ if (isWin) {
31
+ electron.app.setAppUserModelId(id ?? `org.${electron.app.name}`);
32
+ }
33
+ }
34
+ function disableHWAccForWin7() {
35
+ if (!__EIU_IS_ESM__ && __require("node:os").release().startsWith("6.1")) {
36
+ electron.app.disableHardwareAcceleration();
37
+ }
38
+ }
39
+ function singleInstance(window) {
40
+ const result = electron.app.requestSingleInstanceLock();
41
+ if (result) {
42
+ electron.app.on("second-instance", () => {
43
+ if (window) {
44
+ window.show();
45
+ if (window.isMinimized()) {
46
+ window.restore();
47
+ }
48
+ window.focus();
49
+ }
50
+ });
51
+ } else {
52
+ electron.app.quit();
53
+ }
54
+ return result;
55
+ }
56
+ function setPortableAppDataPath(dirName = "data") {
57
+ const portablePath = path.join(path.dirname(electron.app.getPath("exe")), dirName);
58
+ if (!fs.existsSync(portablePath)) {
59
+ fs.mkdirSync(portablePath);
60
+ }
61
+ electron.app.setPath("appData", portablePath);
62
+ }
63
+ function loadPage(win, htmlFilePath = "index.html") {
64
+ if (isDev) {
65
+ win.loadURL(process.env.VITE_DEV_SERVER_URL + htmlFilePath);
66
+ } else {
67
+ win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
68
+ }
69
+ }
70
+ function getPathFromMain(...paths) {
71
+ return isDev ? path.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "main", ...paths) : getPathFromAppNameAsar("main", ...paths);
72
+ }
73
+ function getPathFromPreload(...paths) {
74
+ return isDev ? path.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
75
+ }
76
+ function getPathFromPublic(...paths) {
77
+ return isDev ? path.join(electron.app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
78
+ }
79
+ function getPathFromEntryAsar(...paths) {
80
+ return path.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
81
+ }
82
+ function handleUnexpectedErrors(callback) {
83
+ process.on("uncaughtException", callback);
84
+ process.on("unhandledRejection", callback);
85
+ }
86
+
87
+ export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
@@ -0,0 +1,55 @@
1
+ import zlib from 'node:zlib';
2
+ import crypto from 'node:crypto';
3
+
4
+ // src/utils/zip.ts
5
+ async function defaultZipFile(buffer) {
6
+ return new Promise((resolve, reject) => {
7
+ zlib.brotliCompress(buffer, (err, buffer2) => {
8
+ if (err) {
9
+ reject(err);
10
+ } else {
11
+ resolve(buffer2);
12
+ }
13
+ });
14
+ });
15
+ }
16
+ async function defaultUnzipFile(buffer) {
17
+ return new Promise((resolve, reject) => {
18
+ zlib.brotliDecompress(buffer, (err, buffer2) => {
19
+ if (err) {
20
+ reject(err);
21
+ } else {
22
+ resolve(buffer2);
23
+ }
24
+ });
25
+ });
26
+ }
27
+ function hashBuffer(data, length) {
28
+ const hash = crypto.createHash("SHA256").update(data).digest("binary");
29
+ return Buffer.from(hash).subarray(0, length);
30
+ }
31
+ function aesEncrypt(plainText, key, iv) {
32
+ const cipher = crypto.createCipheriv("aes-256-cbc", key, iv);
33
+ return cipher.update(plainText, "utf8", "base64url") + cipher.final("base64url");
34
+ }
35
+ function defaultSignature(buffer, privateKey, cert, version) {
36
+ const sig = crypto.createSign("RSA-SHA256").update(buffer).sign(crypto.createPrivateKey(privateKey), "base64");
37
+ return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
38
+ }
39
+ function aesDecrypt(encryptedText, key, iv) {
40
+ const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
41
+ return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
42
+ }
43
+ function defaultVerifySignature(buffer, version, signature, cert) {
44
+ try {
45
+ const [sig, ver] = aesDecrypt(signature, hashBuffer(cert, 32), hashBuffer(buffer, 16)).split("%");
46
+ if (ver !== version) {
47
+ return false;
48
+ }
49
+ return crypto.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
50
+ } catch {
51
+ return false;
52
+ }
53
+ }
54
+
55
+ export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultZipFile, hashBuffer };
@@ -0,0 +1,70 @@
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") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/utils/version.ts
9
+ function parseVersion(version) {
10
+ const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
11
+ if (!match) {
12
+ throw new TypeError(`invalid version: ${version}`);
13
+ }
14
+ const [major, minor, patch] = match.slice(1, 4).map(Number);
15
+ const ret = {
16
+ major,
17
+ minor,
18
+ patch,
19
+ stage: "",
20
+ stageVersion: -1
21
+ };
22
+ if (match[4]) {
23
+ let [stage, _v] = match[4].split(".");
24
+ ret.stage = stage;
25
+ ret.stageVersion = Number(_v) || -1;
26
+ }
27
+ if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
28
+ throw new TypeError(`Invalid version: ${version}`);
29
+ }
30
+ return ret;
31
+ }
32
+ function defaultIsLowerVersion(oldVer, newVer) {
33
+ const oldV = parseVersion(oldVer);
34
+ const newV = parseVersion(newVer);
35
+ function compareStrings(str1, str2) {
36
+ if (str1 === "") {
37
+ return str2 !== "";
38
+ } else if (str2 === "") {
39
+ return true;
40
+ }
41
+ return str1 < str2;
42
+ }
43
+ for (let key of Object.keys(oldV)) {
44
+ if (key === "stage" && compareStrings(oldV[key], newV[key])) {
45
+ return true;
46
+ } else if (oldV[key] !== newV[key]) {
47
+ return oldV[key] < newV[key];
48
+ }
49
+ }
50
+ return false;
51
+ }
52
+ function isUpdateJSON(json) {
53
+ const is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
54
+ return is(json) && is(json?.beta);
55
+ }
56
+ function defaultVersionJsonGenerator(existingJson, signature, version, minimumVersion) {
57
+ existingJson.beta = {
58
+ version,
59
+ minimumVersion,
60
+ signature
61
+ };
62
+ if (!parseVersion(version).stage) {
63
+ existingJson.version = version;
64
+ existingJson.minimumVersion = minimumVersion;
65
+ existingJson.signature = signature;
66
+ }
67
+ return existingJson;
68
+ }
69
+
70
+ export { __require, defaultIsLowerVersion, defaultVersionJsonGenerator, isUpdateJSON, parseVersion };