AppUpdater.d.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /// <reference types="node" />
  2. import { AllPublishOptions, CancellationToken, PublishConfiguration, UpdateInfo } from "builder-util-runtime";
  3. import { EventEmitter } from "events";
  4. import { OutgoingHttpHeaders } from "http";
  5. import { Lazy } from "lazy-val";
  6. import "source-map-support/register";
  7. import { Logger, Provider, UpdateCheckResult, UpdaterSignal } from "./main";
  8. import { DownloadedUpdateHelper } from "./DownloadedUpdateHelper";
  9. export declare abstract class AppUpdater extends EventEmitter {
  10. /**
  11. * Whether to automatically download an update when it is found.
  12. */
  13. autoDownload: boolean;
  14. /**
  15. * Whether to automatically install a downloaded update on app quit (if `quitAndInstall` was not called before).
  16. *
  17. * Applicable only on Windows and Linux.
  18. */
  19. autoInstallOnAppQuit: boolean;
  20. /**
  21. * *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`.
  22. *
  23. * If `true`, downgrade will be allowed (`allowDowngrade` will be set to `true`).
  24. */
  25. allowPrerelease: boolean;
  26. /**
  27. * *GitHub provider only.* Get all release notes (from current version to latest), not just the latest.
  28. * @default false
  29. */
  30. fullChangelog: boolean;
  31. /**
  32. * Whether to allow version downgrade (when a user from the beta channel wants to go back to the stable channel).
  33. * @default false
  34. */
  35. allowDowngrade: boolean;
  36. /**
  37. * The current application version.
  38. */
  39. readonly currentVersion: string;
  40. private _channel;
  41. protected readonly downloadedUpdateHelper: DownloadedUpdateHelper;
  42. /**
  43. * Get the update channel. Not applicable for GitHub. Doesn't return `channel` from the update configuration, only if was previously set.
  44. */
  45. /**
  46. * Set the update channel. Not applicable for GitHub. Overrides `channel` in the update configuration.
  47. *
  48. * `allowDowngrade` will be automatically set to `true`. If this behavior is not suitable for you, simple set `allowDowngrade` explicitly after.
  49. */
  50. channel: string | null;
  51. /**
  52. * The request headers.
  53. */
  54. requestHeaders: OutgoingHttpHeaders | null;
  55. protected _logger: Logger;
  56. /**
  57. * 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() }`.
  58. * Set it to `null` if you would like to disable a logging feature.
  59. */
  60. logger: Logger | null;
  61. /**
  62. * For type safety you can use signals, e.g. `autoUpdater.signals.updateDownloaded(() => {})` instead of `autoUpdater.on('update-available', () => {})`
  63. */
  64. readonly signals: UpdaterSignal;
  65. private _appUpdateConfigPath;
  66. /**
  67. * test only
  68. * @private
  69. */
  70. updateConfigPath: string | null;
  71. protected updateAvailable: boolean;
  72. private clientPromise;
  73. protected readonly provider: Promise<Provider<any>>;
  74. protected readonly stagingUserIdPromise: Lazy<string>;
  75. configOnDisk: Lazy<any>;
  76. private readonly untilAppReady;
  77. private checkForUpdatesPromise;
  78. protected readonly app: Electron.App;
  79. protected updateInfo: UpdateInfo | null;
  80. protected constructor(options: AllPublishOptions | null | undefined, app?: Electron.App);
  81. getFeedURL(): string | null | undefined;
  82. /**
  83. * Configure update provider. If value is `string`, [GenericServerOptions](/configuration/publish.md#genericserveroptions) will be set with value as `url`.
  84. * @param options If you want to override configuration in the `app-update.yml`.
  85. */
  86. setFeedURL(options: PublishConfiguration | AllPublishOptions | string): void;
  87. /**
  88. * Asks the server whether there is an update.
  89. */
  90. checkForUpdates(): Promise<UpdateCheckResult>;
  91. checkForUpdatesAndNotify(): Promise<UpdateCheckResult | null>;
  92. private isStagingMatch(updateInfo);
  93. private _checkForUpdates();
  94. private computeFinalHeaders(headers);
  95. protected getUpdateInfo(): Promise<UpdateInfo>;
  96. private doCheckForUpdates();
  97. protected onUpdateAvailable(updateInfo: UpdateInfo): void;
  98. /**
  99. * Start downloading update manually. You can use this method if `autoDownload` option is set to `false`.
  100. * @returns {Promise<string>} Path to downloaded file.
  101. */
  102. downloadUpdate(cancellationToken?: CancellationToken): Promise<any>;
  103. protected dispatchError(e: Error): void;
  104. protected abstract doDownloadUpdate(updateInfo: UpdateInfo, cancellationToken: CancellationToken): Promise<Array<string>>;
  105. /**
  106. * Restarts the app and installs the update after it has been downloaded.
  107. * It should only be called after `update-downloaded` has been emitted.
  108. *
  109. * **Note:** `autoUpdater.quitAndInstall()` will close all application windows first and only emit `before-quit` event on `app` after that.
  110. * This is different from the normal quit event sequence.
  111. *
  112. * @param isSilent *windows-only* Runs the installer in silent mode. Defaults to `false`.
  113. * @param isForceRunAfter Run the app after finish even on silent install. Not applicable for macOS. Ignored if `isSilent` is set to `false`.
  114. */
  115. abstract quitAndInstall(isSilent?: boolean, isForceRunAfter?: boolean): void;
  116. private loadUpdateConfig();
  117. /*** @private */
  118. protected computeRequestHeaders(): Promise<OutgoingHttpHeaders>;
  119. private getOrCreateStagingUserId();
  120. }
  121. /** @private */
  122. export declare class NoOpLogger implements Logger {
  123. info(message?: any): void;
  124. warn(message?: any): void;
  125. error(message?: any): void;
  126. }