Skip to content

Commit

Permalink
Support for universal links
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany authored May 30, 2024
2 parents bab0910 + 515546f commit 8265cd4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ func main() {
now := time.Now()
fmt.Println("Exit at", now.String())
}
input := make(chan string, 1)

systray.Run(onReady, onExit, func(b bool) {})
systray.Run(onReady, onExit, func(b bool) {}, input)
}

func addQuitItem() {
Expand Down
7 changes: 5 additions & 2 deletions systray.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var (

currentID = uint32(0)
quitOnce sync.Once

urlInput chan string
)

// This helper function allows us to call systrayExit only once,
Expand Down Expand Up @@ -81,14 +83,15 @@ func newMenuItem(title string, tooltip string, parent *MenuItem) *MenuItem {

// Run initializes GUI and starts the event loop, then invokes the onReady
// callback. It blocks until systray.Quit() is called.
func Run(onReady, onExit func(), onAppearanceChanged func(bool)) {
func Run(onReady, onExit func(), onAppearanceChanged func(bool), input chan string) {
urlInput = input
setInternalLoop(true)
Register(onReady, onExit, onAppearanceChanged)

nativeLoop()
}

// RunWithExternalLoop allows the systemtray module to operate with other tookits.
// RunWithExternalLoop allows the systemtray module to operate with other toolkits.
// The returned start and end functions should be called by the toolkit when the application has started and will end.
func RunWithExternalLoop(onReady, onExit func(), onAppearanceChanged func(bool)) (start, end func()) {
Register(onReady, onExit, onAppearanceChanged)
Expand Down
1 change: 1 addition & 0 deletions systray.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern void systray_on_exit();
extern void systray_menu_opened();
extern void systray_menu_item_selected(int menu_id);
extern void systray_appearance_changed(bool dark);
extern void handleURL(char*);
void registerSystray(void);
void nativeEnd(void);
int nativeLoop(void);
Expand Down
5 changes: 5 additions & 0 deletions systray_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,8 @@ func systray_menu_opened() {
func systray_appearance_changed(dark C.bool) {
systrayAppearanceChanged(bool(dark))
}

//export handleURL
func handleURL(u *C.char) {
urlInput <- C.GoString(u)
}
11 changes: 11 additions & 0 deletions systray_darwin.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ @implementation AppDelegate

@synthesize window = _window;

- (BOOL)application:(NSApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<NSUserActivityRestoring>> *restorableObjects))restorationHandler {
if (![userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
return NO;
}

NSString *urlStr = [userActivity.webpageURL absoluteString];
handleURL((char *)[urlStr UTF8String]);

return YES;
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
self->statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
Expand Down

0 comments on commit 8265cd4

Please sign in to comment.