Skip to content

Commit 803e4ca

Browse files
committed
Use MacOS openApplicationAtURL syscall to re-run updated app
1 parent 3d60bed commit 803e4ca

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

update.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,9 @@ func updateHandler(c *gin.Context) {
4141
return
4242
}
4343
c.JSON(200, gin.H{"success": "Please wait a moment while the agent reboots itself"})
44-
Systray.RestartWith(restartPath)
44+
if restartPath == "quit" {
45+
Systray.Quit()
46+
} else {
47+
Systray.RestartWith(restartPath)
48+
}
4549
}

updater/updater_darwin.go

+28-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@
1515

1616
package updater
1717

18+
/*
19+
#cgo CFLAGS: -x objective-c
20+
#cgo LDFLAGS: -framework Cocoa
21+
#import <Cocoa/Cocoa.h>
22+
23+
void runApplication(const char *path) {
24+
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
25+
NSURL *url = [NSURL fileURLWithPath:@(path) isDirectory:NO];
26+
27+
NSWorkspaceOpenConfiguration* configuration = [NSWorkspaceOpenConfiguration new];
28+
//[configuration setEnvironment:env];
29+
[configuration setPromptsUserIfNeeded:YES];
30+
[configuration setCreatesNewApplicationInstance:YES];
31+
32+
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
33+
[ws openApplicationAtURL:url configuration:configuration completionHandler:^(NSRunningApplication* app, NSError* error) {
34+
dispatch_semaphore_signal(semaphore);
35+
}];
36+
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
37+
}
38+
*/
39+
import "C"
40+
1841
import (
1942
"bytes"
2043
"context"
@@ -125,7 +148,9 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
125148
_ = oldAppPath.RemoveAll()
126149

127150
// Restart agent
128-
newExecutable := currentAppPath.Join("Contents", "MacOS", "Arduino_Create_Agent")
129-
logrus.WithField("path", newExecutable).Info("Running new app")
130-
return newExecutable.String(), nil
151+
logrus.WithField("path", currentAppPath).Info("Running new app")
152+
C.runApplication(C.CString(currentAppPath.String()))
153+
154+
// Close old agent
155+
return "quit", nil
131156
}

0 commit comments

Comments
 (0)