Skip to content

Commit 88e048c

Browse files
authored
removed processessToRun and enhanced download backend (#85)
removed processessToRun and enhanced download backend
1 parent 8ea9968 commit 88e048c

File tree

1 file changed

+18
-32
lines changed

1 file changed

+18
-32
lines changed

public/electron/updateManager.js

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const {
77
getFrontendVersion,
88
appPath,
99
backendPath,
10-
phZipPath,
1110
resultsPath,
1211
frontendReleaseUrl,
1312
installerExePath,
@@ -80,9 +79,7 @@ const unzipBackendAndCleanUp = async (zipPath) => {
8079
'./a11y_shell.sh' echo "Initialise"
8180
`;
8281

83-
return async () => {
84-
await execCommand(unzipCommand);
85-
};
82+
return execCommand(unzipCommand);
8683
};
8784

8885
const getLatestFrontendVersion = (latestRelease, latestPreRelease) => {
@@ -272,11 +269,11 @@ const downloadAndUnzipBackendWindows = async (tag = undefined) => {
272269
});
273270
};
274271

275-
const downloadBackend = async (tag = undefined) => {
272+
const downloadBackend = async (tag, zipPath) => {
276273
const downloadUrl = `https://github.com/GovTechSG/purple-a11y/releases/download/${tag}/purple-a11y-portable-mac.zip`;
277-
const command = `curl '${downloadUrl}' -o '${phZipPath}' -L && rm -rf '${backendPath}' && mkdir '${backendPath}'`;
274+
const command = `curl '${downloadUrl}' -o '${zipPath}' -L && rm -rf '${backendPath}' && mkdir '${backendPath}'`;
278275

279-
return async () => await execCommand(command);
276+
return execCommand(command);
280277
};
281278

282279
// MacOS only
@@ -295,11 +292,9 @@ const validateZipFile = async (zipPath) => {
295292
return fs.existsSync(zipPath) && (await isZipValid(zipPath));
296293
};
297294

298-
const hashAndSaveZip = (zipPath) => {
299-
return async () => {
300-
const currHash = await hashPrepackage(zipPath);
301-
fs.writeFileSync(hashPath, currHash);
302-
};
295+
const hashAndSaveZip = async (zipPath) => {
296+
const currHash = await hashPrepackage(zipPath);
297+
fs.writeFileSync(hashPath, currHash);
303298
};
304299

305300
const run = async (updaterEventEmitter, latestRelease, latestPreRelease) => {
@@ -370,7 +365,6 @@ const run = async (updaterEventEmitter, latestRelease, latestPreRelease) => {
370365
await downloadAndUnzipBackendWindows(getFrontendVersion());
371366
}
372367
} else {
373-
const processesToRun = [];
374368
let restartRequired = false;
375369
consoleLogger.info("mac detected");
376370
// user is on mac
@@ -410,32 +404,24 @@ const run = async (updaterEventEmitter, latestRelease, latestPreRelease) => {
410404

411405
if (!skipUnzip) {
412406
// expected to reach here when restart triggered on update
413-
processesToRun.push(
414-
() => consoleLogger.info("proceeding to unzip backend prepackage"),
415-
() => updaterEventEmitter.emit("settingUp"),
416-
await unzipBackendAndCleanUp(macOSPrepackageBackend),
417-
hashAndSaveZip(macOSPrepackageBackend)
418-
);
407+
consoleLogger.info("proceeding to unzip backend prepackage");
408+
updaterEventEmitter.emit("settingUp");
409+
await unzipBackendAndCleanUp(macOSPrepackageBackend);
410+
await hashAndSaveZip(macOSPrepackageBackend);
419411
}
420412
} else {
421413
// unlikely scenario
422-
processesToRun.push(
423-
() =>
424-
consoleLogger.info(
425-
"prepackage zip is invalid. proceed to download from backend. check the prepackage manually."
426-
),
427-
await downloadBackend(getFrontendVersion()),
428-
await unzipBackendAndCleanUp(phZipPath),
429-
hashAndSaveZip(phZipPath)
414+
consoleLogger.info(
415+
"prepackage zip is invalid. proceed to download from backend."
430416
);
417+
await downloadBackend(getFrontendVersion(), macOSPrepackageBackend);
418+
await unzipBackendAndCleanUp(macOSPrepackageBackend);
419+
await hashAndSaveZip(macOSPrepackageBackend);
431420
}
432421

433422
if (restartRequired) {
434-
processesToRun.push(() => updaterEventEmitter.emit("restartTriggered"));
435-
}
436-
437-
for (const proc of processesToRun) {
438-
await proc();
423+
consoleLogger.info("restarting app...");
424+
updaterEventEmitter.emit("restartTriggered");
439425
}
440426
}
441427
};

0 commit comments

Comments
 (0)