electron-incremental-update 0.9.0 → 1.0.0

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.
@@ -0,0 +1,31 @@
1
+ /**
2
+ * parse Github CDN URL for accelerating the speed of downloading
3
+ *
4
+ * {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 some public CDN links}
5
+ */
6
+ declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, relativeFilePath: string): string;
7
+ /**
8
+ * handle all unhandled error
9
+ * @param callback callback function
10
+ */
11
+ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
12
+ interface Version {
13
+ major: number;
14
+ minor: number;
15
+ patch: number;
16
+ stage: string;
17
+ stageVersion: number;
18
+ }
19
+ declare function parseVersion(version: string): Version;
20
+ type UpdateInfo = {
21
+ signature: string;
22
+ minimumVersion: string;
23
+ version: string;
24
+ size: number;
25
+ };
26
+ type UpdateJSON = UpdateInfo & {
27
+ beta: UpdateInfo;
28
+ };
29
+ declare function isUpdateJSON(json: any): json is UpdateJSON;
30
+
31
+ export { type UpdateInfo as U, type Version as V, type UpdateJSON as a, parseVersion as b, handleUnexpectedErrors as h, isUpdateJSON as i, parseGithubCdnURL as p };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * parse Github CDN URL for accelerating the speed of downloading
3
+ *
4
+ * {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 some public CDN links}
5
+ */
6
+ declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, relativeFilePath: string): string;
7
+ /**
8
+ * handle all unhandled error
9
+ * @param callback callback function
10
+ */
11
+ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
12
+ interface Version {
13
+ major: number;
14
+ minor: number;
15
+ patch: number;
16
+ stage: string;
17
+ stageVersion: number;
18
+ }
19
+ declare function parseVersion(version: string): Version;
20
+ type UpdateInfo = {
21
+ signature: string;
22
+ minimumVersion: string;
23
+ version: string;
24
+ size: number;
25
+ };
26
+ type UpdateJSON = UpdateInfo & {
27
+ beta: UpdateInfo;
28
+ };
29
+ declare function isUpdateJSON(json: any): json is UpdateJSON;
30
+
31
+ export { type UpdateInfo as U, type Version as V, type UpdateJSON as a, parseVersion as b, handleUnexpectedErrors as h, isUpdateJSON as i, parseGithubCdnURL as p };
package/dist/utils.d.mts CHANGED
@@ -1,4 +1,6 @@
1
- declare const DEFAULT_APP_NAME = "product";
1
+ import { BrowserWindow } from 'electron';
2
+ export { U as UpdateInfo, a as UpdateJSON, V as Version, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseGithubCdnURL, b as parseVersion } from './noDep-TvZoKVF8.mjs';
3
+
2
4
  type Is = {
3
5
  dev: boolean;
4
6
  win: boolean;
@@ -9,75 +11,118 @@ type Is = {
9
11
  * get app info
10
12
  */
11
13
  declare const is: Is;
12
- declare function getLocale(): string | undefined;
13
14
  /**
14
- * get the application asar absolute path (not `app.asar`),
15
+ * get the absolute path of `${app.name}.asar` (not `app.asar`)
16
+ *
15
17
  * if is in dev, return `'DEV.asar'`
16
- * @param name The name of the application
17
- */
18
- declare function getProductAsarPath(name?: string): string;
19
- /**
20
- * get the version of Electron runtime
18
+ * @todo change a better function name or merge into {@link getPaths}
21
19
  */
22
- declare function getElectronVersion(): string;
20
+ declare function getPathFromAppNameAsar(...path: string[]): string;
23
21
  /**
24
- * get the version of application (name.asar)
22
+ * get versions of App, Entry, Electron, Node and System
23
+ *
24
+ * App version is read from `version` file in `${app.name}.asar`
25
+ *
26
+ * Entry version is read from `package.json`
25
27
  *
26
- * if is dev, return {@link getElectronVersion}
27
- * @param name - The name of the application
28
+ * SystemVersion: `${platform} ${os.release()}`
28
29
  */
29
- declare function getAppVersion(name?: string): string;
30
- declare class NoSuchNativeModuleError extends Error {
31
- moduleName: string;
32
- constructor(moduleName: string);
33
- }
34
- declare function isNoSuchNativeModuleError(e: unknown): e is NoSuchNativeModuleError;
30
+ declare function getVersions(): {
31
+ appVersion: string;
32
+ entryVersion: string;
33
+ electronVersion: string;
34
+ nodeVersion: string;
35
+ systemVersion: string;
36
+ };
35
37
  /**
36
- * require native package, if not found, return {@link NoSuchNativeModuleError}
37
- * @param packageName native package name
38
+ * load native module from entry
39
+ * @param moduleName file name in entry
38
40
  */
39
- declare function requireNative<T = any>(packageName: string): T | NoSuchNativeModuleError;
40
-
41
- interface Version {
42
- major: number;
43
- minor: number;
44
- patch: number;
45
- stage: string;
46
- stageVersion: number;
47
- }
48
- declare function parseVersion(version: string): Version;
49
-
50
- declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
51
- declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
52
-
41
+ type RequireNative = <T = any>(moduleName: string) => T;
53
42
  /**
54
- * parse Github CDN URL for accelerating the speed of downloading
55
- *
56
- * {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 some public CDN links}
43
+ * load module from entry, **only for main and preload**
44
+ * @remark use `require`, only support **CommonJS**
45
+ * @param devEntryDirPath entry directory path when dev, default `../../dist-entry`
46
+ * @param entryDirPath entry directory path when not dev, default `join(app.getAppPath(), basename(devEntryDirPath))`
47
+ * @example
48
+ * const requireNative = loadNativeModuleFromEntry()
49
+ * const db = requireNative<typeof import('../native/db')>('db')
50
+ * db.test()
57
51
  */
58
- declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, relativeFilePath: string): string;
52
+ declare function loadNativeModuleFromEntry(devEntryDirPath?: string, entryDirPath?: string): RequireNative;
59
53
  /**
60
54
  * Restarts the Electron app.
61
55
  */
62
56
  declare function restartApp(): void;
63
57
  /**
64
58
  * fix app use model id, only for Windows
65
- * @param id app id
59
+ * @param id app id @default `org.${app.name}`
60
+ */
61
+ declare function setAppUserModelId(id?: string): void;
62
+ /**
63
+ * disable hardware acceleration for Windows 7
66
64
  */
67
- declare function setAppUserModelId(id: string): void;
65
+ declare function disableHWAccForWin7(): void;
68
66
  /**
69
- * set AppData dir for portable Windows app
67
+ * keep single electron instance and auto restore window on `second-instance` event
68
+ * @param window brwoser window to show
69
+ * @returns `false` if the app is running
70
70
  */
71
- declare function setPortableAppDataPath(dirName?: string, create?: boolean): void;
71
+ declare function singleInstance(window?: BrowserWindow): boolean;
72
+ /**
73
+ * set `AppData` dir to the dir of .exe file
74
+ *
75
+ * useful for portable Windows app
76
+ * @param dirName dir name, default to `data`
77
+ */
78
+ declare function setPortableAppDataPath(dirName?: string): void;
72
79
  /**
73
80
  * ensure app is ready.
74
81
  * @param timeout wait timeout, @default 1000
75
82
  */
76
83
  declare function waitAppReady(timeout?: number): Promise<void>;
77
84
  /**
78
- * handle all unhandled error
79
- * @param callback callback function
85
+ * get paths, **only for main and preload**
86
+ * @param entryDirName entry dir name, default to `dist-entry`
80
87
  */
81
- declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
88
+ declare function getPaths(entryDirName?: string): {
89
+ /**
90
+ * @example
91
+ * ```ts
92
+ * devServerURL && win.loadURL(devServerURL)
93
+ * ```
94
+ */
95
+ devServerURL: string | undefined;
96
+ /**
97
+ * @example
98
+ * ```ts
99
+ * win.loadFile(indexHTMLPath)
100
+ * ```
101
+ */
102
+ indexHTMLPath: string;
103
+ /**
104
+ * get path inside entry asar
105
+ * @param paths joined path
106
+ */
107
+ getPathFromEntryAsar(...paths: string[]): string;
108
+ /**
109
+ * get path inside `${app.name}.asar/main`
110
+ * @param paths joined path
111
+ */
112
+ getPathFromMain(...paths: string[]): string;
113
+ /**
114
+ * get path inside `${app.name}.asar/preload`
115
+ * @param paths joined path
116
+ */
117
+ getPathFromPreload(...paths: string[]): string;
118
+ /**
119
+ * get path inside public dir
120
+ * @param paths joined path
121
+ */
122
+ getPathFromPublic(...paths: string[]): string;
123
+ };
124
+
125
+ declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
126
+ declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
82
127
 
83
- export { DEFAULT_APP_NAME, NoSuchNativeModuleError, type Version, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, is, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, unzipFile, waitAppReady, zipFile };
128
+ export { disableHWAccForWin7, getPathFromAppNameAsar, getPaths, getVersions, is, loadNativeModuleFromEntry, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance, unzipFile, waitAppReady, zipFile };
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- declare const DEFAULT_APP_NAME = "product";
1
+ import { BrowserWindow } from 'electron';
2
+ export { U as UpdateInfo, a as UpdateJSON, V as Version, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseGithubCdnURL, b as parseVersion } from './noDep-TvZoKVF8.js';
3
+
2
4
  type Is = {
3
5
  dev: boolean;
4
6
  win: boolean;
@@ -9,75 +11,118 @@ type Is = {
9
11
  * get app info
10
12
  */
11
13
  declare const is: Is;
12
- declare function getLocale(): string | undefined;
13
14
  /**
14
- * get the application asar absolute path (not `app.asar`),
15
+ * get the absolute path of `${app.name}.asar` (not `app.asar`)
16
+ *
15
17
  * if is in dev, return `'DEV.asar'`
16
- * @param name The name of the application
17
- */
18
- declare function getProductAsarPath(name?: string): string;
19
- /**
20
- * get the version of Electron runtime
18
+ * @todo change a better function name or merge into {@link getPaths}
21
19
  */
22
- declare function getElectronVersion(): string;
20
+ declare function getPathFromAppNameAsar(...path: string[]): string;
23
21
  /**
24
- * get the version of application (name.asar)
22
+ * get versions of App, Entry, Electron, Node and System
23
+ *
24
+ * App version is read from `version` file in `${app.name}.asar`
25
+ *
26
+ * Entry version is read from `package.json`
25
27
  *
26
- * if is dev, return {@link getElectronVersion}
27
- * @param name - The name of the application
28
+ * SystemVersion: `${platform} ${os.release()}`
28
29
  */
29
- declare function getAppVersion(name?: string): string;
30
- declare class NoSuchNativeModuleError extends Error {
31
- moduleName: string;
32
- constructor(moduleName: string);
33
- }
34
- declare function isNoSuchNativeModuleError(e: unknown): e is NoSuchNativeModuleError;
30
+ declare function getVersions(): {
31
+ appVersion: string;
32
+ entryVersion: string;
33
+ electronVersion: string;
34
+ nodeVersion: string;
35
+ systemVersion: string;
36
+ };
35
37
  /**
36
- * require native package, if not found, return {@link NoSuchNativeModuleError}
37
- * @param packageName native package name
38
+ * load native module from entry
39
+ * @param moduleName file name in entry
38
40
  */
39
- declare function requireNative<T = any>(packageName: string): T | NoSuchNativeModuleError;
40
-
41
- interface Version {
42
- major: number;
43
- minor: number;
44
- patch: number;
45
- stage: string;
46
- stageVersion: number;
47
- }
48
- declare function parseVersion(version: string): Version;
49
-
50
- declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
51
- declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
52
-
41
+ type RequireNative = <T = any>(moduleName: string) => T;
53
42
  /**
54
- * parse Github CDN URL for accelerating the speed of downloading
55
- *
56
- * {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 some public CDN links}
43
+ * load module from entry, **only for main and preload**
44
+ * @remark use `require`, only support **CommonJS**
45
+ * @param devEntryDirPath entry directory path when dev, default `../../dist-entry`
46
+ * @param entryDirPath entry directory path when not dev, default `join(app.getAppPath(), basename(devEntryDirPath))`
47
+ * @example
48
+ * const requireNative = loadNativeModuleFromEntry()
49
+ * const db = requireNative<typeof import('../native/db')>('db')
50
+ * db.test()
57
51
  */
58
- declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, relativeFilePath: string): string;
52
+ declare function loadNativeModuleFromEntry(devEntryDirPath?: string, entryDirPath?: string): RequireNative;
59
53
  /**
60
54
  * Restarts the Electron app.
61
55
  */
62
56
  declare function restartApp(): void;
63
57
  /**
64
58
  * fix app use model id, only for Windows
65
- * @param id app id
59
+ * @param id app id @default `org.${app.name}`
60
+ */
61
+ declare function setAppUserModelId(id?: string): void;
62
+ /**
63
+ * disable hardware acceleration for Windows 7
66
64
  */
67
- declare function setAppUserModelId(id: string): void;
65
+ declare function disableHWAccForWin7(): void;
68
66
  /**
69
- * set AppData dir for portable Windows app
67
+ * keep single electron instance and auto restore window on `second-instance` event
68
+ * @param window brwoser window to show
69
+ * @returns `false` if the app is running
70
70
  */
71
- declare function setPortableAppDataPath(dirName?: string, create?: boolean): void;
71
+ declare function singleInstance(window?: BrowserWindow): boolean;
72
+ /**
73
+ * set `AppData` dir to the dir of .exe file
74
+ *
75
+ * useful for portable Windows app
76
+ * @param dirName dir name, default to `data`
77
+ */
78
+ declare function setPortableAppDataPath(dirName?: string): void;
72
79
  /**
73
80
  * ensure app is ready.
74
81
  * @param timeout wait timeout, @default 1000
75
82
  */
76
83
  declare function waitAppReady(timeout?: number): Promise<void>;
77
84
  /**
78
- * handle all unhandled error
79
- * @param callback callback function
85
+ * get paths, **only for main and preload**
86
+ * @param entryDirName entry dir name, default to `dist-entry`
80
87
  */
81
- declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
88
+ declare function getPaths(entryDirName?: string): {
89
+ /**
90
+ * @example
91
+ * ```ts
92
+ * devServerURL && win.loadURL(devServerURL)
93
+ * ```
94
+ */
95
+ devServerURL: string | undefined;
96
+ /**
97
+ * @example
98
+ * ```ts
99
+ * win.loadFile(indexHTMLPath)
100
+ * ```
101
+ */
102
+ indexHTMLPath: string;
103
+ /**
104
+ * get path inside entry asar
105
+ * @param paths joined path
106
+ */
107
+ getPathFromEntryAsar(...paths: string[]): string;
108
+ /**
109
+ * get path inside `${app.name}.asar/main`
110
+ * @param paths joined path
111
+ */
112
+ getPathFromMain(...paths: string[]): string;
113
+ /**
114
+ * get path inside `${app.name}.asar/preload`
115
+ * @param paths joined path
116
+ */
117
+ getPathFromPreload(...paths: string[]): string;
118
+ /**
119
+ * get path inside public dir
120
+ * @param paths joined path
121
+ */
122
+ getPathFromPublic(...paths: string[]): string;
123
+ };
124
+
125
+ declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
126
+ declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
82
127
 
83
- export { DEFAULT_APP_NAME, NoSuchNativeModuleError, type Version, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, is, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, unzipFile, waitAppReady, zipFile };
128
+ export { disableHWAccForWin7, getPathFromAppNameAsar, getPaths, getVersions, is, loadNativeModuleFromEntry, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance, unzipFile, waitAppReady, zipFile };