Skip to content

Commit ebd430e

Browse files
committed
fix: windows update fails, doesnt show first time and task manager ux
1 parent 02d6041 commit ebd430e

File tree

3 files changed

+29
-47
lines changed

3 files changed

+29
-47
lines changed
Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,30 @@
11
const fs = require('fs');
22
const path = require('path');
3-
const { exec } = require('child_process');
3+
const { spawn } = require('child_process');
44

55
const args = process.argv.slice(2); // Skip the first two elements
66
const appdataDir = args[0];
7-
function launchInstaller(zipFilePath, absoluteExtractPath) {
8-
return new Promise((resolve, reject)=>{
9-
const extractPath = path.join(appdataDir, 'installer', "extracted");
10-
const dirContents = fs.readdirSync(extractPath);
11-
console.log("extracted dir contents: ", dirContents);
12-
let exePath;
13-
if(dirContents.length === 1){
14-
exePath = path.join(extractPath, dirContents[0]);
15-
if(!exePath.endsWith(".exe")){
16-
reject("Cannot resolve upgrade installer exe in: ", extractPath);
17-
return;
18-
}
19-
} else {
20-
reject("Cannot resolve upgrade installer exe in: ", extractPath);
21-
return;
22-
}
23-
24-
exec(`"${exePath}" /P`, (error, stdout, stderr) => {
25-
if (error) {
26-
console.error(`Error extracting ZIP file: ${error.message}`);
27-
reject(error.message);
28-
return;
29-
}
30-
if (stderr) {
31-
console.error(`Error output: ${stderr}`);
32-
reject(stderr);
33-
return;
34-
}
35-
console.log(`Updater launched successfully to ${absoluteExtractPath}`);
36-
resolve();
37-
});
38-
});
39-
}
407

418
if(!appdataDir) {
429
process.exit(1);
4310
}
44-
launchInstaller()
45-
.then(()=>{
46-
process.exit(0);
47-
})
48-
.catch((err)=>{
49-
console.error(err);
11+
const extractPath = path.join(appdataDir, 'installer', "extracted");
12+
const dirContents = fs.readdirSync(extractPath);
13+
console.log("extracted dir contents: ", dirContents);
14+
let exePath;
15+
if(dirContents.length === 1){
16+
exePath = path.join(extractPath, dirContents[0]);
17+
if(!exePath.endsWith(".exe")){
18+
console.error("Cannot resolve upgrade installer exe in: ", extractPath);
5019
process.exit(1);
51-
});
20+
}
21+
} else {
22+
console.error("Cannot resolve upgrade installer exe in: ", extractPath);
23+
process.exit(1);
24+
}
25+
const child = spawn(`${exePath}`, ['/P'], {
26+
detached: true, // This allows the child process to run independently of its parent.
27+
stdio: 'ignore' // This is often used in conjunction with detached to avoid keeping the parent's stdio open.
28+
});
29+
child.unref();
30+
process.exit(0);

src/extensionsIntegrated/appUpdater/main.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ define(function (require, exports, module) {
6262
}
6363
}
6464
});
65+
updateTask.show();
6566
}
6667
let updateAvailable = PreferencesManager.getViewState(KEY_UPDATE_AVAILABLE);
6768
if(updateAvailable){
@@ -480,13 +481,9 @@ define(function (require, exports, module) {
480481
_refreshUpdateStatus();
481482
// check for updates at boot
482483
let lastUpdateCheckTime = PreferencesManager.getViewState(KEY_LAST_UPDATE_CHECK_TIME);
483-
if(!lastUpdateCheckTime){
484-
lastUpdateCheckTime = Date.now();
485-
PreferencesManager.setViewState(KEY_LAST_UPDATE_CHECK_TIME, lastUpdateCheckTime);
486-
}
487484
const currentTime = Date.now();
488485
const oneDayInMilliseconds = 24 * 60 * 60 * 1000; // 24 hours * 60 minutes * 60 seconds * 1000 milliseconds
489-
if ((currentTime - lastUpdateCheckTime) < oneDayInMilliseconds) {
486+
if(lastUpdateCheckTime && ((currentTime - lastUpdateCheckTime) < oneDayInMilliseconds)){
490487
console.log("Skipping update check: last update check was within one day");
491488
return;
492489
}

src/features/TaskManager.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ define(function (require, exports, module) {
306306
* @typedef {Object} TaskObject
307307
* Methods for managing the task's state and UI representation in the TaskManager.
308308
*
309+
* @property {function(): void} show - Shows the task popup in the ui.
309310
* @property {function(): void} close - Closes the task and removes it from the UI.
310311
* @property {function(string): void} setTitle - Sets the task's title.
311312
* @property {function(): string} getTitle - Returns the task's title.
@@ -432,6 +433,10 @@ define(function (require, exports, module) {
432433
return task._message;
433434
}
434435

436+
function show() {
437+
$("#status-tasks .btn-dropdown").click();
438+
}
439+
435440
function setProgressPercent(percent) {
436441
task._percent = percent;
437442
task._completedStatus = STATUS_INCOMPLETE;
@@ -495,6 +500,7 @@ define(function (require, exports, module) {
495500
_renderPlayIcons(task);
496501
}
497502

503+
task.show = show;
498504
task.close = close;
499505
task.setTitle = setTitle;
500506
task.getTitle = getTitle;
@@ -539,7 +545,7 @@ define(function (require, exports, module) {
539545
exports._onSelect = _onSelect;
540546
exports._setLegacyExtensionBusy = _setLegacyExtensionBusy;
541547

542-
window.TaskManager = exports; // todo remove this
548+
window.TaskManager = exports;
543549
// public apis
544550
exports.addNewTask = addNewTask;
545551
});

0 commit comments

Comments
 (0)