Skip to content

Commit 0c280b5

Browse files
committed
feat: mac app autoupdate initial
1 parent f388424 commit 0c280b5

File tree

1 file changed

+47
-1
lines changed
  • src/extensionsIntegrated/appUpdater

1 file changed

+47
-1
lines changed

src/extensionsIntegrated/appUpdater/main.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
*/
2020

21-
/*global logger*/
21+
/*global logger, path*/
2222

2323
// this file uses tauri APIs directly and is probably the only place where tauri apis are used outside of the
2424
// 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) {
317317
}
318318
}
319319

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+
320362
let installerLocation;
321363
async function quitTimeAppUpdateHandler() {
322364
if(!installerLocation){
@@ -355,6 +397,10 @@ define(function (require, exports, module) {
355397
launchLinuxUpdater()
356398
.then(resolve)
357399
.catch(failUpdateDialogAndExit);
400+
} else if (brackets.platform === "mac") {
401+
doMacUpdate()
402+
.then(resolve)
403+
.catch(failUpdateDialogAndExit);
358404
} else {
359405
resolve();
360406
}

0 commit comments

Comments
 (0)