UNPKG

5.69 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.AppImageUpdater = void 0;
7
8function _builderUtilRuntime() {
9 const data = require("builder-util-runtime");
10
11 _builderUtilRuntime = function () {
12 return data;
13 };
14
15 return data;
16}
17
18function _child_process() {
19 const data = require("child_process");
20
21 _child_process = function () {
22 return data;
23 };
24
25 return data;
26}
27
28function _fsExtra() {
29 const data = require("fs-extra");
30
31 _fsExtra = function () {
32 return data;
33 };
34
35 return data;
36}
37
38var _fs = require("fs");
39
40var path = _interopRequireWildcard(require("path"));
41
42function _BaseUpdater() {
43 const data = require("./BaseUpdater");
44
45 _BaseUpdater = function () {
46 return data;
47 };
48
49 return data;
50}
51
52function _FileWithEmbeddedBlockMapDifferentialDownloader() {
53 const data = require("./differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader");
54
55 _FileWithEmbeddedBlockMapDifferentialDownloader = function () {
56 return data;
57 };
58
59 return data;
60}
61
62function _Provider() {
63 const data = require("./providers/Provider");
64
65 _Provider = function () {
66 return data;
67 };
68
69 return data;
70}
71
72function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
73
74function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
75
76class AppImageUpdater extends _BaseUpdater().BaseUpdater {
77 constructor(options, app) {
78 super(options, app);
79 }
80
81 isUpdaterActive() {
82 if (process.env.APPIMAGE == null) {
83 if (process.env.SNAP == null) {
84 this._logger.warn("APPIMAGE env is not defined, current application is not an AppImage");
85 } else {
86 this._logger.info("SNAP env is defined, updater is disabled");
87 }
88
89 return false;
90 }
91
92 return super.isUpdaterActive();
93 }
94 /*** @private */
95
96
97 doDownloadUpdate(downloadUpdateOptions) {
98 const provider = downloadUpdateOptions.updateInfoAndProvider.provider;
99 const fileInfo = (0, _Provider().findFile)(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), "AppImage");
100 return this.executeDownload({
101 fileExtension: "AppImage",
102 fileInfo,
103 downloadUpdateOptions,
104 task: async (updateFile, downloadOptions) => {
105 const oldFile = process.env.APPIMAGE;
106
107 if (oldFile == null) {
108 throw (0, _builderUtilRuntime().newError)("APPIMAGE env is not defined", "ERR_UPDATER_OLD_FILE_NOT_FOUND");
109 }
110
111 let isDownloadFull = false;
112
113 try {
114 await new (_FileWithEmbeddedBlockMapDifferentialDownloader().FileWithEmbeddedBlockMapDifferentialDownloader)(fileInfo.info, this.httpExecutor, {
115 newUrl: fileInfo.url,
116 oldFile,
117 logger: this._logger,
118 newFile: updateFile,
119 isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,
120 requestHeaders: downloadUpdateOptions.requestHeaders
121 }).download();
122 } catch (e) {
123 this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`); // during test (developer machine mac) we must throw error
124
125
126 isDownloadFull = process.platform === "linux";
127 }
128
129 if (isDownloadFull) {
130 await this.httpExecutor.download(fileInfo.url, updateFile, downloadOptions);
131 }
132
133 await (0, _fsExtra().chmod)(updateFile, 0o755);
134 }
135 });
136 }
137
138 doInstall(options) {
139 const appImageFile = process.env.APPIMAGE;
140
141 if (appImageFile == null) {
142 throw (0, _builderUtilRuntime().newError)("APPIMAGE env is not defined", "ERR_UPDATER_OLD_FILE_NOT_FOUND");
143 } // https://stackoverflow.com/a/1712051/1910191
144
145
146 (0, _fs.unlinkSync)(appImageFile);
147 let destination;
148 const existingBaseName = path.basename(appImageFile); // https://github.com/electron-userland/electron-builder/issues/2964
149 // if no version in existing file name, it means that user wants to preserve current custom name
150
151 if (path.basename(options.installerPath) === existingBaseName || !/\d+\.\d+\.\d+/.test(existingBaseName)) {
152 // no version in the file name, overwrite existing
153 destination = appImageFile;
154 } else {
155 destination = path.join(path.dirname(appImageFile), path.basename(options.installerPath));
156 }
157
158 (0, _child_process().execFileSync)("mv", ["-f", options.installerPath, destination]);
159 const env = { ...process.env,
160 APPIMAGE_SILENT_INSTALL: "true"
161 };
162
163 if (options.isForceRunAfter) {
164 (0, _child_process().spawn)(destination, [], {
165 detached: true,
166 stdio: "ignore",
167 env
168 }).unref();
169 } else {
170 env.APPIMAGE_EXIT_AFTER_INSTALL = "true";
171 (0, _child_process().execFileSync)(destination, [], {
172 env
173 });
174 }
175
176 return true;
177 }
178
179} exports.AppImageUpdater = AppImageUpdater;
180// __ts-babel@6.0.4
181//# sourceMappingURL=AppImageUpdater.js.map
\No newline at end of file