@@ -6,24 +6,19 @@ const { exec, spawn } = require("child_process");
6
6
const axios = require ( "axios" ) ;
7
7
const {
8
8
releaseUrl,
9
- enginePath,
10
9
getEngineVersion,
11
10
getFrontendVersion,
12
11
appPath,
13
12
backendPath,
14
- frontendPath,
15
13
updateBackupsFolder,
16
14
scanResultsPath,
17
15
phZipPath,
18
- createPlaywrightContext,
19
- deleteClonedProfiles,
20
- artifactInstallerPath,
21
16
resultsPath,
22
17
frontendReleaseUrl,
23
18
installerExePath,
19
+ macOSExecutablePath,
24
20
} = require ( "./constants" ) ;
25
21
const { silentLogger } = require ( "./logs" ) ;
26
- const { readUserDataFromFile } = require ( "./userDataManager" ) ;
27
22
28
23
let currentChildProcess ;
29
24
@@ -148,7 +143,6 @@ const isLatestFrontendVersion = async () => {
148
143
149
144
const latestVersion = data . tag_name ;
150
145
const frontendVersion = getFrontendVersion ( ) ;
151
-
152
146
console . log ( "Frontend version installed: " , frontendVersion ) ;
153
147
console . log ( "Latest frontend version found: " , latestVersion ) ;
154
148
@@ -161,6 +155,10 @@ const isLatestFrontendVersion = async () => {
161
155
}
162
156
} ;
163
157
158
+ /**
159
+ * Spawns a PowerShell process to download and unzip the frontend
160
+ * @returns {Promise<boolean> } true if the frontend was downloaded and unzipped successfully, false otherwise
161
+ */
164
162
const downloadAndUnzipFrontendWindows = async ( ) => {
165
163
const shellScript = `
166
164
$webClient = New-Object System.Net.WebClient
@@ -208,6 +206,32 @@ const downloadAndUnzipFrontendWindows = async () => {
208
206
} ) ;
209
207
} ;
210
208
209
+ /**
210
+ * Spawns a Shell Command process to download and unzip the frontend
211
+ */
212
+ const downloadAndUnzipFrontendMac = async ( ) => {
213
+ const command = `
214
+ curl -L '${ frontendReleaseUrl } ' -o '${ resultsPath } /purple-hats-desktop-mac.zip' &&
215
+ mv '${ macOSExecutablePath } ' '${ path . join (
216
+ macOSExecutablePath ,
217
+ ".."
218
+ ) } /Purple Hats Old.app' &&
219
+ ditto -xk '${ resultsPath } /purple-hats-desktop-mac.zip' '${ path . join (
220
+ macOSExecutablePath ,
221
+ ".."
222
+ ) } ' &&
223
+ rm '${ resultsPath } /purple-hats-desktop-mac.zip' &&
224
+ rm -rf '${ path . join ( macOSExecutablePath , ".." ) } /Purple Hats Old.app' &&
225
+ find '${ macOSExecutablePath } ' -exec xattr -d com.apple.quarantine {} \\` ;
226
+
227
+ await execCommand ( command ) ;
228
+ } ;
229
+
230
+ /**
231
+ * Spawn a PowerShell process to launch the InnoSetup installer executable, which contains the frontend and backend
232
+ * upon confirmation from the user, the installer will be launched & Electron will exit
233
+ * @returns {Promise<boolean> } true if the installer executable was launched successfully, false otherwise
234
+ */
211
235
const spawnScriptToLaunchInstaller = ( ) => {
212
236
const shellScript = `Start-Process -FilePath "${ installerExePath } "` ;
213
237
@@ -345,6 +369,29 @@ const run = async (updaterEventEmitter) => {
345
369
}
346
370
}
347
371
} else {
372
+ if ( ! ( await isLatestFrontendVersion ( ) ) ) {
373
+ updaterEventEmitter . emit ( "checking" ) ;
374
+ const userResponse = new Promise ( ( resolve ) => {
375
+ updaterEventEmitter . emit ( "promptFrontendUpdate" , resolve ) ;
376
+ } ) ;
377
+
378
+ const proceedUpdate = await userResponse ;
379
+
380
+ if ( proceedUpdate ) {
381
+ updaterEventEmitter . emit ( "updatingFrontend" ) ;
382
+
383
+ // Relaunch the app with new binaries if the frontend update is successful
384
+ // If unsuccessful, the app will be launched with existing frontend
385
+ try {
386
+ await downloadAndUnzipFrontendMac ( ) ;
387
+ currentChildProcess = null ;
388
+ updaterEventEmitter . emit ( "restartTriggered" ) ;
389
+ } catch ( e ) {
390
+ silentLogger . error ( e . toString ( ) ) ;
391
+ }
392
+ }
393
+ }
394
+
348
395
if ( isInterruptedUpdate ) {
349
396
updaterEventEmitter . emit ( "updatingBackend" ) ;
350
397
if ( ! backendExists ) {
0 commit comments