Skip to content

Commit 7822f2c

Browse files
committed
Use MacOS openApplicationAtURL syscall to re-run updated app
1 parent 33631c4 commit 7822f2c

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_macos.go

+28-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@
1717

1818
package updater
1919

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

129152
// Restart agent
130-
newExecutable := currentAppPath.Join("Contents", "MacOS", "Arduino_Create_Agent")
131-
logrus.WithField("path", newExecutable).Info("Running new app")
132-
return newExecutable.String(), nil
153+
logrus.WithField("path", currentAppPath).Info("Running new app")
154+
C.runApplication(C.CString(currentAppPath.String()))
155+
156+
// Close old agent
157+
return "quit", nil
133158
}

0 commit comments

Comments
 (0)