|
18 | 18 | * |
19 | 19 | */ |
20 | 20 |
|
21 | | -/*global logger*/ |
| 21 | +/*global logger, path*/ |
22 | 22 |
|
23 | 23 | // this file uses tauri APIs directly and is probably the only place where tauri apis are used outside of the |
24 | 24 | // shell.js file. This is app updates are pretty core level even though we do it as an extension here. |
@@ -317,6 +317,48 @@ define(function (require, exports, module) { |
317 | 317 | } |
318 | 318 | } |
319 | 319 |
|
| 320 | + async function getCurrentMacAppPath() { |
| 321 | + const cliArgs = await window.__TAURI__.invoke('_get_commandline_args'); |
| 322 | + let fullPath = cliArgs[0]; // something like /Applications/editor.app/contents/.../Phoenix code |
| 323 | + const normalizedPath = path.normalize(fullPath); |
| 324 | + const parts = normalizedPath.split(path.sep); |
| 325 | + const appIndex = parts.findIndex(part => part.endsWith('.app')); |
| 326 | + |
| 327 | + // Reconstruct the path up to the .app part |
| 328 | + if (appIndex !== -1) { |
| 329 | + const appPathParts = parts.slice(0, appIndex + 1); |
| 330 | + return appPathParts.join(path.sep); // returns /Applications/editor.app |
| 331 | + } |
| 332 | + // .app part is found |
| 333 | + return null; |
| 334 | + } |
| 335 | + |
| 336 | + async function doMacUpdate() { |
| 337 | + const currentAppPath = await getCurrentMacAppPath(); |
| 338 | + if(!currentAppPath || !installerLocation || !currentAppPath.endsWith(".app") || |
| 339 | + !installerLocation.endsWith(".app")){ |
| 340 | + throw new Error("Cannot resolve .app location to copy."); |
| 341 | + } |
| 342 | + const removeCommand = new window.__TAURI__.shell |
| 343 | + .Command(`recursive-rm-unix`, ['-r', currentAppPath]); |
| 344 | + let result; |
| 345 | + try { |
| 346 | + result = removeCommand.execute(); |
| 347 | + if(result.code !== 0){ |
| 348 | + console.error("Could not remove old app", currentAppPath, "Trying to overwrite"); |
| 349 | + } |
| 350 | + } catch (e) { |
| 351 | + // we dont fail here, we will try to overwrite now. |
| 352 | + console.error("Could not remove old app", currentAppPath, "Trying to overwrite", e); |
| 353 | + } |
| 354 | + const copyCommand = new window.__TAURI__.shell |
| 355 | + .Command(`recursive-copy-unix`, ['-r', installerLocation, currentAppPath]); |
| 356 | + result = await copyCommand.execute(); |
| 357 | + if(result.code !== 0){ |
| 358 | + throw new Error("Update script exit with non-0 exit code: " + result.code); |
| 359 | + } |
| 360 | + } |
| 361 | + |
320 | 362 | let installerLocation; |
321 | 363 | async function quitTimeAppUpdateHandler() { |
322 | 364 | if(!installerLocation){ |
@@ -355,6 +397,10 @@ define(function (require, exports, module) { |
355 | 397 | launchLinuxUpdater() |
356 | 398 | .then(resolve) |
357 | 399 | .catch(failUpdateDialogAndExit); |
| 400 | + } else if (brackets.platform === "mac") { |
| 401 | + doMacUpdate() |
| 402 | + .then(resolve) |
| 403 | + .catch(failUpdateDialogAndExit); |
358 | 404 | } else { |
359 | 405 | resolve(); |
360 | 406 | } |
|
0 commit comments