|
1 | 1 | const fs = require('fs'); |
2 | 2 | const path = require('path'); |
3 | | -const { exec } = require('child_process'); |
| 3 | +const { spawn } = require('child_process'); |
4 | 4 |
|
5 | 5 | const args = process.argv.slice(2); // Skip the first two elements |
6 | 6 | 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 | | -} |
40 | 7 |
|
41 | 8 | if(!appdataDir) { |
42 | 9 | process.exit(1); |
43 | 10 | } |
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); |
50 | 19 | 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); |
0 commit comments