mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 13:18:06 -06:00
Migrate away from deprecated methods for setting the standard application on macOS
The methods for checking if qBittorrent is set as the standard application for opening torrent files and magnet links and setting qBittorrent as the standard application for those is using deprecated methods now. For example `LSCopyDefaultHandlerForURLScheme` and `kUTTagClassFilenameExtension`. The new methods have been moved to `macutilities.mm` because in `os.cpp` cocoa couldn't be imported. PR #23059.
This commit is contained in:
@@ -44,6 +44,11 @@ namespace MacUtils
|
||||
void displayNotification(const QString &title, const QString &message);
|
||||
void openFiles(const PathList &pathList);
|
||||
|
||||
bool isMagnetLinkAssocSet();
|
||||
void setMagnetLinkAssoc();
|
||||
bool isTorrentFileAssocSet();
|
||||
void setTorrentFileAssoc();
|
||||
|
||||
QString badgeLabelText();
|
||||
void setBadgeLabelText(const QString &text);
|
||||
}
|
||||
|
||||
@@ -143,6 +143,46 @@ namespace MacUtils
|
||||
}
|
||||
}
|
||||
|
||||
bool isMagnetLinkAssocSet()
|
||||
{
|
||||
@autoreleasepool
|
||||
{
|
||||
const NSURL *magnetStandardURL = [[NSWorkspace sharedWorkspace] URLForApplicationToOpenURL:[NSURL URLWithString:@"magnet:"]];
|
||||
const NSURL *qbtURL = [[NSBundle mainBundle] bundleURL];
|
||||
return [magnetStandardURL isEqual:qbtURL];
|
||||
}
|
||||
}
|
||||
|
||||
void setMagnetLinkAssoc()
|
||||
{
|
||||
@autoreleasepool
|
||||
{
|
||||
[[NSWorkspace sharedWorkspace] setDefaultApplicationAtURL:[[NSBundle mainBundle] bundleURL]
|
||||
toOpenURLsWithScheme:@"magnet" completionHandler:nil];
|
||||
}
|
||||
}
|
||||
|
||||
bool isTorrentFileAssocSet()
|
||||
{
|
||||
@autoreleasepool
|
||||
{
|
||||
const NSURL *torrentStandardURL = [[NSWorkspace sharedWorkspace]
|
||||
URLForApplicationToOpenContentType:[UTType typeWithFilenameExtension:@"torrent"]];
|
||||
const NSURL *qbtURL = [[NSBundle mainBundle] bundleURL];
|
||||
return [torrentStandardURL isEqual:qbtURL];
|
||||
}
|
||||
}
|
||||
|
||||
void setTorrentFileAssoc()
|
||||
{
|
||||
@autoreleasepool
|
||||
{
|
||||
[[NSWorkspace sharedWorkspace] setDefaultApplicationAtURL:[[NSBundle mainBundle] bundleURL]
|
||||
toOpenContentType:[UTType typeWithFilenameExtension:@"torrent"]
|
||||
completionHandler:nil];
|
||||
}
|
||||
}
|
||||
|
||||
QString badgeLabelText()
|
||||
{
|
||||
return QString::fromNSString(NSApp.dockTile.badgeLabel);
|
||||
|
||||
@@ -88,9 +88,9 @@
|
||||
#include "base/net/dnsupdater.h"
|
||||
#endif
|
||||
|
||||
#if defined Q_OS_MACOS || defined Q_OS_WIN
|
||||
#include "base/utils/os.h"
|
||||
#endif // defined Q_OS_MACOS || defined Q_OS_WIN
|
||||
#ifdef Q_OS_MACOS
|
||||
#include "macutilities.h"
|
||||
#endif
|
||||
|
||||
#define SETTINGS_KEY(name) u"OptionsDialog/" name
|
||||
|
||||
@@ -329,9 +329,9 @@ void OptionsDialog::loadBehaviorTabOptions()
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
m_ui->checkShowSystray->setVisible(false);
|
||||
m_ui->checkAssociateTorrents->setChecked(Utils::OS::isTorrentFileAssocSet());
|
||||
m_ui->checkAssociateTorrents->setChecked(MacUtils::isTorrentFileAssocSet());
|
||||
m_ui->checkAssociateTorrents->setEnabled(!m_ui->checkAssociateTorrents->isChecked());
|
||||
m_ui->checkAssociateMagnetLinks->setChecked(Utils::OS::isMagnetLinkAssocSet());
|
||||
m_ui->checkAssociateMagnetLinks->setChecked(MacUtils::isMagnetLinkAssocSet());
|
||||
m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked());
|
||||
#endif
|
||||
|
||||
@@ -517,14 +517,14 @@ void OptionsDialog::saveBehaviorTabOptions() const
|
||||
#ifdef Q_OS_MACOS
|
||||
if (m_ui->checkAssociateTorrents->isChecked())
|
||||
{
|
||||
Utils::OS::setTorrentFileAssoc();
|
||||
m_ui->checkAssociateTorrents->setChecked(Utils::OS::isTorrentFileAssocSet());
|
||||
MacUtils::setTorrentFileAssoc();
|
||||
m_ui->checkAssociateTorrents->setChecked(MacUtils::isTorrentFileAssocSet());
|
||||
m_ui->checkAssociateTorrents->setEnabled(!m_ui->checkAssociateTorrents->isChecked());
|
||||
}
|
||||
if (m_ui->checkAssociateMagnetLinks->isChecked())
|
||||
{
|
||||
Utils::OS::setMagnetLinkAssoc();
|
||||
m_ui->checkAssociateMagnetLinks->setChecked(Utils::OS::isMagnetLinkAssocSet());
|
||||
MacUtils::setMagnetLinkAssoc();
|
||||
m_ui->checkAssociateMagnetLinks->setChecked(MacUtils::isMagnetLinkAssocSet());
|
||||
m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked());
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user