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

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,15 +1,17 @@
1
- import { U as UpdateJSON } from './version-CffZWDhZ.cjs';
2
- import { O as OnDownloading, U as URLHandler, I as IProvider } from './types-DxPmQmaq.cjs';
1
+ import { EventEmitter } from 'node:events';
2
+ import { U as UpdateJSON, a as UpdateInfo } from './version-CemSHimT.cjs';
3
+ import { D as DownloadingInfo, I as IProvider, U as URLHandler } from './types-Tequ_V2o.cjs';
3
4
  import '@subframe7536/type-utils';
4
5
 
5
6
  declare const ErrorInfo: {
6
7
  readonly download: "Download failed";
7
8
  readonly validate: "Validate failed";
8
9
  readonly param: "Missing params";
9
- readonly version: "Unsatisfied version";
10
+ readonly network: "Network error";
10
11
  };
11
12
  declare class UpdaterError extends Error {
12
- constructor(msg: typeof ErrorInfo[keyof typeof ErrorInfo], info: string);
13
+ code: keyof typeof ErrorInfo;
14
+ constructor(msg: keyof typeof ErrorInfo, info: string);
13
15
  }
14
16
  type CheckResult<T extends UpdateJSON> = {
15
17
  success: true;
@@ -49,12 +51,17 @@ interface UpdaterOption {
49
51
  logger?: Logger;
50
52
  }
51
53
 
52
- declare class Updater {
54
+ declare class Updater extends EventEmitter<{
55
+ 'checking': any;
56
+ 'update-available': [data: UpdateInfo];
57
+ 'update-unavailable': [reason: string];
58
+ 'error': [error: UpdaterError];
59
+ 'download-progress': [info: DownloadingInfo];
60
+ 'update-downloaded': any;
61
+ }> {
53
62
  private CERT;
54
63
  private info?;
55
- private options;
56
64
  private asarPath;
57
- private gzipPath;
58
65
  private tmpFilePath;
59
66
  private provider;
60
67
  /**
@@ -62,34 +69,19 @@ declare class Updater {
62
69
  */
63
70
  logger?: Logger;
64
71
  /**
65
- * downloading progress hook
66
- * @param progress download progress
67
- * @example
68
- * updater.onDownloading = ({ percent, total, current }) => {
69
- * console.log(`download progress: ${percent}, total: ${total}, current: ${current}`)
70
- * }
71
- */
72
- onDownloading?: OnDownloading;
73
- /**
74
- * URL handler hook
75
- *
76
- * for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDN links}
77
- * @param url source url
78
- * @param isDownloadAsar whether is download asar
72
+ * whether to receive beta update
79
73
  */
80
- handleURL?: URLHandler;
74
+ receiveBeta?: boolean;
81
75
  /**
82
- * whether receive beta version
76
+ * whether force update in DEV
83
77
  */
84
- get receiveBeta(): boolean;
85
- set receiveBeta(receiveBeta: boolean);
78
+ forceUpdate?: boolean;
86
79
  /**
87
80
  * initialize incremental updater
88
81
  * @param provider update provider
89
82
  * @param option UpdaterOption
90
83
  */
91
84
  constructor(provider: IProvider, option?: UpdaterOption);
92
- private needUpdate;
93
85
  /**
94
86
  * this function is used to parse download data.
95
87
  * - if format is `'json'`
@@ -101,40 +93,45 @@ declare class Updater {
101
93
  * @param format 'json' or 'buffer'
102
94
  * @param data download URL or update json or buffer
103
95
  */
104
- private parseData;
96
+ private fetch;
105
97
  /**
106
- * check update info using default options
98
+ * handle error message and emit error event
107
99
  */
108
- checkUpdate<T extends UpdateJSON>(): Promise<CheckResult<T>>;
100
+ private err;
109
101
  /**
110
- * check update info using custom url
111
- * @param url custom download URL of `updatejson`
102
+ * check update info using default options
112
103
  */
113
- checkUpdate<T extends UpdateJSON>(url: string): Promise<CheckResult<T>>;
104
+ checkUpdate(): Promise<boolean>;
114
105
  /**
115
106
  * check update info using existing update json
116
107
  * @param data existing update json
117
108
  */
118
- checkUpdate<T extends UpdateJSON>(data: T): Promise<CheckResult<T>>;
109
+ checkUpdate(data: UpdateJSON): Promise<boolean>;
119
110
  /**
120
111
  * download update using default options
121
112
  */
122
- download(): Promise<DownloadResult>;
123
- /**
124
- * download update using custom url
125
- * @param url custom download URL
126
- */
127
- download(url: string): Promise<DownloadResult>;
113
+ download(): Promise<boolean>;
128
114
  /**
129
115
  * download update using existing `asar.gz` buffer and signature
130
116
  * @param data existing `asar.gz` buffer
131
117
  * @param sig signature
132
118
  */
133
- download(data: Buffer, sig: string): Promise<DownloadResult>;
119
+ download(data: Uint8Array | Buffer, sig: string): Promise<boolean>;
134
120
  /**
135
121
  * quit App and install
136
122
  */
137
123
  quitAndInstall(): void;
124
+ /**
125
+ * setup provider URL handler
126
+ *
127
+ * @example
128
+ * updater.setURLHandler((url, isDownloadingAsar) => {
129
+ * if (isDownloadingAsar) {
130
+ * return url.replace('https://raw.githubusercontent.com', 'https://cdn.jsdelivr.net/gh')
131
+ * }
132
+ * })
133
+ */
134
+ setURLHandler(handler: URLHandler): void;
138
135
  }
139
136
 
140
137
  type Promisable<T> = T | Promise<T>;
@@ -146,7 +143,7 @@ type Promisable<T> = T | Promise<T>;
146
143
  * @param logger logger
147
144
  * @default install(); logger.info(`update success!`)
148
145
  */
149
- type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger: Logger) => Promisable<void>;
146
+ type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
150
147
  interface AppOption {
151
148
  /**
152
149
  * update provider
@@ -165,13 +162,13 @@ interface AppOption {
165
162
  * @param mainFilePath main file path of `${app.name}.asar`
166
163
  * @param logger logger
167
164
  */
168
- beforeStart?: (mainFilePath: string, logger: Logger) => Promisable<void>;
165
+ beforeStart?: (mainFilePath: string, logger?: Logger) => Promisable<void>;
169
166
  /**
170
167
  * hooks on app start up error
171
168
  * @param err installing or startup error
172
169
  * @param logger logger
173
170
  */
174
- onStartError?: (err: unknown, logger: Logger) => void;
171
+ onStartError?: (err: unknown, logger?: Logger) => void;
175
172
  }
176
173
  /**
177
174
  * utils for startuping with updater
package/dist/index.d.ts CHANGED
@@ -1,15 +1,17 @@
1
- import { U as UpdateJSON } from './version-CffZWDhZ.js';
2
- import { O as OnDownloading, U as URLHandler, I as IProvider } from './types-seJf3Wbc.js';
1
+ import { EventEmitter } from 'node:events';
2
+ import { U as UpdateJSON, a as UpdateInfo } from './version-CemSHimT.js';
3
+ import { D as DownloadingInfo, I as IProvider, U as URLHandler } from './types-DxhNaNgR.js';
3
4
  import '@subframe7536/type-utils';
4
5
 
5
6
  declare const ErrorInfo: {
6
7
  readonly download: "Download failed";
7
8
  readonly validate: "Validate failed";
8
9
  readonly param: "Missing params";
9
- readonly version: "Unsatisfied version";
10
+ readonly network: "Network error";
10
11
  };
11
12
  declare class UpdaterError extends Error {
12
- constructor(msg: typeof ErrorInfo[keyof typeof ErrorInfo], info: string);
13
+ code: keyof typeof ErrorInfo;
14
+ constructor(msg: keyof typeof ErrorInfo, info: string);
13
15
  }
14
16
  type CheckResult<T extends UpdateJSON> = {
15
17
  success: true;
@@ -49,12 +51,17 @@ interface UpdaterOption {
49
51
  logger?: Logger;
50
52
  }
51
53
 
52
- declare class Updater {
54
+ declare class Updater extends EventEmitter<{
55
+ 'checking': any;
56
+ 'update-available': [data: UpdateInfo];
57
+ 'update-unavailable': [reason: string];
58
+ 'error': [error: UpdaterError];
59
+ 'download-progress': [info: DownloadingInfo];
60
+ 'update-downloaded': any;
61
+ }> {
53
62
  private CERT;
54
63
  private info?;
55
- private options;
56
64
  private asarPath;
57
- private gzipPath;
58
65
  private tmpFilePath;
59
66
  private provider;
60
67
  /**
@@ -62,34 +69,19 @@ declare class Updater {
62
69
  */
63
70
  logger?: Logger;
64
71
  /**
65
- * downloading progress hook
66
- * @param progress download progress
67
- * @example
68
- * updater.onDownloading = ({ percent, total, current }) => {
69
- * console.log(`download progress: ${percent}, total: ${total}, current: ${current}`)
70
- * }
71
- */
72
- onDownloading?: OnDownloading;
73
- /**
74
- * URL handler hook
75
- *
76
- * for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDN links}
77
- * @param url source url
78
- * @param isDownloadAsar whether is download asar
72
+ * whether to receive beta update
79
73
  */
80
- handleURL?: URLHandler;
74
+ receiveBeta?: boolean;
81
75
  /**
82
- * whether receive beta version
76
+ * whether force update in DEV
83
77
  */
84
- get receiveBeta(): boolean;
85
- set receiveBeta(receiveBeta: boolean);
78
+ forceUpdate?: boolean;
86
79
  /**
87
80
  * initialize incremental updater
88
81
  * @param provider update provider
89
82
  * @param option UpdaterOption
90
83
  */
91
84
  constructor(provider: IProvider, option?: UpdaterOption);
92
- private needUpdate;
93
85
  /**
94
86
  * this function is used to parse download data.
95
87
  * - if format is `'json'`
@@ -101,40 +93,45 @@ declare class Updater {
101
93
  * @param format 'json' or 'buffer'
102
94
  * @param data download URL or update json or buffer
103
95
  */
104
- private parseData;
96
+ private fetch;
105
97
  /**
106
- * check update info using default options
98
+ * handle error message and emit error event
107
99
  */
108
- checkUpdate<T extends UpdateJSON>(): Promise<CheckResult<T>>;
100
+ private err;
109
101
  /**
110
- * check update info using custom url
111
- * @param url custom download URL of `updatejson`
102
+ * check update info using default options
112
103
  */
113
- checkUpdate<T extends UpdateJSON>(url: string): Promise<CheckResult<T>>;
104
+ checkUpdate(): Promise<boolean>;
114
105
  /**
115
106
  * check update info using existing update json
116
107
  * @param data existing update json
117
108
  */
118
- checkUpdate<T extends UpdateJSON>(data: T): Promise<CheckResult<T>>;
109
+ checkUpdate(data: UpdateJSON): Promise<boolean>;
119
110
  /**
120
111
  * download update using default options
121
112
  */
122
- download(): Promise<DownloadResult>;
123
- /**
124
- * download update using custom url
125
- * @param url custom download URL
126
- */
127
- download(url: string): Promise<DownloadResult>;
113
+ download(): Promise<boolean>;
128
114
  /**
129
115
  * download update using existing `asar.gz` buffer and signature
130
116
  * @param data existing `asar.gz` buffer
131
117
  * @param sig signature
132
118
  */
133
- download(data: Buffer, sig: string): Promise<DownloadResult>;
119
+ download(data: Uint8Array | Buffer, sig: string): Promise<boolean>;
134
120
  /**
135
121
  * quit App and install
136
122
  */
137
123
  quitAndInstall(): void;
124
+ /**
125
+ * setup provider URL handler
126
+ *
127
+ * @example
128
+ * updater.setURLHandler((url, isDownloadingAsar) => {
129
+ * if (isDownloadingAsar) {
130
+ * return url.replace('https://raw.githubusercontent.com', 'https://cdn.jsdelivr.net/gh')
131
+ * }
132
+ * })
133
+ */
134
+ setURLHandler(handler: URLHandler): void;
138
135
  }
139
136
 
140
137
  type Promisable<T> = T | Promise<T>;
@@ -146,7 +143,7 @@ type Promisable<T> = T | Promise<T>;
146
143
  * @param logger logger
147
144
  * @default install(); logger.info(`update success!`)
148
145
  */
149
- type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger: Logger) => Promisable<void>;
146
+ type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
150
147
  interface AppOption {
151
148
  /**
152
149
  * update provider
@@ -165,13 +162,13 @@ interface AppOption {
165
162
  * @param mainFilePath main file path of `${app.name}.asar`
166
163
  * @param logger logger
167
164
  */
168
- beforeStart?: (mainFilePath: string, logger: Logger) => Promisable<void>;
165
+ beforeStart?: (mainFilePath: string, logger?: Logger) => Promisable<void>;
169
166
  /**
170
167
  * hooks on app start up error
171
168
  * @param err installing or startup error
172
169
  * @param logger logger
173
170
  */
174
- onStartError?: (err: unknown, logger: Logger) => void;
171
+ onStartError?: (err: unknown, logger?: Logger) => void;
175
172
  }
176
173
  /**
177
174
  * utils for startuping with updater