Skip to content

General enhancements to macOS ventura binary #741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use MacOS openApplicationAtURL syscall to re-run updated app
  • Loading branch information
cmaglie committed Feb 14, 2023
commit 803e4ca93f024fef611932142aa3f250d59a082c
6 changes: 5 additions & 1 deletion update.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ func updateHandler(c *gin.Context) {
return
}
c.JSON(200, gin.H{"success": "Please wait a moment while the agent reboots itself"})
Systray.RestartWith(restartPath)
if restartPath == "quit" {
Systray.Quit()
} else {
Systray.RestartWith(restartPath)
}
}
31 changes: 28 additions & 3 deletions updater/updater_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@

package updater

/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Cocoa
#import <Cocoa/Cocoa.h>

void runApplication(const char *path) {
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
NSURL *url = [NSURL fileURLWithPath:@(path) isDirectory:NO];

NSWorkspaceOpenConfiguration* configuration = [NSWorkspaceOpenConfiguration new];
//[configuration setEnvironment:env];
[configuration setPromptsUserIfNeeded:YES];
[configuration setCreatesNewApplicationInstance:YES];

dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[ws openApplicationAtURL:url configuration:configuration completionHandler:^(NSRunningApplication* app, NSError* error) {
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
}
*/
import "C"

import (
"bytes"
"context"
Expand Down Expand Up @@ -125,7 +148,9 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
_ = oldAppPath.RemoveAll()

// Restart agent
newExecutable := currentAppPath.Join("Contents", "MacOS", "Arduino_Create_Agent")
logrus.WithField("path", newExecutable).Info("Running new app")
return newExecutable.String(), nil
logrus.WithField("path", currentAppPath).Info("Running new app")
C.runApplication(C.CString(currentAppPath.String()))

// Close old agent
return "quit", nil
}