electron-incremental-update 0.8.5 → 0.8.7
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 +17 -10
- package/dist/{chunk-GXZSAUBR.mjs → chunk-5BZLJPHJ.mjs} +8 -1
- package/dist/chunk-CMBFI77K.mjs +75 -0
- package/dist/chunk-OGAOUYV3.mjs +99 -0
- package/dist/index.d.mts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.js +74 -57
- package/dist/index.mjs +21 -22
- package/dist/{updateJson.d.mts → updateJson-7e45d9e1.d.ts} +1 -2
- package/dist/utils.d.mts +43 -40
- package/dist/utils.d.ts +43 -40
- package/dist/utils.js +106 -120
- package/dist/utils.mjs +17 -14
- package/dist/vite.d.mts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +7 -13
- package/dist/vite.mjs +3 -7
- package/package.json +1 -1
- package/dist/chunk-2JVXVTC5.mjs +0 -9
- package/dist/chunk-CR6HTU6P.mjs +0 -170
- package/dist/chunk-ZFXKCRJC.mjs +0 -11
- package/dist/updateJson.d.ts +0 -12
- package/dist/updateJson.js +0 -33
- package/dist/updateJson.mjs +0 -7
package/README.md
CHANGED
|
@@ -51,25 +51,25 @@ src
|
|
|
51
51
|
|
|
52
52
|
```ts
|
|
53
53
|
// electron/app.ts
|
|
54
|
-
import {
|
|
54
|
+
import { initApp, parseGithubCdnURL } from 'electron-incremental-update'
|
|
55
55
|
import { name, repository } from '../package.json'
|
|
56
56
|
|
|
57
57
|
const SIGNATURE_CERT = '' // auto generate certificate when start app
|
|
58
58
|
|
|
59
|
-
const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
|
|
60
|
-
const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
|
|
61
59
|
initApp({ onStart: console.log })
|
|
62
60
|
// can be updater option or function that return updater
|
|
63
61
|
.setUpdater({
|
|
64
62
|
SIGNATURE_CERT,
|
|
65
63
|
productName: name,
|
|
66
64
|
repository,
|
|
67
|
-
updateJsonURL: parseGithubCdnURL(repository,
|
|
68
|
-
releaseAsarURL: parseGithubCdnURL(repository,
|
|
65
|
+
updateJsonURL: parseGithubCdnURL(repository, '...', 'version.json'),
|
|
66
|
+
releaseAsarURL: parseGithubCdnURL(repository, '...', `download/latest/${name}.asar.gz`),
|
|
69
67
|
receiveBeta: true
|
|
70
68
|
})
|
|
71
69
|
```
|
|
72
70
|
|
|
71
|
+
- [some cdn resources](https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34):
|
|
72
|
+
|
|
73
73
|
### setup vite.config.ts
|
|
74
74
|
|
|
75
75
|
make sure the plugin is set in the **last** build task
|
|
@@ -121,7 +121,7 @@ export default defineConfig(({ command }) => {
|
|
|
121
121
|
```json
|
|
122
122
|
{
|
|
123
123
|
// ...
|
|
124
|
-
"main": "app.js" // <- app entry file
|
|
124
|
+
"main": "app.js" // <- app entry file path
|
|
125
125
|
}
|
|
126
126
|
```
|
|
127
127
|
|
|
@@ -174,7 +174,7 @@ However, you have the option to customize the download function when creating th
|
|
|
174
174
|
```ts
|
|
175
175
|
// electron/main/index.ts
|
|
176
176
|
import type { StartupWithUpdater, Updater } from 'electron-incremental-update'
|
|
177
|
-
import {
|
|
177
|
+
import { appInfo, getProductAsarPath } from 'electron-incremental-update/utils'
|
|
178
178
|
import { app } from 'electron'
|
|
179
179
|
import { name } from '../../package.json'
|
|
180
180
|
|
|
@@ -182,8 +182,8 @@ const startup: StartupWithUpdater = (updater: Updater) => {
|
|
|
182
182
|
await app.whenReady()
|
|
183
183
|
console.log('\ncurrent:')
|
|
184
184
|
console.log(`\tasar path: ${getProductAsarPath(name)}`)
|
|
185
|
-
console.log(`\
|
|
186
|
-
console.log(`\
|
|
185
|
+
console.log(`\tapp: ${appInfo.appVersion(name)}`)
|
|
186
|
+
console.log(`\telectron: ${appInfo.electronVersion}`)
|
|
187
187
|
updater.onDownloading = ({ percent }) => {
|
|
188
188
|
console.log(percent)
|
|
189
189
|
}
|
|
@@ -209,11 +209,18 @@ export default startup
|
|
|
209
209
|
|
|
210
210
|
### use native modules
|
|
211
211
|
|
|
212
|
+
the native modules is packed in `app.asar`, so you cannot directly access it when in production
|
|
213
|
+
|
|
214
|
+
to use it, you can prebundle native modules, or use `requireNative` to load.
|
|
215
|
+
|
|
212
216
|
```ts
|
|
213
217
|
// db.ts
|
|
214
|
-
import { requireNative } from 'electron-incremental-update'
|
|
218
|
+
import { isNoSuchNativeModuleError, requireNative } from 'electron-incremental-update/utils'
|
|
215
219
|
|
|
216
220
|
const Database = requireNative<typeof import('better-sqlite3')>('better-sqlite3')
|
|
221
|
+
if (isNoSuchNativeModuleError(Database)) {
|
|
222
|
+
// ...
|
|
223
|
+
}
|
|
217
224
|
const db = new Database(':memory:')
|
|
218
225
|
db.exec(
|
|
219
226
|
'DROP TABLE IF EXISTS employees; '
|
|
@@ -30,7 +30,14 @@ var verify = (buffer, signature2, cert) => {
|
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
// src/updateJson.ts
|
|
34
|
+
function isUpdateJSON(json) {
|
|
35
|
+
const is = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
|
|
36
|
+
return is(json) && "beta" in json && is(json.beta);
|
|
37
|
+
}
|
|
38
|
+
|
|
33
39
|
export {
|
|
34
40
|
signature,
|
|
35
|
-
verify
|
|
41
|
+
verify,
|
|
42
|
+
isUpdateJSON
|
|
36
43
|
};
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
// src/utils/version.ts
|
|
10
|
+
function parseVersion(version) {
|
|
11
|
+
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
|
|
12
|
+
const match = semver.exec(version);
|
|
13
|
+
if (!match) {
|
|
14
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
15
|
+
}
|
|
16
|
+
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
17
|
+
const ret = {
|
|
18
|
+
major,
|
|
19
|
+
minor,
|
|
20
|
+
patch,
|
|
21
|
+
stage: "",
|
|
22
|
+
stageVersion: -1
|
|
23
|
+
};
|
|
24
|
+
if (match[4]) {
|
|
25
|
+
let [stage, _v] = match[4].split(".");
|
|
26
|
+
ret.stage = stage;
|
|
27
|
+
ret.stageVersion = Number(_v) || -1;
|
|
28
|
+
}
|
|
29
|
+
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
30
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
31
|
+
}
|
|
32
|
+
return ret;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/utils/zip.ts
|
|
36
|
+
import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
37
|
+
import { gunzip, gzip } from "node:zlib";
|
|
38
|
+
async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
39
|
+
if (!existsSync(gzipPath)) {
|
|
40
|
+
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
41
|
+
}
|
|
42
|
+
const compressedBuffer = readFileSync(gzipPath);
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
gunzip(compressedBuffer, (err, buffer) => {
|
|
45
|
+
rmSync(gzipPath);
|
|
46
|
+
if (err) {
|
|
47
|
+
reject(err);
|
|
48
|
+
}
|
|
49
|
+
writeFileSync(targetFilePath, buffer);
|
|
50
|
+
resolve(null);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
55
|
+
if (!existsSync(filePath)) {
|
|
56
|
+
throw new Error(`path to be zipped not exist: ${filePath}`);
|
|
57
|
+
}
|
|
58
|
+
const buffer = readFileSync(filePath);
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
gzip(buffer, (err, buffer2) => {
|
|
61
|
+
if (err) {
|
|
62
|
+
reject(err);
|
|
63
|
+
}
|
|
64
|
+
writeFileSync(targetFilePath, buffer2);
|
|
65
|
+
resolve(null);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export {
|
|
71
|
+
__require,
|
|
72
|
+
parseVersion,
|
|
73
|
+
unzipFile,
|
|
74
|
+
zipFile
|
|
75
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__require
|
|
3
|
+
} from "./chunk-CMBFI77K.mjs";
|
|
4
|
+
|
|
5
|
+
// src/utils/core.ts
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { release } from "node:os";
|
|
9
|
+
import { app } from "electron";
|
|
10
|
+
var DEFAULT_APP_NAME = "product";
|
|
11
|
+
var appInfo = {
|
|
12
|
+
dev: !app.isPackaged,
|
|
13
|
+
win: process.platform === "win32",
|
|
14
|
+
mac: process.platform === "darwin",
|
|
15
|
+
linux: process.platform === "linux",
|
|
16
|
+
electronVersion: getElectronVersion(),
|
|
17
|
+
appVersion: getAppVersion,
|
|
18
|
+
systemVersion: release()
|
|
19
|
+
};
|
|
20
|
+
function getLocale() {
|
|
21
|
+
return app.isReady() ? app.getLocale() : void 0;
|
|
22
|
+
}
|
|
23
|
+
function getProductAsarPath(name = DEFAULT_APP_NAME) {
|
|
24
|
+
return !app.isPackaged ? "DEV.asar" : join(dirname(app.getAppPath()), `${name}.asar`);
|
|
25
|
+
}
|
|
26
|
+
function getElectronVersion() {
|
|
27
|
+
return app.getVersion();
|
|
28
|
+
}
|
|
29
|
+
function getAppVersion(name = DEFAULT_APP_NAME) {
|
|
30
|
+
return app.isPackaged ? readFileSync(join(getProductAsarPath(name), "version"), "utf-8") : getElectronVersion();
|
|
31
|
+
}
|
|
32
|
+
var NoSuchNativeModuleError = class extends Error {
|
|
33
|
+
moduleName;
|
|
34
|
+
constructor(moduleName) {
|
|
35
|
+
super(`no such native module: ${moduleName}`);
|
|
36
|
+
this.moduleName = moduleName;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
function isNoSuchNativeModuleError(e) {
|
|
40
|
+
return e instanceof NoSuchNativeModuleError;
|
|
41
|
+
}
|
|
42
|
+
function requireNative(packageName) {
|
|
43
|
+
const path = app.isPackaged ? join(app.getAppPath(), "node_modules", packageName) : packageName;
|
|
44
|
+
try {
|
|
45
|
+
return __require(path);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return new NoSuchNativeModuleError(packageName);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/utils/utils.ts
|
|
52
|
+
import { app as app2 } from "electron";
|
|
53
|
+
function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
54
|
+
if (!originRepoURL.startsWith("https://github.com/")) {
|
|
55
|
+
throw new Error("origin url must start with https://github.com/");
|
|
56
|
+
}
|
|
57
|
+
originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
|
|
58
|
+
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
59
|
+
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
60
|
+
return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
61
|
+
}
|
|
62
|
+
function restartApp() {
|
|
63
|
+
app2.relaunch();
|
|
64
|
+
app2.quit();
|
|
65
|
+
}
|
|
66
|
+
function waitAppReady(duration = 1e3) {
|
|
67
|
+
if (app2.isReady()) {
|
|
68
|
+
return Promise.resolve();
|
|
69
|
+
}
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
const timeout = setTimeout(() => {
|
|
72
|
+
reject(new Error("app is not ready"));
|
|
73
|
+
}, duration);
|
|
74
|
+
app2.whenReady().then(() => {
|
|
75
|
+
clearTimeout(timeout);
|
|
76
|
+
resolve();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function handleUnexpectedErrors(callback) {
|
|
81
|
+
process.on("uncaughtException", callback);
|
|
82
|
+
process.on("unhandledRejection", callback);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export {
|
|
86
|
+
DEFAULT_APP_NAME,
|
|
87
|
+
appInfo,
|
|
88
|
+
getLocale,
|
|
89
|
+
getProductAsarPath,
|
|
90
|
+
getElectronVersion,
|
|
91
|
+
getAppVersion,
|
|
92
|
+
NoSuchNativeModuleError,
|
|
93
|
+
isNoSuchNativeModuleError,
|
|
94
|
+
requireNative,
|
|
95
|
+
parseGithubCdnURL,
|
|
96
|
+
restartApp,
|
|
97
|
+
waitAppReady,
|
|
98
|
+
handleUnexpectedErrors
|
|
99
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UpdateJSON } from './updateJson.
|
|
1
|
+
import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
|
|
2
2
|
|
|
3
3
|
declare class MinimumVersionError extends Error {
|
|
4
4
|
currentVersion: string;
|
|
@@ -141,11 +141,11 @@ interface UpdaterOption {
|
|
|
141
141
|
*/
|
|
142
142
|
SIGNATURE_CERT: string;
|
|
143
143
|
/**
|
|
144
|
-
* name of your application
|
|
144
|
+
* name of your application, you can use the `name` in `package.json`
|
|
145
145
|
*
|
|
146
|
-
*
|
|
146
|
+
* @default DEFAULT_APP_NAME
|
|
147
147
|
*/
|
|
148
|
-
productName
|
|
148
|
+
productName?: string;
|
|
149
149
|
/**
|
|
150
150
|
* repository url, e.g. `https://github.com/electron/electron`
|
|
151
151
|
*
|
|
@@ -184,7 +184,6 @@ declare class IncrementalUpdater implements Updater {
|
|
|
184
184
|
logger?: Logger;
|
|
185
185
|
onDownloading?: (progress: DownloadingInfo) => void;
|
|
186
186
|
get productName(): string;
|
|
187
|
-
set productName(name: string);
|
|
188
187
|
get receiveBeta(): boolean;
|
|
189
188
|
set receiveBeta(receiveBeta: boolean);
|
|
190
189
|
constructor(option: UpdaterOption);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UpdateJSON } from './updateJson.js';
|
|
1
|
+
import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
|
|
2
2
|
|
|
3
3
|
declare class MinimumVersionError extends Error {
|
|
4
4
|
currentVersion: string;
|
|
@@ -141,11 +141,11 @@ interface UpdaterOption {
|
|
|
141
141
|
*/
|
|
142
142
|
SIGNATURE_CERT: string;
|
|
143
143
|
/**
|
|
144
|
-
* name of your application
|
|
144
|
+
* name of your application, you can use the `name` in `package.json`
|
|
145
145
|
*
|
|
146
|
-
*
|
|
146
|
+
* @default DEFAULT_APP_NAME
|
|
147
147
|
*/
|
|
148
|
-
productName
|
|
148
|
+
productName?: string;
|
|
149
149
|
/**
|
|
150
150
|
* repository url, e.g. `https://github.com/electron/electron`
|
|
151
151
|
*
|
|
@@ -184,7 +184,6 @@ declare class IncrementalUpdater implements Updater {
|
|
|
184
184
|
logger?: Logger;
|
|
185
185
|
onDownloading?: (progress: DownloadingInfo) => void;
|
|
186
186
|
get productName(): string;
|
|
187
|
-
set productName(name: string);
|
|
188
187
|
get receiveBeta(): boolean;
|
|
189
188
|
set receiveBeta(receiveBeta: boolean);
|
|
190
189
|
constructor(option: UpdaterOption);
|
package/dist/index.js
CHANGED
|
@@ -36,59 +36,39 @@ __export(src_exports, {
|
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(src_exports);
|
|
38
38
|
var import_node_path2 = require("path");
|
|
39
|
-
var
|
|
40
|
-
var
|
|
39
|
+
var import_node_fs4 = require("fs");
|
|
40
|
+
var import_electron4 = __toESM(require("electron"));
|
|
41
41
|
|
|
42
42
|
// src/updater/index.ts
|
|
43
|
-
var
|
|
43
|
+
var import_node_fs3 = require("fs");
|
|
44
44
|
var import_promises = require("fs/promises");
|
|
45
45
|
|
|
46
|
-
// src/utils.ts
|
|
46
|
+
// src/utils/core.ts
|
|
47
47
|
var import_node_fs = require("fs");
|
|
48
48
|
var import_node_path = require("path");
|
|
49
|
-
var
|
|
50
|
-
var import_electron =
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
var import_node_os = require("os");
|
|
50
|
+
var import_electron = require("electron");
|
|
51
|
+
var DEFAULT_APP_NAME = "product";
|
|
52
|
+
var appInfo = {
|
|
53
|
+
dev: !import_electron.app.isPackaged,
|
|
54
|
+
win: process.platform === "win32",
|
|
55
|
+
mac: process.platform === "darwin",
|
|
56
|
+
linux: process.platform === "linux",
|
|
57
|
+
electronVersion: getElectronVersion(),
|
|
58
|
+
appVersion: getAppVersion,
|
|
59
|
+
systemVersion: (0, import_node_os.release)()
|
|
55
60
|
};
|
|
56
|
-
function getProductAsarPath(name) {
|
|
57
|
-
return
|
|
61
|
+
function getProductAsarPath(name = DEFAULT_APP_NAME) {
|
|
62
|
+
return !import_electron.app.isPackaged ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`);
|
|
58
63
|
}
|
|
59
|
-
function
|
|
60
|
-
return import_electron.
|
|
61
|
-
}
|
|
62
|
-
function getProductVersion(name) {
|
|
63
|
-
return info.dev ? getEntryVersion() : (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8");
|
|
64
|
-
}
|
|
65
|
-
function waitAppReady(duration = 1e3) {
|
|
66
|
-
return new Promise((resolve2, reject) => {
|
|
67
|
-
const timeout = setTimeout(() => {
|
|
68
|
-
reject(new Error("app is not ready"));
|
|
69
|
-
}, duration);
|
|
70
|
-
import_electron.default.app.whenReady().then(() => {
|
|
71
|
-
clearTimeout(timeout);
|
|
72
|
-
resolve2();
|
|
73
|
-
});
|
|
74
|
-
});
|
|
64
|
+
function getElectronVersion() {
|
|
65
|
+
return import_electron.app.getVersion();
|
|
75
66
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
79
|
-
}
|
|
80
|
-
const compressedBuffer = (0, import_node_fs.readFileSync)(gzipPath);
|
|
81
|
-
return new Promise((resolve2, reject) => {
|
|
82
|
-
(0, import_node_zlib.gunzip)(compressedBuffer, (err, buffer) => {
|
|
83
|
-
(0, import_node_fs.rmSync)(gzipPath);
|
|
84
|
-
if (err) {
|
|
85
|
-
reject(err);
|
|
86
|
-
}
|
|
87
|
-
(0, import_node_fs.writeFileSync)(targetFilePath, buffer);
|
|
88
|
-
resolve2(null);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
67
|
+
function getAppVersion(name = DEFAULT_APP_NAME) {
|
|
68
|
+
return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getElectronVersion();
|
|
91
69
|
}
|
|
70
|
+
|
|
71
|
+
// src/utils/version.ts
|
|
92
72
|
function parseVersion(version) {
|
|
93
73
|
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
|
|
94
74
|
const match = semver.exec(version);
|
|
@@ -114,6 +94,43 @@ function parseVersion(version) {
|
|
|
114
94
|
return ret;
|
|
115
95
|
}
|
|
116
96
|
|
|
97
|
+
// src/utils/zip.ts
|
|
98
|
+
var import_node_fs2 = require("fs");
|
|
99
|
+
var import_node_zlib = require("zlib");
|
|
100
|
+
async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
101
|
+
if (!(0, import_node_fs2.existsSync)(gzipPath)) {
|
|
102
|
+
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
103
|
+
}
|
|
104
|
+
const compressedBuffer = (0, import_node_fs2.readFileSync)(gzipPath);
|
|
105
|
+
return new Promise((resolve2, reject) => {
|
|
106
|
+
(0, import_node_zlib.gunzip)(compressedBuffer, (err, buffer) => {
|
|
107
|
+
(0, import_node_fs2.rmSync)(gzipPath);
|
|
108
|
+
if (err) {
|
|
109
|
+
reject(err);
|
|
110
|
+
}
|
|
111
|
+
(0, import_node_fs2.writeFileSync)(targetFilePath, buffer);
|
|
112
|
+
resolve2(null);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/utils/utils.ts
|
|
118
|
+
var import_electron2 = require("electron");
|
|
119
|
+
function waitAppReady(duration = 1e3) {
|
|
120
|
+
if (import_electron2.app.isReady()) {
|
|
121
|
+
return Promise.resolve();
|
|
122
|
+
}
|
|
123
|
+
return new Promise((resolve2, reject) => {
|
|
124
|
+
const timeout = setTimeout(() => {
|
|
125
|
+
reject(new Error("app is not ready"));
|
|
126
|
+
}, duration);
|
|
127
|
+
import_electron2.app.whenReady().then(() => {
|
|
128
|
+
clearTimeout(timeout);
|
|
129
|
+
resolve2();
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
117
134
|
// src/crypto.ts
|
|
118
135
|
var import_node_crypto = require("crypto");
|
|
119
136
|
function decrypt(encryptedText, key2, iv) {
|
|
@@ -168,11 +185,11 @@ var DownloadError = class extends Error {
|
|
|
168
185
|
};
|
|
169
186
|
|
|
170
187
|
// src/updater/defaultFunctions.ts
|
|
171
|
-
var
|
|
188
|
+
var import_electron3 = require("electron");
|
|
172
189
|
var downloadJSONDefault = async (url, headers) => {
|
|
173
190
|
await waitAppReady();
|
|
174
191
|
return new Promise((resolve2, reject) => {
|
|
175
|
-
const request =
|
|
192
|
+
const request = import_electron3.net.request({
|
|
176
193
|
url,
|
|
177
194
|
method: "GET",
|
|
178
195
|
redirect: "follow"
|
|
@@ -206,7 +223,7 @@ var downloadBufferDefault = async (url, headers, total, onDownloading) => {
|
|
|
206
223
|
await waitAppReady();
|
|
207
224
|
let current = 0;
|
|
208
225
|
return new Promise((resolve2, reject) => {
|
|
209
|
-
const request =
|
|
226
|
+
const request = import_electron3.net.request({
|
|
210
227
|
url,
|
|
211
228
|
method: "GET",
|
|
212
229
|
redirect: "follow"
|
|
@@ -267,9 +284,6 @@ var IncrementalUpdater = class {
|
|
|
267
284
|
get productName() {
|
|
268
285
|
return this.option.productName;
|
|
269
286
|
}
|
|
270
|
-
set productName(name) {
|
|
271
|
-
this.option.productName = name;
|
|
272
|
-
}
|
|
273
287
|
get receiveBeta() {
|
|
274
288
|
return !!this.option.receiveBeta;
|
|
275
289
|
}
|
|
@@ -278,14 +292,17 @@ var IncrementalUpdater = class {
|
|
|
278
292
|
}
|
|
279
293
|
constructor(option) {
|
|
280
294
|
this.option = option;
|
|
295
|
+
if (!option.productName) {
|
|
296
|
+
this.option.productName = DEFAULT_APP_NAME;
|
|
297
|
+
}
|
|
281
298
|
this.asarPath = getProductAsarPath(this.productName);
|
|
282
299
|
this.gzipPath = `${this.asarPath}.gz`;
|
|
283
300
|
this.tmpFilePath = `${this.asarPath}.tmp`;
|
|
284
301
|
}
|
|
285
302
|
async needUpdate(version, minVersion) {
|
|
286
303
|
const compare = this.option.overrideFunctions?.compareVersion ?? compareVersionDefault;
|
|
287
|
-
const productVersion =
|
|
288
|
-
const entryVersion =
|
|
304
|
+
const productVersion = getAppVersion(this.option.productName);
|
|
305
|
+
const entryVersion = getElectronVersion();
|
|
289
306
|
if (await compare(entryVersion, minVersion)) {
|
|
290
307
|
throw new MinimumVersionError(entryVersion, minVersion);
|
|
291
308
|
}
|
|
@@ -293,11 +310,11 @@ var IncrementalUpdater = class {
|
|
|
293
310
|
return await compare(productVersion, version);
|
|
294
311
|
}
|
|
295
312
|
async parseData(format, data) {
|
|
296
|
-
if ((0,
|
|
313
|
+
if ((0, import_node_fs3.existsSync)(this.tmpFilePath)) {
|
|
297
314
|
this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
|
|
298
315
|
await (0, import_promises.rm)(this.tmpFilePath);
|
|
299
316
|
}
|
|
300
|
-
if ((0,
|
|
317
|
+
if ((0, import_node_fs3.existsSync)(this.gzipPath)) {
|
|
301
318
|
this.logger?.warn(`remove .gz file: ${this.gzipPath}`);
|
|
302
319
|
await (0, import_promises.rm)(this.gzipPath);
|
|
303
320
|
}
|
|
@@ -421,17 +438,17 @@ function initApp(appOptions) {
|
|
|
421
438
|
} = hooks || {};
|
|
422
439
|
function handleError(msg) {
|
|
423
440
|
onStartError?.(new Error(msg));
|
|
424
|
-
|
|
441
|
+
import_electron4.default.app.quit();
|
|
425
442
|
}
|
|
426
443
|
async function startup(updater) {
|
|
427
444
|
try {
|
|
428
445
|
const asarPath = getProductAsarPath(updater.productName);
|
|
429
446
|
const updateAsarPath = `${asarPath}.tmp`;
|
|
430
|
-
if ((0,
|
|
447
|
+
if ((0, import_node_fs4.existsSync)(updateAsarPath)) {
|
|
431
448
|
await beforeDoUpdate?.(asarPath, updateAsarPath);
|
|
432
|
-
(0,
|
|
449
|
+
(0, import_node_fs4.renameSync)(updateAsarPath, asarPath);
|
|
433
450
|
}
|
|
434
|
-
const mainDir =
|
|
451
|
+
const mainDir = import_electron4.default.app.isPackaged ? asarPath : electronDevDistPath;
|
|
435
452
|
const entry = (0, import_node_path2.resolve)(__dirname, mainDir, mainPath);
|
|
436
453
|
await beforeStart?.(entry);
|
|
437
454
|
require(entry)(updater);
|
package/dist/index.mjs
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
+
isUpdateJSON,
|
|
2
3
|
verify
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-5BZLJPHJ.mjs";
|
|
4
5
|
import {
|
|
5
|
-
|
|
6
|
+
DEFAULT_APP_NAME,
|
|
7
|
+
getAppVersion,
|
|
8
|
+
getElectronVersion,
|
|
6
9
|
getProductAsarPath,
|
|
7
|
-
getProductVersion,
|
|
8
|
-
parseVersion,
|
|
9
|
-
unzipFile,
|
|
10
10
|
waitAppReady
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import {
|
|
13
|
-
isUpdateJSON
|
|
14
|
-
} from "./chunk-2JVXVTC5.mjs";
|
|
11
|
+
} from "./chunk-OGAOUYV3.mjs";
|
|
15
12
|
import {
|
|
16
|
-
__require
|
|
17
|
-
|
|
13
|
+
__require,
|
|
14
|
+
parseVersion,
|
|
15
|
+
unzipFile
|
|
16
|
+
} from "./chunk-CMBFI77K.mjs";
|
|
18
17
|
|
|
19
18
|
// src/index.ts
|
|
20
19
|
import { resolve } from "node:path";
|
|
21
20
|
import { existsSync as existsSync2, renameSync } from "node:fs";
|
|
22
|
-
import
|
|
21
|
+
import Electron from "electron";
|
|
23
22
|
|
|
24
23
|
// src/updater/index.ts
|
|
25
24
|
import { existsSync } from "node:fs";
|
|
@@ -51,11 +50,11 @@ var DownloadError = class extends Error {
|
|
|
51
50
|
};
|
|
52
51
|
|
|
53
52
|
// src/updater/defaultFunctions.ts
|
|
54
|
-
import
|
|
53
|
+
import { net } from "electron";
|
|
55
54
|
var downloadJSONDefault = async (url, headers) => {
|
|
56
55
|
await waitAppReady();
|
|
57
56
|
return new Promise((resolve2, reject) => {
|
|
58
|
-
const request =
|
|
57
|
+
const request = net.request({
|
|
59
58
|
url,
|
|
60
59
|
method: "GET",
|
|
61
60
|
redirect: "follow"
|
|
@@ -89,7 +88,7 @@ var downloadBufferDefault = async (url, headers, total, onDownloading) => {
|
|
|
89
88
|
await waitAppReady();
|
|
90
89
|
let current = 0;
|
|
91
90
|
return new Promise((resolve2, reject) => {
|
|
92
|
-
const request =
|
|
91
|
+
const request = net.request({
|
|
93
92
|
url,
|
|
94
93
|
method: "GET",
|
|
95
94
|
redirect: "follow"
|
|
@@ -150,9 +149,6 @@ var IncrementalUpdater = class {
|
|
|
150
149
|
get productName() {
|
|
151
150
|
return this.option.productName;
|
|
152
151
|
}
|
|
153
|
-
set productName(name) {
|
|
154
|
-
this.option.productName = name;
|
|
155
|
-
}
|
|
156
152
|
get receiveBeta() {
|
|
157
153
|
return !!this.option.receiveBeta;
|
|
158
154
|
}
|
|
@@ -161,14 +157,17 @@ var IncrementalUpdater = class {
|
|
|
161
157
|
}
|
|
162
158
|
constructor(option) {
|
|
163
159
|
this.option = option;
|
|
160
|
+
if (!option.productName) {
|
|
161
|
+
this.option.productName = DEFAULT_APP_NAME;
|
|
162
|
+
}
|
|
164
163
|
this.asarPath = getProductAsarPath(this.productName);
|
|
165
164
|
this.gzipPath = `${this.asarPath}.gz`;
|
|
166
165
|
this.tmpFilePath = `${this.asarPath}.tmp`;
|
|
167
166
|
}
|
|
168
167
|
async needUpdate(version, minVersion) {
|
|
169
168
|
const compare = this.option.overrideFunctions?.compareVersion ?? compareVersionDefault;
|
|
170
|
-
const productVersion =
|
|
171
|
-
const entryVersion =
|
|
169
|
+
const productVersion = getAppVersion(this.option.productName);
|
|
170
|
+
const entryVersion = getElectronVersion();
|
|
172
171
|
if (await compare(entryVersion, minVersion)) {
|
|
173
172
|
throw new MinimumVersionError(entryVersion, minVersion);
|
|
174
173
|
}
|
|
@@ -304,7 +303,7 @@ function initApp(appOptions) {
|
|
|
304
303
|
} = hooks || {};
|
|
305
304
|
function handleError(msg) {
|
|
306
305
|
onStartError?.(new Error(msg));
|
|
307
|
-
|
|
306
|
+
Electron.app.quit();
|
|
308
307
|
}
|
|
309
308
|
async function startup(updater) {
|
|
310
309
|
try {
|
|
@@ -314,7 +313,7 @@ function initApp(appOptions) {
|
|
|
314
313
|
await beforeDoUpdate?.(asarPath, updateAsarPath);
|
|
315
314
|
renameSync(updateAsarPath, asarPath);
|
|
316
315
|
}
|
|
317
|
-
const mainDir =
|
|
316
|
+
const mainDir = Electron.app.isPackaged ? asarPath : electronDevDistPath;
|
|
318
317
|
const entry = resolve(__dirname, mainDir, mainPath);
|
|
319
318
|
await beforeStart?.(entry);
|
|
320
319
|
__require(entry)(updater);
|