From 664c7ffb212eb898ed03f7b19c883400fa027b6b Mon Sep 17 00:00:00 2001 From: Juha Vuolle Date: Tue, 30 Apr 2024 11:19:23 +0300 Subject: [PATCH] macOS: Add support for custom uri scheme handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With this support applications can claim to be handler for specific custom scheme URLs such as "com.my.app" This requires that the scheme is listed in the plist file (CFBundleURLTypes and CFBundleURLSchemes). One notable usage example is the use of OAuth redirect_uris. [ChangeLog][macOS] Added support for custom uri scheme handling Task-number: QTBUG-124340 Change-Id: Ia04e9b89b53ee6f24129f9dd5ee8fbc5c0f0516c Reviewed-by: Tor Arne Vestbø --- .../platforms/cocoa/qcocoaapplicationdelegate.mm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index 10be0fe658..d642115926 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -359,13 +359,25 @@ QT_USE_NAMESPACE - (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent { Q_UNUSED(replyEvent); + NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; + const QString qurlString = QString::fromNSString(urlString); + + if (event.eventClass == kInternetEventClass && event.eventID == kAEGetURL) { + // 'GURL' (Get URL) event this application should handle + if (!QGuiApplication::instance()) + return; + QCocoaIntegration *cocoaIntegration = QCocoaIntegration::instance(); + Q_ASSERT(cocoaIntegration); + cocoaIntegration->services()->handleUrl(QUrl(qurlString)); + return; + } + // The string we get from the requesting application might not necessarily meet // QUrl's requirement for a IDN-compliant host. So if we can't parse into a QUrl, // then we pass the string on to the application as the name of a file (and // QFileOpenEvent::file is not guaranteed to be the path to a local, open'able // file anyway). - const QString qurlString = QString::fromNSString(urlString); if (const QUrl url(qurlString); url.isValid()) QWindowSystemInterface::handleFileOpenEvent(url); else