electron-incremental-update 2.4.3 → 3.0.0-beta.2
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 +48 -40
- package/dist/download-BN4uMS4_.d.mts +39 -0
- package/dist/download-DO7iuxEJ.d.cts +39 -0
- package/dist/electron-BFoZUBhU.cjs +320 -0
- package/dist/electron-CJIoO4ny.mjs +180 -0
- package/dist/index.cjs +259 -331
- package/dist/index.d.cts +179 -169
- package/dist/index.d.mts +204 -0
- package/dist/index.mjs +271 -0
- package/dist/provider.cjs +142 -330
- package/dist/provider.d.cts +113 -114
- package/dist/provider.d.mts +133 -0
- package/dist/provider.mjs +152 -0
- package/dist/types-BM9Jfu7q.d.cts +154 -0
- package/dist/types-DASqEPXE.d.mts +154 -0
- package/dist/utils.cjs +43 -381
- package/dist/utils.d.cts +117 -85
- package/dist/utils.d.mts +161 -0
- package/dist/utils.mjs +5 -0
- package/dist/version--eVB2A7n.mjs +72 -0
- package/dist/version-aPrLuz_-.cjs +129 -0
- package/dist/vite.d.mts +565 -0
- package/dist/vite.mjs +1222 -0
- package/dist/zip-BCC7FAQ_.cjs +264 -0
- package/dist/zip-Dwm7s1C9.mjs +185 -0
- package/package.json +65 -64
- package/dist/chunk-AAAM44NW.js +0 -70
- package/dist/chunk-IVHNGRZY.js +0 -122
- package/dist/chunk-PD4EV4MM.js +0 -147
- package/dist/index.d.ts +0 -194
- package/dist/index.js +0 -309
- package/dist/provider.d.ts +0 -134
- package/dist/provider.js +0 -152
- package/dist/types-CU7GyVez.d.cts +0 -151
- package/dist/types-CU7GyVez.d.ts +0 -151
- package/dist/utils.d.ts +0 -129
- package/dist/utils.js +0 -3
- package/dist/vite.d.ts +0 -533
- package/dist/vite.js +0 -945
- package/dist/zip-Blmn2vzE.d.cts +0 -71
- package/dist/zip-CnSv_Njj.d.ts +0 -71
- package/provider.d.ts +0 -1
- package/provider.js +0 -1
- package/utils.d.ts +0 -1
- package/utils.js +0 -1
- package/vite.d.ts +0 -1
- package/vite.js +0 -1
package/README.md
CHANGED
|
@@ -30,9 +30,11 @@ It use 2 asar file structure for updates:
|
|
|
30
30
|
```sh
|
|
31
31
|
npm install -D electron-incremental-update
|
|
32
32
|
```
|
|
33
|
+
|
|
33
34
|
```sh
|
|
34
35
|
yarn add -D electron-incremental-update
|
|
35
36
|
```
|
|
37
|
+
|
|
36
38
|
```sh
|
|
37
39
|
pnpm add -D electron-incremental-update
|
|
38
40
|
```
|
|
@@ -113,16 +115,18 @@ export default defineConfig(async ({ command }) => {
|
|
|
113
115
|
},
|
|
114
116
|
updater: {
|
|
115
117
|
// options
|
|
116
|
-
}
|
|
118
|
+
},
|
|
117
119
|
}),
|
|
118
120
|
],
|
|
119
|
-
server:
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
server:
|
|
122
|
+
process.env.VSCODE_DEBUG &&
|
|
123
|
+
(() => {
|
|
124
|
+
const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
|
|
125
|
+
return {
|
|
126
|
+
host: url.hostname,
|
|
127
|
+
port: +url.port,
|
|
128
|
+
}
|
|
129
|
+
})(),
|
|
126
130
|
}
|
|
127
131
|
})
|
|
128
132
|
```
|
|
@@ -145,14 +149,16 @@ export default defineElectronConfig({
|
|
|
145
149
|
// options
|
|
146
150
|
},
|
|
147
151
|
renderer: {
|
|
148
|
-
server:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
152
|
+
server:
|
|
153
|
+
process.env.VSCODE_DEBUG &&
|
|
154
|
+
(() => {
|
|
155
|
+
const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
|
|
156
|
+
return {
|
|
157
|
+
host: url.hostname,
|
|
158
|
+
port: +url.port,
|
|
159
|
+
}
|
|
160
|
+
})(),
|
|
161
|
+
},
|
|
156
162
|
})
|
|
157
163
|
```
|
|
158
164
|
|
|
@@ -181,9 +187,7 @@ module.exports = {
|
|
|
181
187
|
'dist-entry',
|
|
182
188
|
],
|
|
183
189
|
npmRebuild: false,
|
|
184
|
-
asarUnpack: [
|
|
185
|
-
'**/*.{node,dll,dylib,so}',
|
|
186
|
-
],
|
|
190
|
+
asarUnpack: ['**/*.{node,dll,dylib,so}'],
|
|
187
191
|
directories: {
|
|
188
192
|
output: 'release',
|
|
189
193
|
},
|
|
@@ -264,7 +268,7 @@ updater.provider = new GitHubProvider({
|
|
|
264
268
|
url.hostname = 'mirror.ghproxy.com'
|
|
265
269
|
url.pathname = `https://github.com${url.pathname}`
|
|
266
270
|
return url
|
|
267
|
-
}
|
|
271
|
+
},
|
|
268
272
|
})
|
|
269
273
|
```
|
|
270
274
|
|
|
@@ -314,7 +318,7 @@ const plugin = electronWithUpdater({
|
|
|
314
318
|
})
|
|
315
319
|
// for @napi-rs/image
|
|
316
320
|
const startStr = '@napi-rs+image-'
|
|
317
|
-
const fileName = readdirSync('./node_modules/.pnpm').find(p => p.startsWith(startStr))!
|
|
321
|
+
const fileName = readdirSync('./node_modules/.pnpm').find((p) => p.startsWith(startStr))!
|
|
318
322
|
const archName = fileName.substring(startStr.length).split('@')[0]
|
|
319
323
|
copyToEntryOutputDir({
|
|
320
324
|
from: `./node_modules/.pnpm/${fileName}/node_modules/@napi-rs/image-${archName}/image.${archName}.node`,
|
|
@@ -333,12 +337,14 @@ in `electron/native/db.ts`
|
|
|
333
337
|
import Database from 'better-sqlite3'
|
|
334
338
|
import { getPathFromEntryAsar } from 'electron-incremental-update/utils'
|
|
335
339
|
|
|
336
|
-
const db = new Database(':memory:', {
|
|
340
|
+
const db = new Database(':memory:', {
|
|
341
|
+
nativeBinding: getPathFromEntryAsar('./better_sqlite3.node'),
|
|
342
|
+
})
|
|
337
343
|
|
|
338
344
|
export function test(): void {
|
|
339
345
|
db.exec(
|
|
340
|
-
'DROP TABLE IF EXISTS employees; '
|
|
341
|
-
|
|
346
|
+
'DROP TABLE IF EXISTS employees; ' +
|
|
347
|
+
'CREATE TABLE IF NOT EXISTS employees (name TEXT, salary INTEGER)',
|
|
342
348
|
)
|
|
343
349
|
|
|
344
350
|
db.prepare('INSERT INTO employees VALUES (:n, :s)').run({
|
|
@@ -374,7 +380,7 @@ module.exports = {
|
|
|
374
380
|
'dist-entry',
|
|
375
381
|
// exclude all dependencies in electron-builder config
|
|
376
382
|
'!node_modules/**',
|
|
377
|
-
]
|
|
383
|
+
],
|
|
378
384
|
}
|
|
379
385
|
```
|
|
380
386
|
|
|
@@ -597,11 +603,7 @@ function downloadUtil<T>(
|
|
|
597
603
|
url: string,
|
|
598
604
|
headers: Record<string, any>,
|
|
599
605
|
signal: AbortSignal,
|
|
600
|
-
onResponse: (
|
|
601
|
-
resp: IncomingMessage,
|
|
602
|
-
resolve: (data: T) => void,
|
|
603
|
-
reject: (e: any) => void
|
|
604
|
-
) => void
|
|
606
|
+
onResponse: (resp: IncomingMessage, resolve: (data: T) => void, reject: (e: any) => void) => void,
|
|
605
607
|
): Promise<T>
|
|
606
608
|
/**
|
|
607
609
|
* Default function to download json and parse to UpdateJson
|
|
@@ -614,7 +616,7 @@ function defaultDownloadJSON<T>(
|
|
|
614
616
|
url: string,
|
|
615
617
|
headers: Record<string, any>,
|
|
616
618
|
signal: AbortSignal,
|
|
617
|
-
resolveData?: ResolveDataFn
|
|
619
|
+
resolveData?: ResolveDataFn,
|
|
618
620
|
): Promise<T>
|
|
619
621
|
/**
|
|
620
622
|
* Default function to download json and parse to UpdateJson
|
|
@@ -625,7 +627,7 @@ function defaultDownloadJSON<T>(
|
|
|
625
627
|
function defaultDownloadUpdateJSON(
|
|
626
628
|
url: string,
|
|
627
629
|
headers: Record<string, any>,
|
|
628
|
-
signal: AbortSignal
|
|
630
|
+
signal: AbortSignal,
|
|
629
631
|
): Promise<UpdateJSON>
|
|
630
632
|
/**
|
|
631
633
|
* Default function to download asar buffer,
|
|
@@ -639,7 +641,7 @@ function defaultDownloadAsar(
|
|
|
639
641
|
url: string,
|
|
640
642
|
headers: Record<string, any>,
|
|
641
643
|
signal: AbortSignal,
|
|
642
|
-
onDownloading?: (progress: DownloadingInfo) => void
|
|
644
|
+
onDownloading?: (progress: DownloadingInfo) => void,
|
|
643
645
|
): Promise<Buffer>
|
|
644
646
|
```
|
|
645
647
|
|
|
@@ -688,7 +690,7 @@ type OnInstallFunction = (
|
|
|
688
690
|
install: VoidFunction,
|
|
689
691
|
tempAsarPath: string,
|
|
690
692
|
appNameAsarPath: string,
|
|
691
|
-
logger?: Logger
|
|
693
|
+
logger?: Logger,
|
|
692
694
|
) => Promisable<void>
|
|
693
695
|
```
|
|
694
696
|
|
|
@@ -724,6 +726,7 @@ export type Logger = {
|
|
|
724
726
|
error: (msg: string, e?: Error) => void
|
|
725
727
|
}
|
|
726
728
|
```
|
|
729
|
+
|
|
727
730
|
#### Provider
|
|
728
731
|
|
|
729
732
|
```ts
|
|
@@ -778,7 +781,7 @@ export interface IProvider {
|
|
|
778
781
|
name: string,
|
|
779
782
|
updateInfo: UpdateInfo,
|
|
780
783
|
signal: AbortSignal,
|
|
781
|
-
onDownloading?: (info: DownloadingInfo) => void
|
|
784
|
+
onDownloading?: (info: DownloadingInfo) => void,
|
|
782
785
|
) => Promise<Buffer>
|
|
783
786
|
/**
|
|
784
787
|
* Check the old version is less than new version
|
|
@@ -799,13 +802,18 @@ export interface IProvider {
|
|
|
799
802
|
* @param signature signature
|
|
800
803
|
* @param cert certificate
|
|
801
804
|
*/
|
|
802
|
-
verifySignaure: (
|
|
805
|
+
verifySignaure: (
|
|
806
|
+
buffer: Buffer,
|
|
807
|
+
version: string,
|
|
808
|
+
signature: string,
|
|
809
|
+
cert: string,
|
|
810
|
+
) => Promisable<boolean>
|
|
803
811
|
}
|
|
804
812
|
```
|
|
805
813
|
|
|
806
814
|
#### Plugin
|
|
807
815
|
|
|
808
|
-
|
|
816
|
+
````ts
|
|
809
817
|
export interface ElectronWithUpdaterOptions {
|
|
810
818
|
/**
|
|
811
819
|
* Whether is in build mode
|
|
@@ -1111,7 +1119,7 @@ export interface GeneratorOverrideFunctions {
|
|
|
1111
1119
|
buffer: Buffer,
|
|
1112
1120
|
privateKey: string,
|
|
1113
1121
|
cert: string,
|
|
1114
|
-
version: string
|
|
1122
|
+
version: string,
|
|
1115
1123
|
) => Promisable<string>
|
|
1116
1124
|
/**
|
|
1117
1125
|
* Custom generate update json function
|
|
@@ -1125,7 +1133,7 @@ export interface GeneratorOverrideFunctions {
|
|
|
1125
1133
|
existingJson: UpdateJSON,
|
|
1126
1134
|
signature: string,
|
|
1127
1135
|
version: string,
|
|
1128
|
-
minVersion: string
|
|
1136
|
+
minVersion: string,
|
|
1129
1137
|
) => Promisable<UpdateJSON>
|
|
1130
1138
|
/**
|
|
1131
1139
|
* Custom generate zip file buffer
|
|
@@ -1133,7 +1141,7 @@ export interface GeneratorOverrideFunctions {
|
|
|
1133
1141
|
*/
|
|
1134
1142
|
generateGzipFile?: (buffer: Buffer) => Promisable<Buffer>
|
|
1135
1143
|
}
|
|
1136
|
-
|
|
1144
|
+
````
|
|
1137
1145
|
|
|
1138
1146
|
## Credits
|
|
1139
1147
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { p as Arrayable, s as UpdateJSON, t as DownloadingInfo } from "./types-DASqEPXE.mjs";
|
|
2
|
+
import { ClientRequest, IncomingMessage } from "electron";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/download.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Safe get value from header
|
|
7
|
+
* @param headers response header
|
|
8
|
+
* @param key target header key
|
|
9
|
+
*/
|
|
10
|
+
declare function getHeader(headers: Record<string, Arrayable<string>>, key: any): any;
|
|
11
|
+
declare function downloadUtil<T>(url: string, headers: Record<string, any>, onResponse: (req: ClientRequest, resp: IncomingMessage, resolve: (data: T) => void, reject: (e: any) => void) => void): Promise<T>;
|
|
12
|
+
type ResolveDataFn = (data: string, resolve: (data: any) => void, reject: (e: any) => void) => void;
|
|
13
|
+
declare const resolveJson: ResolveDataFn;
|
|
14
|
+
/**
|
|
15
|
+
* Default function to download json and parse to UpdateJson
|
|
16
|
+
* @param url target url
|
|
17
|
+
* @param headers extra headers
|
|
18
|
+
* @param signal abort signal
|
|
19
|
+
* @param resolveData on resolve
|
|
20
|
+
*/
|
|
21
|
+
declare function defaultDownloadText<T>(url: string, headers: Record<string, any>, signal: AbortSignal, resolveData: ResolveDataFn): Promise<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Default function to download json and parse to UpdateJson
|
|
24
|
+
* @param url target url
|
|
25
|
+
* @param headers extra headers
|
|
26
|
+
* @param signal abort signal
|
|
27
|
+
*/
|
|
28
|
+
declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>, signal: AbortSignal): Promise<UpdateJSON>;
|
|
29
|
+
/**
|
|
30
|
+
* Default function to download asar buffer,
|
|
31
|
+
* get total size from `Content-Length` header
|
|
32
|
+
* @param url target url
|
|
33
|
+
* @param headers extra headers
|
|
34
|
+
* @param signal abort signal
|
|
35
|
+
* @param onDownloading on downloading callback
|
|
36
|
+
*/
|
|
37
|
+
declare function defaultDownloadAsar(url: string, headers: Record<string, any>, signal: AbortSignal, onDownloading?: (progress: DownloadingInfo) => void): Promise<Buffer>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { getHeader as a, downloadUtil as i, defaultDownloadText as n, resolveJson as o, defaultDownloadUpdateJSON as r, defaultDownloadAsar as t };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { p as Arrayable, s as UpdateJSON, t as DownloadingInfo } from "./types-BM9Jfu7q.cjs";
|
|
2
|
+
import { ClientRequest, IncomingMessage } from "electron";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/download.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Safe get value from header
|
|
7
|
+
* @param headers response header
|
|
8
|
+
* @param key target header key
|
|
9
|
+
*/
|
|
10
|
+
declare function getHeader(headers: Record<string, Arrayable<string>>, key: any): any;
|
|
11
|
+
declare function downloadUtil<T>(url: string, headers: Record<string, any>, onResponse: (req: ClientRequest, resp: IncomingMessage, resolve: (data: T) => void, reject: (e: any) => void) => void): Promise<T>;
|
|
12
|
+
type ResolveDataFn = (data: string, resolve: (data: any) => void, reject: (e: any) => void) => void;
|
|
13
|
+
declare const resolveJson: ResolveDataFn;
|
|
14
|
+
/**
|
|
15
|
+
* Default function to download json and parse to UpdateJson
|
|
16
|
+
* @param url target url
|
|
17
|
+
* @param headers extra headers
|
|
18
|
+
* @param signal abort signal
|
|
19
|
+
* @param resolveData on resolve
|
|
20
|
+
*/
|
|
21
|
+
declare function defaultDownloadText<T>(url: string, headers: Record<string, any>, signal: AbortSignal, resolveData: ResolveDataFn): Promise<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Default function to download json and parse to UpdateJson
|
|
24
|
+
* @param url target url
|
|
25
|
+
* @param headers extra headers
|
|
26
|
+
* @param signal abort signal
|
|
27
|
+
*/
|
|
28
|
+
declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>, signal: AbortSignal): Promise<UpdateJSON>;
|
|
29
|
+
/**
|
|
30
|
+
* Default function to download asar buffer,
|
|
31
|
+
* get total size from `Content-Length` header
|
|
32
|
+
* @param url target url
|
|
33
|
+
* @param headers extra headers
|
|
34
|
+
* @param signal abort signal
|
|
35
|
+
* @param onDownloading on downloading callback
|
|
36
|
+
*/
|
|
37
|
+
declare function defaultDownloadAsar(url: string, headers: Record<string, any>, signal: AbortSignal, onDownloading?: (progress: DownloadingInfo) => void): Promise<Buffer>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { getHeader as a, downloadUtil as i, defaultDownloadText as n, resolveJson as o, defaultDownloadUpdateJSON as r, defaultDownloadAsar as t };
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
const require_version = require('./version-aPrLuz_-.cjs');
|
|
2
|
+
let electron = require("electron");
|
|
3
|
+
let node_fs = require("node:fs");
|
|
4
|
+
node_fs = require_version.__toESM(node_fs);
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
node_path = require_version.__toESM(node_path);
|
|
7
|
+
|
|
8
|
+
//#region src/utils/electron.ts
|
|
9
|
+
/**
|
|
10
|
+
* Compile time dev check
|
|
11
|
+
*/
|
|
12
|
+
const isDev = __EIU_IS_DEV__;
|
|
13
|
+
const isWin = process.platform === "win32";
|
|
14
|
+
const isMac = process.platform === "darwin";
|
|
15
|
+
const isLinux = process.platform === "linux";
|
|
16
|
+
/**
|
|
17
|
+
* Get joined path of `${electron.app.name}.asar` (not `app.asar`)
|
|
18
|
+
*
|
|
19
|
+
* If is in dev, **always** return `'DEV.asar'`
|
|
20
|
+
*/
|
|
21
|
+
function getPathFromAppNameAsar(...paths) {
|
|
22
|
+
return isDev ? "DEV.asar" : node_path.default.join(node_path.default.dirname(electron.app.getAppPath()), `${electron.app.name}.asar`, ...paths);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get app version, if is in dev, return `getEntryVersion()`
|
|
26
|
+
*/
|
|
27
|
+
function getAppVersion() {
|
|
28
|
+
return isDev ? getEntryVersion() : node_fs.default.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get entry version
|
|
32
|
+
*/
|
|
33
|
+
function getEntryVersion() {
|
|
34
|
+
return electron.app.getVersion();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Use `require` to load native module from entry asar
|
|
38
|
+
* @param moduleName file name in entry
|
|
39
|
+
* @example
|
|
40
|
+
* requireNative<typeof import('../native/db')>('db')
|
|
41
|
+
*/
|
|
42
|
+
function requireNative(moduleName) {
|
|
43
|
+
const m = getPathFromEntryAsar(moduleName);
|
|
44
|
+
if (__EIU_IS_ESM__) throw new Error(`Cannot require "${m}", \`requireNative\` only support CommonJS, use \`importNative\` instead`);
|
|
45
|
+
return require(m);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Use `import` to load native module from entry asar
|
|
49
|
+
* @param moduleName file name in entry
|
|
50
|
+
* @example
|
|
51
|
+
* await importNative<typeof import('../native/db')>('db')
|
|
52
|
+
*/
|
|
53
|
+
async function importNative(moduleName) {
|
|
54
|
+
const m = getPathFromEntryAsar(moduleName);
|
|
55
|
+
if (!__EIU_IS_ESM__) throw new Error(`Cannot import "${m}", \`importNative\` only support ESModule, use \`requireNative\` instead`);
|
|
56
|
+
return await import(`file://${m}.js`);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Restarts the Electron app.
|
|
60
|
+
*/
|
|
61
|
+
function restartApp() {
|
|
62
|
+
electron.app.relaunch();
|
|
63
|
+
electron.app.quit();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Fix app use model id, only for Windows
|
|
67
|
+
* @param id app id, default is `org.${electron.app.name}`
|
|
68
|
+
*/
|
|
69
|
+
function setAppUserModelId(id) {
|
|
70
|
+
if (isWin) electron.app.setAppUserModelId(id ?? `org.${electron.app.name}`);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Disable hardware acceleration for Windows 7
|
|
74
|
+
*
|
|
75
|
+
* Only support CommonJS
|
|
76
|
+
*/
|
|
77
|
+
function disableHWAccForWin7() {
|
|
78
|
+
if (!__EIU_IS_ESM__ && require("node:os").release().startsWith("6.1")) electron.app.disableHardwareAcceleration();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Keep single electron instance and auto restore window on `second-instance` event
|
|
82
|
+
* @param window brwoser window to show
|
|
83
|
+
*/
|
|
84
|
+
function singleInstance(window) {
|
|
85
|
+
electron.app.on("second-instance", () => {
|
|
86
|
+
if (window) {
|
|
87
|
+
window.show();
|
|
88
|
+
if (window.isMinimized()) window.restore();
|
|
89
|
+
window.focus();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Set `userData` dir to the dir of .exe file
|
|
95
|
+
*
|
|
96
|
+
* Useful for portable Windows app
|
|
97
|
+
* @param dirName dir name, default to `data`
|
|
98
|
+
* @param create whether to create dir, default to `true`
|
|
99
|
+
*/
|
|
100
|
+
function setPortableDataPath(dirName = "data", create = true) {
|
|
101
|
+
if (electron.app.isReady()) throw new Error("Portable app data dir must be setup before app is ready");
|
|
102
|
+
const portableDir = node_path.default.join(node_path.default.dirname(electron.app.getPath("exe")), dirName);
|
|
103
|
+
if (create) {
|
|
104
|
+
if (!node_fs.default.existsSync(portableDir)) node_fs.default.mkdirSync(portableDir);
|
|
105
|
+
else if (!node_fs.default.statSync(portableDir).isDirectory()) {
|
|
106
|
+
node_fs.default.rmSync(portableDir);
|
|
107
|
+
node_fs.default.mkdirSync(portableDir);
|
|
108
|
+
}
|
|
109
|
+
} else if (!node_fs.default.existsSync(portableDir)) throw new Error("Portable app data dir does not exists");
|
|
110
|
+
electron.app.setPath("userData", portableDir);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @deprecated Use {@link setPortableDataPath} instead
|
|
114
|
+
*/
|
|
115
|
+
const setPortableAppDataPath = setPortableDataPath;
|
|
116
|
+
/**
|
|
117
|
+
* Load `process.env.VITE_DEV_SERVER_URL` when dev, else load html file
|
|
118
|
+
* @param win window
|
|
119
|
+
* @param htmlFilePath html file path, default is `index.html`
|
|
120
|
+
*/
|
|
121
|
+
function loadPage(win, htmlFilePath = "index.html") {
|
|
122
|
+
if (isDev) win.loadURL(process.env.VITE_DEV_SERVER_URL + htmlFilePath);
|
|
123
|
+
else win.loadFile(getPathFromAppNameAsar("renderer", htmlFilePath));
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Beautify devtools' font and scrollbar
|
|
127
|
+
* @param win target window
|
|
128
|
+
* @param options sans font family, mono font family and scrollbar
|
|
129
|
+
* @see https://github.com/electron/electron/issues/42055
|
|
130
|
+
*/
|
|
131
|
+
function beautifyDevTools(win, options) {
|
|
132
|
+
const { mono, sans, scrollbar = true } = options;
|
|
133
|
+
win.webContents.on("devtools-opened", async () => {
|
|
134
|
+
let css = `:root{--sans:${sans};--mono:${mono}}:root, body { --source-code-font-family: var(--mono) !important; --source-code-font-size: 12px !important; --monospace-font-family: var(--mono) !important; --monospace-font-size: 12px !important; --default-font-family: var(--sans), sans-serif !important; --default-font-size: 12px !important; } button, input, select, .undisplayable-text, .expandable-inline-button { font-family: var(--sans) !important; } `;
|
|
135
|
+
if (scrollbar) css += ":root { --scrollbar-width: max(0.85vw, 10px); } @media (prefers-color-scheme: light) { :root { --scrollbar-color-rgb: 0, 0, 0; } } @media (prefers-color-scheme: dark) { :root { --scrollbar-color-rgb: 255, 255, 255; } } *::-webkit-scrollbar { width: var(--scrollbar-width) !important; height: var(--scrollbar-width) !important; } *::-webkit-scrollbar-track { background-color: transparent !important; border-radius: var(--scrollbar-width) !important; box-shadow: none !important; } *::-webkit-scrollbar-thumb { box-shadow: inset 0 0 0 var(--scrollbar-width) !important; border-radius: var(--scrollbar-width) !important; border: calc(var(--scrollbar-width) * 2 / 9) solid transparent !important; background-clip: content-box; background-color: transparent !important; color: rgba(var(--scrollbar-color-rgb), 30%) !important; } *::-webkit-scrollbar-thumb:hover { color: rgba(var(--scrollbar-color-rgb), 45%) !important; } *::-webkit-scrollbar-thumb:active { color: rgba(var(--scrollbar-color-rgb), 60%) !important; } @supports not selector(::-webkit-scrollbar) { html { scrollbar-color: rgb(var(--scrollbar-color-rgb)); scrollbar-width: thin; } } ";
|
|
136
|
+
const js = `const __CSS__='${css}';function e(e){let t=document.createElement(\`style\`);t.innerHTML=e,document.body.append(t),[\`platform-windows\`,\`platform-mac\`,\`platform-linux\`].forEach(e=>document.querySelectorAll(\`.\${e}\`).forEach(t=>t.classList.remove(e))),r();let n=new MutationObserver(e=>{for(let t of e)if(t.type===\`childList\`)for(let e=0;e<t.addedNodes.length;e++)t.addedNodes[e].classList.contains(\`editor-tooltip-host\`)&&r()});n.observe(document.body,{childList:!0});function r(){document.querySelectorAll(\`.editor-tooltip-host\`).forEach(t=>{if(t?.shadowRoot?.querySelectorAll(\`[data-key="overridden-dev-tools-font"]\`).length===0){let n=document.createElement(\`style\`);n.dataset.key=\`overridden-dev-tools-font\`,n.innerHTML=\`\${e}.cm-tooltip-autocomplete ul[role=listbox]{font-family:var(--mono)!important;}\`,t.shadowRoot.append(n)}})}window.onbeforeunload=()=>n.disconnect()}e(__CSS__);`;
|
|
137
|
+
await win?.webContents.devToolsWebContents?.executeJavaScript(js);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get joined path from main dir
|
|
142
|
+
* @param paths rest paths
|
|
143
|
+
*/
|
|
144
|
+
function getPathFromMain(...paths) {
|
|
145
|
+
return isDev ? node_path.default.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "main", ...paths) : getPathFromAppNameAsar("main", ...paths);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get joined path from preload dir
|
|
149
|
+
* @param paths rest paths
|
|
150
|
+
*/
|
|
151
|
+
function getPathFromPreload(...paths) {
|
|
152
|
+
return isDev ? node_path.default.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Get joined path from publich dir
|
|
156
|
+
* @param paths rest paths
|
|
157
|
+
*/
|
|
158
|
+
function getPathFromPublic(...paths) {
|
|
159
|
+
return isDev ? node_path.default.join(electron.app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get joined path from entry asar
|
|
163
|
+
* @param paths rest paths
|
|
164
|
+
*/
|
|
165
|
+
function getPathFromEntryAsar(...paths) {
|
|
166
|
+
return node_path.default.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Handle all unhandled error
|
|
170
|
+
* @param callback callback function
|
|
171
|
+
*/
|
|
172
|
+
function handleUnexpectedErrors(callback) {
|
|
173
|
+
process.on("uncaughtException", callback);
|
|
174
|
+
process.on("unhandledRejection", callback);
|
|
175
|
+
}
|
|
176
|
+
function reloadOnPreloadScriptChanged() {
|
|
177
|
+
if (isDev) process.on("message", (msg) => {
|
|
178
|
+
if (msg === "electron-vite&type=hot-reload") for (const window of electron.BrowserWindow.getAllWindows()) window.reload();
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
183
|
+
Object.defineProperty(exports, 'beautifyDevTools', {
|
|
184
|
+
enumerable: true,
|
|
185
|
+
get: function () {
|
|
186
|
+
return beautifyDevTools;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
Object.defineProperty(exports, 'disableHWAccForWin7', {
|
|
190
|
+
enumerable: true,
|
|
191
|
+
get: function () {
|
|
192
|
+
return disableHWAccForWin7;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
Object.defineProperty(exports, 'getAppVersion', {
|
|
196
|
+
enumerable: true,
|
|
197
|
+
get: function () {
|
|
198
|
+
return getAppVersion;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
Object.defineProperty(exports, 'getEntryVersion', {
|
|
202
|
+
enumerable: true,
|
|
203
|
+
get: function () {
|
|
204
|
+
return getEntryVersion;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
Object.defineProperty(exports, 'getPathFromAppNameAsar', {
|
|
208
|
+
enumerable: true,
|
|
209
|
+
get: function () {
|
|
210
|
+
return getPathFromAppNameAsar;
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
Object.defineProperty(exports, 'getPathFromEntryAsar', {
|
|
214
|
+
enumerable: true,
|
|
215
|
+
get: function () {
|
|
216
|
+
return getPathFromEntryAsar;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
Object.defineProperty(exports, 'getPathFromMain', {
|
|
220
|
+
enumerable: true,
|
|
221
|
+
get: function () {
|
|
222
|
+
return getPathFromMain;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
Object.defineProperty(exports, 'getPathFromPreload', {
|
|
226
|
+
enumerable: true,
|
|
227
|
+
get: function () {
|
|
228
|
+
return getPathFromPreload;
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
Object.defineProperty(exports, 'getPathFromPublic', {
|
|
232
|
+
enumerable: true,
|
|
233
|
+
get: function () {
|
|
234
|
+
return getPathFromPublic;
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
Object.defineProperty(exports, 'handleUnexpectedErrors', {
|
|
238
|
+
enumerable: true,
|
|
239
|
+
get: function () {
|
|
240
|
+
return handleUnexpectedErrors;
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
Object.defineProperty(exports, 'importNative', {
|
|
244
|
+
enumerable: true,
|
|
245
|
+
get: function () {
|
|
246
|
+
return importNative;
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
Object.defineProperty(exports, 'isDev', {
|
|
250
|
+
enumerable: true,
|
|
251
|
+
get: function () {
|
|
252
|
+
return isDev;
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
Object.defineProperty(exports, 'isLinux', {
|
|
256
|
+
enumerable: true,
|
|
257
|
+
get: function () {
|
|
258
|
+
return isLinux;
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
Object.defineProperty(exports, 'isMac', {
|
|
262
|
+
enumerable: true,
|
|
263
|
+
get: function () {
|
|
264
|
+
return isMac;
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
Object.defineProperty(exports, 'isWin', {
|
|
268
|
+
enumerable: true,
|
|
269
|
+
get: function () {
|
|
270
|
+
return isWin;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
Object.defineProperty(exports, 'loadPage', {
|
|
274
|
+
enumerable: true,
|
|
275
|
+
get: function () {
|
|
276
|
+
return loadPage;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
Object.defineProperty(exports, 'reloadOnPreloadScriptChanged', {
|
|
280
|
+
enumerable: true,
|
|
281
|
+
get: function () {
|
|
282
|
+
return reloadOnPreloadScriptChanged;
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
Object.defineProperty(exports, 'requireNative', {
|
|
286
|
+
enumerable: true,
|
|
287
|
+
get: function () {
|
|
288
|
+
return requireNative;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
Object.defineProperty(exports, 'restartApp', {
|
|
292
|
+
enumerable: true,
|
|
293
|
+
get: function () {
|
|
294
|
+
return restartApp;
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
Object.defineProperty(exports, 'setAppUserModelId', {
|
|
298
|
+
enumerable: true,
|
|
299
|
+
get: function () {
|
|
300
|
+
return setAppUserModelId;
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
Object.defineProperty(exports, 'setPortableAppDataPath', {
|
|
304
|
+
enumerable: true,
|
|
305
|
+
get: function () {
|
|
306
|
+
return setPortableAppDataPath;
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
Object.defineProperty(exports, 'setPortableDataPath', {
|
|
310
|
+
enumerable: true,
|
|
311
|
+
get: function () {
|
|
312
|
+
return setPortableDataPath;
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
Object.defineProperty(exports, 'singleInstance', {
|
|
316
|
+
enumerable: true,
|
|
317
|
+
get: function () {
|
|
318
|
+
return singleInstance;
|
|
319
|
+
}
|
|
320
|
+
});
|