UNPKG

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