UNPKG

7.37 kBTypeScriptView Raw
1/// <reference types="node" />
2import { AllPublishOptions, CancellationToken, PublishConfiguration, UpdateInfo, DownloadOptions } from "builder-util-runtime";
3import { EventEmitter } from "events";
4import { OutgoingHttpHeaders } from "http";
5import { Lazy } from "lazy-val";
6import { SemVer } from "semver";
7import { AppAdapter } from "./AppAdapter";
8import { DownloadedUpdateHelper } from "./DownloadedUpdateHelper";
9import { Logger, Provider, ResolvedUpdateFileInfo, UpdateCheckResult, UpdateDownloadedEvent, UpdaterSignal } from "./main";
10import { ProviderPlatform } from "./providers/Provider";
11import Session = Electron.Session;
12export declare abstract class AppUpdater extends EventEmitter {
13 /**
14 * Whether to automatically download an update when it is found.
15 */
16 autoDownload: boolean;
17 /**
18 * Whether to automatically install a downloaded update on app quit (if `quitAndInstall` was not called before).
19 */
20 autoInstallOnAppQuit: boolean;
21 /**
22 * *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`.
23 *
24 * If `true`, downgrade will be allowed (`allowDowngrade` will be set to `true`).
25 */
26 allowPrerelease: boolean;
27 /**
28 * *GitHub provider only.* Get all release notes (from current version to latest), not just the latest.
29 * @default false
30 */
31 fullChangelog: boolean;
32 /**
33 * Whether to allow version downgrade (when a user from the beta channel wants to go back to the stable channel).
34 *
35 * Taken in account only if channel differs (pre-release version component in terms of semantic versioning).
36 *
37 * @default false
38 */
39 allowDowngrade: boolean;
40 /**
41 * The current application version.
42 */
43 readonly currentVersion: SemVer;
44 private _channel;
45 protected downloadedUpdateHelper: DownloadedUpdateHelper | null;
46 /**
47 * Get the update channel. Not applicable for GitHub. Doesn't return `channel` from the update configuration, only if was previously set.
48 */
49 get channel(): string | null;
50 /**
51 * Set the update channel. Not applicable for GitHub. Overrides `channel` in the update configuration.
52 *
53 * `allowDowngrade` will be automatically set to `true`. If this behavior is not suitable for you, simple set `allowDowngrade` explicitly after.
54 */
55 set channel(value: string | null);
56 /**
57 * The request headers.
58 */
59 requestHeaders: OutgoingHttpHeaders | null;
60 /**
61 * Shortcut for explicitly adding auth tokens to request headers
62 */
63 addAuthHeader(token: string): void;
64 protected _logger: Logger;
65 get netSession(): Session;
66 /**
67 * 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() }`.
68 * Set it to `null` if you would like to disable a logging feature.
69 */
70 get logger(): Logger | null;
71 set logger(value: Logger | null);
72 /**
73 * For type safety you can use signals, e.g. `autoUpdater.signals.updateDownloaded(() => {})` instead of `autoUpdater.on('update-available', () => {})`
74 */
75 readonly signals: UpdaterSignal;
76 private _appUpdateConfigPath;
77 /**
78 * test only
79 * @private
80 */
81 set updateConfigPath(value: string | null);
82 private clientPromise;
83 protected readonly stagingUserIdPromise: Lazy<string>;
84 private checkForUpdatesPromise;
85 protected readonly app: AppAdapter;
86 protected updateInfoAndProvider: UpdateInfoAndProvider | null;
87 protected constructor(options: AllPublishOptions | null | undefined, app?: AppAdapter);
88 getFeedURL(): string | null | undefined;
89 /**
90 * Configure update provider. If value is `string`, [GenericServerOptions](/configuration/publish#genericserveroptions) will be set with value as `url`.
91 * @param options If you want to override configuration in the `app-update.yml`.
92 */
93 setFeedURL(options: PublishConfiguration | AllPublishOptions | string): void;
94 /**
95 * Asks the server whether there is an update.
96 */
97 checkForUpdates(): Promise<UpdateCheckResult>;
98 isUpdaterActive(): boolean;
99 checkForUpdatesAndNotify(downloadNotification?: DownloadNotification): Promise<UpdateCheckResult | null>;
100 private static formatDownloadNotification;
101 private isStagingMatch;
102 private computeFinalHeaders;
103 private isUpdateAvailable;
104 protected getUpdateInfoAndProvider(): Promise<UpdateInfoAndProvider>;
105 private createProviderRuntimeOptions;
106 private doCheckForUpdates;
107 protected onUpdateAvailable(updateInfo: UpdateInfo): void;
108 /**
109 * Start downloading update manually. You can use this method if `autoDownload` option is set to `false`.
110 * @returns {Promise<string>} Path to downloaded file.
111 */
112 downloadUpdate(cancellationToken?: CancellationToken): Promise<any>;
113 protected dispatchError(e: Error): void;
114 protected dispatchUpdateDownloaded(event: UpdateDownloadedEvent): void;
115 protected abstract doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>>;
116 /**
117 * Restarts the app and installs the update after it has been downloaded.
118 * It should only be called after `update-downloaded` has been emitted.
119 *
120 * **Note:** `autoUpdater.quitAndInstall()` will close all application windows first and only emit `before-quit` event on `app` after that.
121 * This is different from the normal quit event sequence.
122 *
123 * @param isSilent *windows-only* Runs the installer in silent mode. Defaults to `false`.
124 * @param isForceRunAfter Run the app after finish even on silent install. Not applicable for macOS. Ignored if `isSilent` is set to `false`.
125 */
126 abstract quitAndInstall(isSilent?: boolean, isForceRunAfter?: boolean): void;
127 private loadUpdateConfig;
128 private computeRequestHeaders;
129 private getOrCreateStagingUserId;
130 private getOrCreateDownloadHelper;
131 protected executeDownload(taskOptions: DownloadExecutorTask): Promise<Array<string>>;
132}
133export interface DownloadUpdateOptions {
134 readonly updateInfoAndProvider: UpdateInfoAndProvider;
135 readonly requestHeaders: OutgoingHttpHeaders;
136 readonly cancellationToken: CancellationToken;
137}
138/** @private */
139export declare class NoOpLogger implements Logger {
140 info(message?: any): void;
141 warn(message?: any): void;
142 error(message?: any): void;
143}
144export interface UpdateInfoAndProvider {
145 info: UpdateInfo;
146 provider: Provider<any>;
147}
148export interface DownloadExecutorTask {
149 readonly fileExtension: string;
150 readonly fileInfo: ResolvedUpdateFileInfo;
151 readonly downloadUpdateOptions: DownloadUpdateOptions;
152 readonly task: (destinationFile: string, downloadOptions: DownloadOptions, packageFile: string | null, removeTempDirIfAny: () => Promise<any>) => Promise<any>;
153 readonly done?: (event: UpdateDownloadedEvent) => Promise<any>;
154}
155export interface DownloadNotification {
156 body: string;
157 title: string;
158}
159/** @private */
160export interface TestOnlyUpdaterOptions {
161 platform: ProviderPlatform;
162 isUseDifferentialDownload?: boolean;
163}