UNPKG

9.58 kBTypeScriptView Raw
1import { AllPublishOptions, CancellationToken, PublishConfiguration, UpdateInfo, DownloadOptions, ProgressInfo } from "builder-util-runtime";
2import { OutgoingHttpHeaders } from "http";
3import { Lazy } from "lazy-val";
4import { SemVer } from "semver";
5import { AppAdapter } from "./AppAdapter";
6import { DownloadedUpdateHelper } from "./DownloadedUpdateHelper";
7import { LoginCallback } from "./electronHttpExecutor";
8import { Logger, Provider, ResolvedUpdateFileInfo, UpdateCheckResult, UpdateDownloadedEvent, UpdaterSignal } from "./main";
9import { ProviderPlatform } from "./providers/Provider";
10import type { TypedEmitter } from "tiny-typed-emitter";
11import Session = Electron.Session;
12import type { AuthInfo } from "electron";
13export type AppUpdaterEvents = {
14 error: (error: Error, message?: string) => void;
15 login: (info: AuthInfo, callback: LoginCallback) => void;
16 "checking-for-update": () => void;
17 "update-not-available": (info: UpdateInfo) => void;
18 "update-available": (info: UpdateInfo) => void;
19 "update-downloaded": (event: UpdateDownloadedEvent) => void;
20 "download-progress": (info: ProgressInfo) => void;
21 "update-cancelled": (info: UpdateInfo) => void;
22 "appimage-filename-updated": (path: string) => void;
23};
24declare const AppUpdater_base: new () => TypedEmitter<AppUpdaterEvents>;
25export declare abstract class AppUpdater extends AppUpdater_base {
26 /**
27 * Whether to automatically download an update when it is found.
28 */
29 autoDownload: boolean;
30 /**
31 * Whether to automatically install a downloaded update on app quit (if `quitAndInstall` was not called before).
32 */
33 autoInstallOnAppQuit: boolean;
34 /**
35 * *windows-only* Whether to run the app after finish install when run the installer NOT in silent mode.
36 * @default true
37 */
38 autoRunAppAfterInstall: boolean;
39 /**
40 * *GitHub provider only.* Whether to allow update to pre-release versions. Defaults to `true` if application version contains prerelease components (e.g. `0.12.1-alpha.1`, here `alpha` is a prerelease component), otherwise `false`.
41 *
42 * If `true`, downgrade will be allowed (`allowDowngrade` will be set to `true`).
43 */
44 allowPrerelease: boolean;
45 /**
46 * *GitHub provider only.* Get all release notes (from current version to latest), not just the latest.
47 * @default false
48 */
49 fullChangelog: boolean;
50 /**
51 * Whether to allow version downgrade (when a user from the beta channel wants to go back to the stable channel).
52 *
53 * Taken in account only if channel differs (pre-release version component in terms of semantic versioning).
54 *
55 * @default false
56 */
57 allowDowngrade: boolean;
58 /**
59 * Web installer files might not have signature verification, this switch prevents to load them unless it is needed.
60 *
61 * Currently false to prevent breaking the current API, but it should be changed to default true at some point that
62 * breaking changes are allowed.
63 *
64 * @default false
65 */
66 disableWebInstaller: boolean;
67 /**
68 * *NSIS only* Disable differential downloads and always perform full download of installer.
69 *
70 * @default false
71 */
72 disableDifferentialDownload: boolean;
73 /**
74 * Allows developer to force the updater to work in "dev" mode, looking for "dev-app-update.yml" instead of "app-update.yml"
75 * Dev: `path.join(this.app.getAppPath(), "dev-app-update.yml")`
76 * Prod: `path.join(process.resourcesPath!, "app-update.yml")`
77 *
78 * @default false
79 */
80 forceDevUpdateConfig: boolean;
81 /**
82 * The current application version.
83 */
84 readonly currentVersion: SemVer;
85 private _channel;
86 protected downloadedUpdateHelper: DownloadedUpdateHelper | null;
87 /**
88 * Get the update channel. Doesn't return `channel` from the update configuration, only if was previously set.
89 */
90 get channel(): string | null;
91 /**
92 * Set the update channel. Overrides `channel` in the update configuration.
93 *
94 * `allowDowngrade` will be automatically set to `true`. If this behavior is not suitable for you, simple set `allowDowngrade` explicitly after.
95 */
96 set channel(value: string | null);
97 /**
98 * The request headers.
99 */
100 requestHeaders: OutgoingHttpHeaders | null;
101 /**
102 * Shortcut for explicitly adding auth tokens to request headers
103 */
104 addAuthHeader(token: string): void;
105 protected _logger: Logger;
106 get netSession(): Session;
107 /**
108 * The logger. You can pass [electron-log](https://github.com/megahertz/electron-log), [winston](https://github.com/winstonjs/winston) or another logger with the following interface: `{ info(), warn(), error() }`.
109 * Set it to `null` if you would like to disable a logging feature.
110 */
111 get logger(): Logger | null;
112 set logger(value: Logger | null);
113 /**
114 * For type safety you can use signals, e.g. `autoUpdater.signals.updateDownloaded(() => {})` instead of `autoUpdater.on('update-available', () => {})`
115 */
116 readonly signals: UpdaterSignal;
117 private _appUpdateConfigPath;
118 /**
119 * test only
120 * @private
121 */
122 set updateConfigPath(value: string | null);
123 private clientPromise;
124 protected readonly stagingUserIdPromise: Lazy<string>;
125 private checkForUpdatesPromise;
126 private downloadPromise;
127 protected readonly app: AppAdapter;
128 protected updateInfoAndProvider: UpdateInfoAndProvider | null;
129 protected constructor(options: AllPublishOptions | null | undefined, app?: AppAdapter);
130 getFeedURL(): string | null | undefined;
131 /**
132 * Configure update provider. If value is `string`, [GenericServerOptions](./publish.md#genericserveroptions) will be set with value as `url`.
133 * @param options If you want to override configuration in the `app-update.yml`.
134 */
135 setFeedURL(options: PublishConfiguration | AllPublishOptions | string): void;
136 /**
137 * Asks the server whether there is an update.
138 */
139 checkForUpdates(): Promise<UpdateCheckResult | null>;
140 isUpdaterActive(): boolean;
141 checkForUpdatesAndNotify(downloadNotification?: DownloadNotification): Promise<UpdateCheckResult | null>;
142 private static formatDownloadNotification;
143 private isStagingMatch;
144 private computeFinalHeaders;
145 private isUpdateAvailable;
146 protected getUpdateInfoAndProvider(): Promise<UpdateInfoAndProvider>;
147 private createProviderRuntimeOptions;
148 private doCheckForUpdates;
149 protected onUpdateAvailable(updateInfo: UpdateInfo): void;
150 /**
151 * Start downloading update manually. You can use this method if `autoDownload` option is set to `false`.
152 * @returns {Promise<Array<string>>} Paths to downloaded files.
153 */
154 downloadUpdate(cancellationToken?: CancellationToken): Promise<Array<string>>;
155 protected dispatchError(e: Error): void;
156 protected dispatchUpdateDownloaded(event: UpdateDownloadedEvent): void;
157 protected abstract doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>>;
158 /**
159 * Restarts the app and installs the update after it has been downloaded.
160 * It should only be called after `update-downloaded` has been emitted.
161 *
162 * **Note:** `autoUpdater.quitAndInstall()` will close all application windows first and only emit `before-quit` event on `app` after that.
163 * This is different from the normal quit event sequence.
164 *
165 * @param isSilent *windows-only* Runs the installer in silent mode. Defaults to `false`.
166 * @param isForceRunAfter Run the app after finish even on silent install. Not applicable for macOS.
167 * Ignored if `isSilent` is set to `false`(In this case you can still set `autoRunAppAfterInstall` to `false` to prevent run the app after finish).
168 */
169 abstract quitAndInstall(isSilent?: boolean, isForceRunAfter?: boolean): void;
170 private loadUpdateConfig;
171 private computeRequestHeaders;
172 private getOrCreateStagingUserId;
173 private getOrCreateDownloadHelper;
174 protected executeDownload(taskOptions: DownloadExecutorTask): Promise<Array<string>>;
175 protected differentialDownloadInstaller(fileInfo: ResolvedUpdateFileInfo, downloadUpdateOptions: DownloadUpdateOptions, installerPath: string, provider: Provider<any>, oldInstallerFileName: string): Promise<boolean>;
176}
177export interface DownloadUpdateOptions {
178 readonly updateInfoAndProvider: UpdateInfoAndProvider;
179 readonly requestHeaders: OutgoingHttpHeaders;
180 readonly cancellationToken: CancellationToken;
181 readonly disableWebInstaller?: boolean;
182 readonly disableDifferentialDownload?: boolean;
183}
184/** @private */
185export declare class NoOpLogger implements Logger {
186 info(message?: any): void;
187 warn(message?: any): void;
188 error(message?: any): void;
189}
190export interface UpdateInfoAndProvider {
191 info: UpdateInfo;
192 provider: Provider<any>;
193}
194export interface DownloadExecutorTask {
195 readonly fileExtension: string;
196 readonly fileInfo: ResolvedUpdateFileInfo;
197 readonly downloadUpdateOptions: DownloadUpdateOptions;
198 readonly task: (destinationFile: string, downloadOptions: DownloadOptions, packageFile: string | null, removeTempDirIfAny: () => Promise<any>) => Promise<any>;
199 readonly done?: (event: UpdateDownloadedEvent) => Promise<any>;
200}
201export interface DownloadNotification {
202 body: string;
203 title: string;
204}
205/** @private */
206export interface TestOnlyUpdaterOptions {
207 platform: ProviderPlatform;
208 isUseDifferentialDownload?: boolean;
209}
210export {};