-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: windows update fails, doesnt show first time and task manager ux
- Loading branch information
Showing
3 changed files
with
29 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,30 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { exec } = require('child_process'); | ||
const { spawn } = require('child_process'); | ||
|
||
const args = process.argv.slice(2); // Skip the first two elements | ||
const appdataDir = args[0]; | ||
function launchInstaller(zipFilePath, absoluteExtractPath) { | ||
return new Promise((resolve, reject)=>{ | ||
const extractPath = path.join(appdataDir, 'installer', "extracted"); | ||
const dirContents = fs.readdirSync(extractPath); | ||
console.log("extracted dir contents: ", dirContents); | ||
let exePath; | ||
if(dirContents.length === 1){ | ||
exePath = path.join(extractPath, dirContents[0]); | ||
if(!exePath.endsWith(".exe")){ | ||
reject("Cannot resolve upgrade installer exe in: ", extractPath); | ||
return; | ||
} | ||
} else { | ||
reject("Cannot resolve upgrade installer exe in: ", extractPath); | ||
return; | ||
} | ||
|
||
exec(`"${exePath}" /P`, (error, stdout, stderr) => { | ||
if (error) { | ||
console.error(`Error extracting ZIP file: ${error.message}`); | ||
reject(error.message); | ||
return; | ||
} | ||
if (stderr) { | ||
console.error(`Error output: ${stderr}`); | ||
reject(stderr); | ||
return; | ||
} | ||
console.log(`Updater launched successfully to ${absoluteExtractPath}`); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
if(!appdataDir) { | ||
process.exit(1); | ||
} | ||
launchInstaller() | ||
.then(()=>{ | ||
process.exit(0); | ||
}) | ||
.catch((err)=>{ | ||
console.error(err); | ||
const extractPath = path.join(appdataDir, 'installer', "extracted"); | ||
const dirContents = fs.readdirSync(extractPath); | ||
console.log("extracted dir contents: ", dirContents); | ||
let exePath; | ||
if(dirContents.length === 1){ | ||
exePath = path.join(extractPath, dirContents[0]); | ||
if(!exePath.endsWith(".exe")){ | ||
console.error("Cannot resolve upgrade installer exe in: ", extractPath); | ||
process.exit(1); | ||
}); | ||
} | ||
} else { | ||
console.error("Cannot resolve upgrade installer exe in: ", extractPath); | ||
process.exit(1); | ||
} | ||
const child = spawn(`${exePath}`, ['/P'], { | ||
detached: true, // This allows the child process to run independently of its parent. | ||
stdio: 'ignore' // This is often used in conjunction with detached to avoid keeping the parent's stdio open. | ||
}); | ||
child.unref(); | ||
process.exit(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters