electron-incremental-update 2.0.0-beta.8 → 2.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.
package/dist/index.d.cts CHANGED
@@ -1,47 +1,156 @@
1
- import { U as Updater, a as UpdaterOption, L as Logger } from './core-ZUlLHadf.cjs';
2
- export { C as CheckResult, D as DownloadResult, E as ErrorInfo, b as UpdaterError } from './core-ZUlLHadf.cjs';
3
- import { I as IProvider } from './types-CItP6bL-.cjs';
4
- import 'node:events';
5
- import '@subframe7536/type-utils';
1
+ import { EventEmitter } from 'node:events';
2
+ import { U as UpdateInfo, a as UpdateJSON } from './version-BYVQ367i.cjs';
3
+ import { I as IProvider, D as DownloadingInfo } from './types-DkCn03M3.cjs';
4
+ import { Promisable } from '@subframe7536/type-utils';
5
+
6
+ declare const ErrorInfo: {
7
+ readonly download: "Download Failed";
8
+ readonly validate: "Validate Failed";
9
+ readonly param: "Missing Params";
10
+ readonly network: "Network Error";
11
+ };
12
+ declare class UpdaterError extends Error {
13
+ code: keyof typeof ErrorInfo;
14
+ constructor(msg: keyof typeof ErrorInfo, info: string);
15
+ }
16
+ interface Logger {
17
+ info: (msg: string) => void;
18
+ debug: (msg: string) => void;
19
+ warn: (msg: string) => void;
20
+ error: (msg: string, e?: unknown) => void;
21
+ }
22
+ interface UpdaterOption {
23
+ /**
24
+ * Update provider
25
+ *
26
+ * If you will not setup `UpdateJSON` or `Buffer` in params when checking update or download, this option is **required**
27
+ */
28
+ provider?: IProvider;
29
+ /**
30
+ * Certifaction key of signature, which will be auto generated by plugin,
31
+ * generate by `selfsigned` if not set
32
+ */
33
+ SIGNATURE_CERT?: string;
34
+ /**
35
+ * Whether to receive beta update
36
+ */
37
+ receiveBeta?: boolean;
38
+ /**
39
+ * Updater logger
40
+ */
41
+ logger?: Logger;
42
+ }
43
+
44
+ declare class Updater extends EventEmitter<{
45
+ 'checking': any;
46
+ 'update-available': [data: UpdateInfo];
47
+ 'update-not-available': [reason: string, data?: UpdateInfo];
48
+ 'error': [error: UpdaterError];
49
+ 'download-progress': [info: DownloadingInfo];
50
+ 'update-downloaded': any;
51
+ 'update-cancelled': any;
52
+ }> {
53
+ private CERT;
54
+ private controller;
55
+ private info?;
56
+ provider?: IProvider;
57
+ /**
58
+ * Updater logger
59
+ */
60
+ logger?: Logger;
61
+ /**
62
+ * Whether to receive beta update
63
+ */
64
+ receiveBeta?: boolean;
65
+ /**
66
+ * Whether force update in DEV
67
+ */
68
+ forceUpdate?: boolean;
69
+ /**
70
+ * Initialize incremental updater
71
+ * @param options UpdaterOption
72
+ */
73
+ constructor(options?: UpdaterOption);
74
+ /**
75
+ * This function is used to parse download data.
76
+ *
77
+ * if data is absent, download URL from provider and return it,
78
+ * else if data is `UpdateJSON`, return it
79
+ */
80
+ private fetch;
81
+ /**
82
+ * Handle error message and emit error event
83
+ */
84
+ private err;
85
+ /**
86
+ * Check update info using default options
87
+ */
88
+ checkForUpdates(): Promise<boolean>;
89
+ /**
90
+ * Check update info using existing update json
91
+ * @param data existing update json
92
+ */
93
+ checkForUpdates(data: UpdateJSON): Promise<boolean>;
94
+ /**
95
+ * Download update using default options
96
+ */
97
+ downloadUpdate(): Promise<boolean>;
98
+ /**
99
+ * Download update using existing `asar.gz` buffer and signature
100
+ * @param data existing `asar.gz` buffer
101
+ * @param info update info
102
+ */
103
+ downloadUpdate(data: Uint8Array, info: Omit<UpdateInfo, 'minimumVersion'>): Promise<boolean>;
104
+ /**
105
+ * quit App and install
106
+ */
107
+ quitAndInstall(): void;
108
+ cancel(): void;
109
+ }
110
+ /**
111
+ * Auto check update, download and install
112
+ */
113
+ declare function autoUpdate(updater: Updater): Promise<void>;
6
114
 
7
- type Promisable<T> = T | Promise<T>;
8
115
  /**
9
- * hooks on rename temp asar path to `${app.name}.asar`
116
+ * Hooks on rename temp asar path to `${app.name}.asar`
10
117
  * @param install `() => renameSync(tempAsarPath, appNameAsarPath)`
11
118
  * @param tempAsarPath temp(updated) asar path
12
119
  * @param appNameAsarPath `${app.name}.asar` path
13
120
  * @param logger logger
14
- * @default install(); logger.info(`update success!`)
121
+ * @default install(); logger.info('update success!')
15
122
  */
16
123
  type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
17
124
  interface AppOption {
18
125
  /**
19
- * update provider
126
+ * Path to index file that make {@link startupWithUpdater} as default export
127
+ *
128
+ * Generate from plugin configuration by default
20
129
  */
21
- provider: IProvider;
130
+ mainPath?: string;
22
131
  /**
23
- * updater options
132
+ * Updater options
24
133
  */
25
134
  updater?: (() => Promisable<Updater>) | UpdaterOption;
26
135
  /**
27
- * hooks on rename temp asar path to `${app.name}.asar`
136
+ * Hooks on rename temp asar path to `${app.name}.asar`
28
137
  */
29
138
  onInstall?: OnInstallFunction;
30
139
  /**
31
- * hooks before app start up
140
+ * Hooks before app startup
32
141
  * @param mainFilePath main file path of `${app.name}.asar`
33
142
  * @param logger logger
34
143
  */
35
144
  beforeStart?: (mainFilePath: string, logger?: Logger) => Promisable<void>;
36
145
  /**
37
- * hooks on app start up error
146
+ * Hooks on app startup error
38
147
  * @param err installing or startup error
39
148
  * @param logger logger
40
149
  */
41
150
  onStartError?: (err: unknown, logger?: Logger) => void;
42
151
  }
43
152
  /**
44
- * utils for startuping with updater
153
+ * Utils to startup with updater
45
154
  * @param fn startup function
46
155
  * @example
47
156
  * // in electron/main/index.ts
@@ -51,28 +160,24 @@ interface AppOption {
51
160
  */
52
161
  declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>): (updater: Updater) => Promisable<void>;
53
162
  /**
54
- * initialize app
163
+ * Initialize Electron with updater
55
164
  * @example
56
- * ```ts
57
- * import { getGithubReleaseCdnGroup, initApp, parseGithubCdnURL } from 'electron-incremental-update'
58
- * import { repository } from '../package.json'
59
- *
60
- * const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
61
- * const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
62
- *
63
- * initApp({
64
- * // can be updater option or function that return updater
165
+ * createElectronApp({
65
166
  * updater: {
66
- * SIGNATURE_CERT: 'custom certificate',
67
- * repository,
68
- * updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
69
- * releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${app.name}.asar.gz`),
70
- * receiveBeta: true,
167
+ * provider: new GitHubProvider({
168
+ * username: 'yourname',
169
+ * repo: 'electron',
170
+ * }),
171
+ * },
172
+ * beforeStart(mainFilePath, logger) {
173
+ * logger?.debug(mainFilePath)
71
174
  * },
72
- * onStart: console.log
73
175
  * })
74
- * ```
75
176
  */
76
- declare function initApp(appOptions: AppOption): Promise<void>;
177
+ declare function createElectronApp(appOptions?: AppOption): Promise<void>;
178
+ /**
179
+ * @alias {@link createElectronApp}
180
+ */
181
+ declare const initApp: typeof createElectronApp;
77
182
 
78
- export { type AppOption, Logger, Updater, UpdaterOption, initApp, startupWithUpdater };
183
+ export { type AppOption, ErrorInfo, type Logger, Updater, UpdaterError, type UpdaterOption, autoUpdate, createElectronApp, initApp, startupWithUpdater };
package/dist/index.d.ts CHANGED
@@ -1,47 +1,156 @@
1
- import { U as Updater, a as UpdaterOption, L as Logger } from './core-DJdvtwvU.js';
2
- export { C as CheckResult, D as DownloadResult, E as ErrorInfo, b as UpdaterError } from './core-DJdvtwvU.js';
3
- import { I as IProvider } from './types-CItP6bL-.js';
4
- import 'node:events';
5
- import '@subframe7536/type-utils';
1
+ import { EventEmitter } from 'node:events';
2
+ import { U as UpdateInfo, a as UpdateJSON } from './version-BYVQ367i.js';
3
+ import { I as IProvider, D as DownloadingInfo } from './types-BLdN9rkY.js';
4
+ import { Promisable } from '@subframe7536/type-utils';
5
+
6
+ declare const ErrorInfo: {
7
+ readonly download: "Download Failed";
8
+ readonly validate: "Validate Failed";
9
+ readonly param: "Missing Params";
10
+ readonly network: "Network Error";
11
+ };
12
+ declare class UpdaterError extends Error {
13
+ code: keyof typeof ErrorInfo;
14
+ constructor(msg: keyof typeof ErrorInfo, info: string);
15
+ }
16
+ interface Logger {
17
+ info: (msg: string) => void;
18
+ debug: (msg: string) => void;
19
+ warn: (msg: string) => void;
20
+ error: (msg: string, e?: unknown) => void;
21
+ }
22
+ interface UpdaterOption {
23
+ /**
24
+ * Update provider
25
+ *
26
+ * If you will not setup `UpdateJSON` or `Buffer` in params when checking update or download, this option is **required**
27
+ */
28
+ provider?: IProvider;
29
+ /**
30
+ * Certifaction key of signature, which will be auto generated by plugin,
31
+ * generate by `selfsigned` if not set
32
+ */
33
+ SIGNATURE_CERT?: string;
34
+ /**
35
+ * Whether to receive beta update
36
+ */
37
+ receiveBeta?: boolean;
38
+ /**
39
+ * Updater logger
40
+ */
41
+ logger?: Logger;
42
+ }
43
+
44
+ declare class Updater extends EventEmitter<{
45
+ 'checking': any;
46
+ 'update-available': [data: UpdateInfo];
47
+ 'update-not-available': [reason: string, data?: UpdateInfo];
48
+ 'error': [error: UpdaterError];
49
+ 'download-progress': [info: DownloadingInfo];
50
+ 'update-downloaded': any;
51
+ 'update-cancelled': any;
52
+ }> {
53
+ private CERT;
54
+ private controller;
55
+ private info?;
56
+ provider?: IProvider;
57
+ /**
58
+ * Updater logger
59
+ */
60
+ logger?: Logger;
61
+ /**
62
+ * Whether to receive beta update
63
+ */
64
+ receiveBeta?: boolean;
65
+ /**
66
+ * Whether force update in DEV
67
+ */
68
+ forceUpdate?: boolean;
69
+ /**
70
+ * Initialize incremental updater
71
+ * @param options UpdaterOption
72
+ */
73
+ constructor(options?: UpdaterOption);
74
+ /**
75
+ * This function is used to parse download data.
76
+ *
77
+ * if data is absent, download URL from provider and return it,
78
+ * else if data is `UpdateJSON`, return it
79
+ */
80
+ private fetch;
81
+ /**
82
+ * Handle error message and emit error event
83
+ */
84
+ private err;
85
+ /**
86
+ * Check update info using default options
87
+ */
88
+ checkForUpdates(): Promise<boolean>;
89
+ /**
90
+ * Check update info using existing update json
91
+ * @param data existing update json
92
+ */
93
+ checkForUpdates(data: UpdateJSON): Promise<boolean>;
94
+ /**
95
+ * Download update using default options
96
+ */
97
+ downloadUpdate(): Promise<boolean>;
98
+ /**
99
+ * Download update using existing `asar.gz` buffer and signature
100
+ * @param data existing `asar.gz` buffer
101
+ * @param info update info
102
+ */
103
+ downloadUpdate(data: Uint8Array, info: Omit<UpdateInfo, 'minimumVersion'>): Promise<boolean>;
104
+ /**
105
+ * quit App and install
106
+ */
107
+ quitAndInstall(): void;
108
+ cancel(): void;
109
+ }
110
+ /**
111
+ * Auto check update, download and install
112
+ */
113
+ declare function autoUpdate(updater: Updater): Promise<void>;
6
114
 
7
- type Promisable<T> = T | Promise<T>;
8
115
  /**
9
- * hooks on rename temp asar path to `${app.name}.asar`
116
+ * Hooks on rename temp asar path to `${app.name}.asar`
10
117
  * @param install `() => renameSync(tempAsarPath, appNameAsarPath)`
11
118
  * @param tempAsarPath temp(updated) asar path
12
119
  * @param appNameAsarPath `${app.name}.asar` path
13
120
  * @param logger logger
14
- * @default install(); logger.info(`update success!`)
121
+ * @default install(); logger.info('update success!')
15
122
  */
16
123
  type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
17
124
  interface AppOption {
18
125
  /**
19
- * update provider
126
+ * Path to index file that make {@link startupWithUpdater} as default export
127
+ *
128
+ * Generate from plugin configuration by default
20
129
  */
21
- provider: IProvider;
130
+ mainPath?: string;
22
131
  /**
23
- * updater options
132
+ * Updater options
24
133
  */
25
134
  updater?: (() => Promisable<Updater>) | UpdaterOption;
26
135
  /**
27
- * hooks on rename temp asar path to `${app.name}.asar`
136
+ * Hooks on rename temp asar path to `${app.name}.asar`
28
137
  */
29
138
  onInstall?: OnInstallFunction;
30
139
  /**
31
- * hooks before app start up
140
+ * Hooks before app startup
32
141
  * @param mainFilePath main file path of `${app.name}.asar`
33
142
  * @param logger logger
34
143
  */
35
144
  beforeStart?: (mainFilePath: string, logger?: Logger) => Promisable<void>;
36
145
  /**
37
- * hooks on app start up error
146
+ * Hooks on app startup error
38
147
  * @param err installing or startup error
39
148
  * @param logger logger
40
149
  */
41
150
  onStartError?: (err: unknown, logger?: Logger) => void;
42
151
  }
43
152
  /**
44
- * utils for startuping with updater
153
+ * Utils to startup with updater
45
154
  * @param fn startup function
46
155
  * @example
47
156
  * // in electron/main/index.ts
@@ -51,28 +160,24 @@ interface AppOption {
51
160
  */
52
161
  declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>): (updater: Updater) => Promisable<void>;
53
162
  /**
54
- * initialize app
163
+ * Initialize Electron with updater
55
164
  * @example
56
- * ```ts
57
- * import { getGithubReleaseCdnGroup, initApp, parseGithubCdnURL } from 'electron-incremental-update'
58
- * import { repository } from '../package.json'
59
- *
60
- * const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
61
- * const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
62
- *
63
- * initApp({
64
- * // can be updater option or function that return updater
165
+ * createElectronApp({
65
166
  * updater: {
66
- * SIGNATURE_CERT: 'custom certificate',
67
- * repository,
68
- * updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
69
- * releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${app.name}.asar.gz`),
70
- * receiveBeta: true,
167
+ * provider: new GitHubProvider({
168
+ * username: 'yourname',
169
+ * repo: 'electron',
170
+ * }),
171
+ * },
172
+ * beforeStart(mainFilePath, logger) {
173
+ * logger?.debug(mainFilePath)
71
174
  * },
72
- * onStart: console.log
73
175
  * })
74
- * ```
75
176
  */
76
- declare function initApp(appOptions: AppOption): Promise<void>;
177
+ declare function createElectronApp(appOptions?: AppOption): Promise<void>;
178
+ /**
179
+ * @alias {@link createElectronApp}
180
+ */
181
+ declare const initApp: typeof createElectronApp;
77
182
 
78
- export { type AppOption, Logger, Updater, UpdaterOption, initApp, startupWithUpdater };
183
+ export { type AppOption, ErrorInfo, type Logger, Updater, UpdaterError, type UpdaterOption, autoUpdate, createElectronApp, initApp, startupWithUpdater };