From a0cb86ebff19f8a050e1b3c94682e7c511e172a0 Mon Sep 17 00:00:00 2001 From: Andrey Pshenkin Date: Wed, 10 Dec 2025 05:14:23 +0000 Subject: [PATCH] V2 - Add universal link support for macOS (#4693) * add universal link support * add changelog * add docs about universal links --------- Co-authored-by: Lea Anthony --- .../frontend/desktop/darwin/AppDelegate.m | 12 ++++++++++++ .../frontend/desktop/darwin/CustomProtocol.h | 2 +- .../frontend/desktop/darwin/CustomProtocol.m | 2 +- .../frontend/desktop/darwin/frontend.go | 4 ++-- .../docs/guides/custom-protocol-schemes.mdx | 18 ++++++++++++++++++ website/src/pages/changelog.mdx | 1 + 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/v2/internal/frontend/desktop/darwin/AppDelegate.m b/v2/internal/frontend/desktop/darwin/AppDelegate.m index 318c333d8..a73ec3ec3 100644 --- a/v2/internal/frontend/desktop/darwin/AppDelegate.m +++ b/v2/internal/frontend/desktop/darwin/AppDelegate.m @@ -9,6 +9,7 @@ #import #import "AppDelegate.h" +#import "CustomProtocol.h" #import "message.h" @implementation AppDelegate @@ -19,6 +20,17 @@ return YES; } +- (BOOL)application:(NSApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray> * _Nullable))restorationHandler { + if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) { + NSURL *url = userActivity.webpageURL; + if (url) { + HandleOpenURL((char*)[[url absoluteString] UTF8String]); + return YES; + } + } + return NO; +} + - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { return NO; } diff --git a/v2/internal/frontend/desktop/darwin/CustomProtocol.h b/v2/internal/frontend/desktop/darwin/CustomProtocol.h index da0e7079f..0698a4d45 100644 --- a/v2/internal/frontend/desktop/darwin/CustomProtocol.h +++ b/v2/internal/frontend/desktop/darwin/CustomProtocol.h @@ -3,7 +3,7 @@ #import -extern void HandleCustomProtocol(char*); +extern void HandleOpenURL(char*); @interface CustomProtocolSchemeHandler : NSObject + (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent; diff --git a/v2/internal/frontend/desktop/darwin/CustomProtocol.m b/v2/internal/frontend/desktop/darwin/CustomProtocol.m index 7365e4f50..ebc61aa00 100644 --- a/v2/internal/frontend/desktop/darwin/CustomProtocol.m +++ b/v2/internal/frontend/desktop/darwin/CustomProtocol.m @@ -6,7 +6,7 @@ NSString *urlStr = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; - HandleCustomProtocol((char*)[[[event paramDescriptorForKeyword:keyDirectObject] stringValue] UTF8String]); + HandleOpenURL((char*)[[[event paramDescriptorForKeyword:keyDirectObject] stringValue] UTF8String]); } @end diff --git a/v2/internal/frontend/desktop/darwin/frontend.go b/v2/internal/frontend/desktop/darwin/frontend.go index c9e70d4be..6566445d5 100644 --- a/v2/internal/frontend/desktop/darwin/frontend.go +++ b/v2/internal/frontend/desktop/darwin/frontend.go @@ -518,8 +518,8 @@ func HandleOpenFile(filePath *C.char) { openFilepathBuffer <- goFilepath } -//export HandleCustomProtocol -func HandleCustomProtocol(url *C.char) { +//export HandleOpenURL +func HandleOpenURL(url *C.char) { goUrl := C.GoString(url) openUrlBuffer <- goUrl } diff --git a/website/docs/guides/custom-protocol-schemes.mdx b/website/docs/guides/custom-protocol-schemes.mdx index c56634f0e..216fb7100 100644 --- a/website/docs/guides/custom-protocol-schemes.mdx +++ b/website/docs/guides/custom-protocol-schemes.mdx @@ -59,6 +59,24 @@ func main() { } ``` +If you want to handle universal links as well, follow this [guide](https://developer.apple.com/documentation/xcode/supporting-universal-links-in-your-app) to add required entitlements, add required keys to Info.plist and configure `apple-app-site-association` on your website. + +Here is example for Info.plist: +```xml +NSUserActivityTypes + + NSUserActivityTypeBrowsingWeb + +``` + +And for entitlements.plist +```xml +com.apple.developer.associated-domains + + applinks:myawesomeapp.com + +``` + ### Windows On Windows Custom Protocol Schemes is supported only with NSIS installer. During installation, the installer will create a diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index 271f24a87..fba54f570 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `ContentProtection` option to allow hiding the application window from screen sharing software [#4241](https://github.com/wailsapp/wails/pull/4241) by [@Taiterbase](https://github.com/Taiterbase) - Added `build:tags` to project specification for automatically adding compilation tags by @symball in [PR](https://github.com/wailsapp/wails/pull/4439) - Support for binding generics in [PR](https://github.dev/wailsapp/wails/pull/3626) by @ktsivkov +- Add universal link support for macOS by @APshenkin in [PR](https://github.com/wailsapp/wails/pull/4693) ### Fixed - Added url validation for BrowserOpenURL by @APshenkin in [PR](https://github.com/wailsapp/wails/pull/4484)