From 7d3ceb7d8cd3aa173e1637f9bb244ae394aba401 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sun, 11 Apr 2021 18:33:35 +0200 Subject: [PATCH] Fix Tidal authentication on macOS --- src/core/commandlineoptions.cpp | 2 +- src/core/mac_startup.mm | 10 ++++++++++ src/core/mainwindow.cpp | 22 ++++++++++++++++------ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/core/commandlineoptions.cpp b/src/core/commandlineoptions.cpp index b0950811e..beb722407 100644 --- a/src/core/commandlineoptions.cpp +++ b/src/core/commandlineoptions.cpp @@ -78,7 +78,7 @@ const char *CommandlineOptions::kHelpText = const char *CommandlineOptions::kVersionText = "Strawberry %1"; -CommandlineOptions::CommandlineOptions(int argc, char* *argv) +CommandlineOptions::CommandlineOptions(int argc, char **argv) : argc_(argc), argv_(argv), url_list_action_(UrlList_None), diff --git a/src/core/mac_startup.mm b/src/core/mac_startup.mm index 4961fd3f0..2d28d1b5e 100644 --- a/src/core/mac_startup.mm +++ b/src/core/mac_startup.mm @@ -148,8 +148,11 @@ QDebug operator<<(QDebug dbg, NSObject* object) { } - (void)applicationDidFinishLaunching:(NSNotification*)aNotification { + Q_UNUSED(aNotification); + [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(handleURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; + key_tap_ = [ [SPMediaKeyTap alloc] initWithDelegate:self]; if ([SPMediaKeyTap usesGlobalMediaKeyTap]) { if ([key_tap_ startWatchingMediaKeys]) { @@ -187,6 +190,13 @@ QDebug operator<<(QDebug dbg, NSObject* object) { } +- (void)handleURLEvent:(NSAppleEventDescriptor*)theEvent withReplyEvent:(NSAppleEventDescriptor*)replyEvent { + + NSString *url = [[theEvent paramDescriptorForKeyword:keyDirectObject] stringValue]; + application_handler_->LoadUrl(QString::fromNSString(url)); + +} + - (void) mediaKeyTap: (SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event { #pragma unused(keyTap) [self handleMediaEvent:event]; diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index 7854c9e0f..67de53064 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -2391,13 +2391,23 @@ void MainWindow::Activate() { bool MainWindow::LoadUrl(const QString &url) { - if (!QFile::exists(url)) return false; + if (QFile::exists(url)) { + MimeData *mimedata = new MimeData; + mimedata->setUrls(QList() << QUrl::fromLocalFile(url)); + AddToPlaylist(mimedata); + return true; + } +#ifdef HAVE_TIDAL + else if (url.startsWith("tidal://login")) { + emit AuthorizationUrlReceived(QUrl(url)); + return true; + } +#endif + else { + qLog(Error) << "Can't open" << url; + } - MimeData *mimedata = new MimeData; - mimedata->setUrls(QList() << QUrl::fromLocalFile(url)); - AddToPlaylist(mimedata); - - return true; + return false; }