V2 - Add universal link support for macOS (#4693)

* add universal link support

* add changelog

* add docs about universal links

---------

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
This commit is contained in:
Andrey Pshenkin 2025-12-10 05:14:23 +00:00 committed by GitHub
commit a0cb86ebff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 35 additions and 4 deletions

View file

@ -9,6 +9,7 @@
#import <Cocoa/Cocoa.h>
#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<id<NSUserActivityRestoring>> * _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;
}

View file

@ -3,7 +3,7 @@
#import <Cocoa/Cocoa.h>
extern void HandleCustomProtocol(char*);
extern void HandleOpenURL(char*);
@interface CustomProtocolSchemeHandler : NSObject
+ (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent;

View file

@ -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

View file

@ -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
}

View file

@ -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
<key>NSUserActivityTypes</key>
<array>
<string>NSUserActivityTypeBrowsingWeb</string>
</array>
```
And for entitlements.plist
```xml
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:myawesomeapp.com</string>
</array>
```
### Windows
On Windows Custom Protocol Schemes is supported only with NSIS installer. During installation, the installer will create a

View file

@ -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)