mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-21 16:07:23 -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:
@@ -193,72 +193,6 @@ void Utils::OS::shutdownComputer([[maybe_unused]] const ShutdownDialogAction &ac
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
namespace
|
||||
{
|
||||
const CFStringRef torrentExtension = CFSTR("torrent");
|
||||
const CFStringRef magnetUrlScheme = CFSTR("magnet");
|
||||
}
|
||||
|
||||
bool Utils::OS::isTorrentFileAssocSet()
|
||||
{
|
||||
bool isSet = false;
|
||||
const CFStringRef torrentId = ::UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, torrentExtension, NULL);
|
||||
if (torrentId != NULL)
|
||||
{
|
||||
const CFStringRef defaultHandlerId = ::LSCopyDefaultRoleHandlerForContentType(torrentId, kLSRolesViewer);
|
||||
if (defaultHandlerId != NULL)
|
||||
{
|
||||
const CFStringRef myBundleId = ::CFBundleGetIdentifier(::CFBundleGetMainBundle());
|
||||
if (myBundleId != NULL)
|
||||
isSet = ::CFStringCompare(myBundleId, defaultHandlerId, 0) == kCFCompareEqualTo;
|
||||
::CFRelease(defaultHandlerId);
|
||||
}
|
||||
::CFRelease(torrentId);
|
||||
}
|
||||
return isSet;
|
||||
}
|
||||
|
||||
void Utils::OS::setTorrentFileAssoc()
|
||||
{
|
||||
if (isTorrentFileAssocSet())
|
||||
return;
|
||||
|
||||
const CFStringRef torrentId = ::UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, torrentExtension, NULL);
|
||||
if (torrentId != NULL)
|
||||
{
|
||||
const CFStringRef myBundleId = ::CFBundleGetIdentifier(::CFBundleGetMainBundle());
|
||||
if (myBundleId != NULL)
|
||||
::LSSetDefaultRoleHandlerForContentType(torrentId, kLSRolesViewer, myBundleId);
|
||||
::CFRelease(torrentId);
|
||||
}
|
||||
}
|
||||
|
||||
bool Utils::OS::isMagnetLinkAssocSet()
|
||||
{
|
||||
bool isSet = false;
|
||||
const CFStringRef defaultHandlerId = ::LSCopyDefaultHandlerForURLScheme(magnetUrlScheme);
|
||||
if (defaultHandlerId != NULL)
|
||||
{
|
||||
const CFStringRef myBundleId = ::CFBundleGetIdentifier(::CFBundleGetMainBundle());
|
||||
if (myBundleId != NULL)
|
||||
isSet = ::CFStringCompare(myBundleId, defaultHandlerId, 0) == kCFCompareEqualTo;
|
||||
::CFRelease(defaultHandlerId);
|
||||
}
|
||||
return isSet;
|
||||
}
|
||||
|
||||
void Utils::OS::setMagnetLinkAssoc()
|
||||
{
|
||||
if (isMagnetLinkAssocSet())
|
||||
return;
|
||||
|
||||
const CFStringRef myBundleId = ::CFBundleGetIdentifier(::CFBundleGetMainBundle());
|
||||
if (myBundleId != NULL)
|
||||
::LSSetDefaultHandlerForURLScheme(magnetUrlScheme, myBundleId);
|
||||
}
|
||||
#endif // Q_OS_MACOS
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
Path Utils::OS::windowsSystemPath()
|
||||
{
|
||||
|
||||
@@ -48,13 +48,6 @@ namespace Utils::OS
|
||||
{
|
||||
void shutdownComputer(const ShutdownDialogAction &action);
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
bool isTorrentFileAssocSet();
|
||||
void setTorrentFileAssoc();
|
||||
bool isMagnetLinkAssocSet();
|
||||
void setMagnetLinkAssoc();
|
||||
#endif // Q_OS_MACOS
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
Path windowsSystemPath();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user