1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.BaseUpdater = void 0;
|
7 |
|
8 | function _AppUpdater() {
|
9 | const data = require("./AppUpdater");
|
10 |
|
11 | _AppUpdater = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | class BaseUpdater extends _AppUpdater().AppUpdater {
|
19 | constructor(options, app) {
|
20 | super(options, app);
|
21 | this.quitAndInstallCalled = false;
|
22 | this.quitHandlerAdded = false;
|
23 | }
|
24 |
|
25 | quitAndInstall(isSilent = false, isForceRunAfter = false) {
|
26 | this._logger.info(`Install on explicit quitAndInstall`);
|
27 |
|
28 | const isInstalled = this.install(isSilent, isSilent ? isForceRunAfter : true);
|
29 |
|
30 | if (isInstalled) {
|
31 | setImmediate(() => {
|
32 | this.app.quit();
|
33 | });
|
34 | } else {
|
35 | this.quitAndInstallCalled = false;
|
36 | }
|
37 | }
|
38 |
|
39 | executeDownload(taskOptions) {
|
40 | return super.executeDownload({ ...taskOptions,
|
41 | done: async event => {
|
42 | this.dispatchUpdateDownloaded(event);
|
43 | this.addQuitHandler();
|
44 | }
|
45 | });
|
46 | }
|
47 |
|
48 |
|
49 | install(isSilent, isForceRunAfter) {
|
50 | if (this.quitAndInstallCalled) {
|
51 | this._logger.warn("install call ignored: quitAndInstallCalled is set to true");
|
52 |
|
53 | return false;
|
54 | }
|
55 |
|
56 | const downloadedUpdateHelper = this.downloadedUpdateHelper;
|
57 | const installerPath = downloadedUpdateHelper == null ? null : downloadedUpdateHelper.file;
|
58 | const downloadedFileInfo = downloadedUpdateHelper == null ? null : downloadedUpdateHelper.downloadedFileInfo;
|
59 |
|
60 | if (installerPath == null || downloadedFileInfo == null) {
|
61 | this.dispatchError(new Error("No valid update available, can't quit and install"));
|
62 | return false;
|
63 | }
|
64 |
|
65 |
|
66 | this.quitAndInstallCalled = true;
|
67 |
|
68 | try {
|
69 | this._logger.info(`Install: isSilent: ${isSilent}, isForceRunAfter: ${isForceRunAfter}`);
|
70 |
|
71 | return this.doInstall({
|
72 | installerPath,
|
73 | isSilent,
|
74 | isForceRunAfter,
|
75 | isAdminRightsRequired: downloadedFileInfo.isAdminRightsRequired
|
76 | });
|
77 | } catch (e) {
|
78 | this.dispatchError(e);
|
79 | return false;
|
80 | }
|
81 | }
|
82 |
|
83 | addQuitHandler() {
|
84 | if (this.quitHandlerAdded || !this.autoInstallOnAppQuit) {
|
85 | return;
|
86 | }
|
87 |
|
88 | this.quitHandlerAdded = true;
|
89 | this.app.onQuit(exitCode => {
|
90 | if (this.quitAndInstallCalled) {
|
91 | this._logger.info("Update installer has already been triggered. Quitting application.");
|
92 |
|
93 | return;
|
94 | }
|
95 |
|
96 | if (exitCode !== 0) {
|
97 | this._logger.info(`Update will be not installed on quit because application is quitting with exit code ${exitCode}`);
|
98 |
|
99 | return;
|
100 | }
|
101 |
|
102 | this._logger.info("Auto install update on quit");
|
103 |
|
104 | this.install(true, false);
|
105 | });
|
106 | }
|
107 |
|
108 | } exports.BaseUpdater = BaseUpdater;
|
109 |
|
110 |
|
\ | No newline at end of file |