|
54 | 54 | #include <QUrlQuery> |
55 | 55 |
|
56 | 56 | #if defined(Q_OS_MAC) |
57 | | -#pragma GCC diagnostic push |
58 | | -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
59 | 57 |
|
60 | | -#include <CoreServices/CoreServices.h> |
61 | 58 | #include <QProcess> |
62 | 59 |
|
63 | 60 | void ForceActivation(); |
@@ -691,87 +688,6 @@ bool SetStartOnSystemStartup(bool fAutoStart) |
691 | 688 | return true; |
692 | 689 | } |
693 | 690 |
|
694 | | - |
695 | | -#elif defined(Q_OS_MAC) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED <= 101100 |
696 | | -// based on: https://github.com/Mozketo/LaunchAtLoginController/blob/master/LaunchAtLoginController.m |
697 | | - |
698 | | -LSSharedFileListItemRef findStartupItemInList(CFArrayRef listSnapshot, LSSharedFileListRef list, CFURLRef findUrl) |
699 | | -{ |
700 | | - if (listSnapshot == nullptr) { |
701 | | - return nullptr; |
702 | | - } |
703 | | - |
704 | | - // loop through the list of startup items and try to find the bitcoin app |
705 | | - for(int i = 0; i < CFArrayGetCount(listSnapshot); i++) { |
706 | | - LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(listSnapshot, i); |
707 | | - UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes; |
708 | | - CFURLRef currentItemURL = nullptr; |
709 | | - |
710 | | -#if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= 10100 |
711 | | - if(&LSSharedFileListItemCopyResolvedURL) |
712 | | - currentItemURL = LSSharedFileListItemCopyResolvedURL(item, resolutionFlags, nullptr); |
713 | | -#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED < 10100 |
714 | | - else |
715 | | - LSSharedFileListItemResolve(item, resolutionFlags, ¤tItemURL, nullptr); |
716 | | -#endif |
717 | | -#else |
718 | | - LSSharedFileListItemResolve(item, resolutionFlags, ¤tItemURL, nullptr); |
719 | | -#endif |
720 | | - |
721 | | - if(currentItemURL) { |
722 | | - if (CFEqual(currentItemURL, findUrl)) { |
723 | | - // found |
724 | | - CFRelease(currentItemURL); |
725 | | - return item; |
726 | | - } |
727 | | - CFRelease(currentItemURL); |
728 | | - } |
729 | | - } |
730 | | - return nullptr; |
731 | | -} |
732 | | - |
733 | | -bool GetStartOnSystemStartup() |
734 | | -{ |
735 | | - CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle()); |
736 | | - if (bitcoinAppUrl == nullptr) { |
737 | | - return false; |
738 | | - } |
739 | | - |
740 | | - LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr); |
741 | | - CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(loginItems, nullptr); |
742 | | - bool res = (findStartupItemInList(listSnapshot, loginItems, bitcoinAppUrl) != nullptr); |
743 | | - CFRelease(bitcoinAppUrl); |
744 | | - CFRelease(loginItems); |
745 | | - CFRelease(listSnapshot); |
746 | | - return res; |
747 | | -} |
748 | | - |
749 | | -bool SetStartOnSystemStartup(bool fAutoStart) |
750 | | -{ |
751 | | - CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle()); |
752 | | - if (bitcoinAppUrl == nullptr) { |
753 | | - return false; |
754 | | - } |
755 | | - |
756 | | - LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr); |
757 | | - CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(loginItems, nullptr); |
758 | | - LSSharedFileListItemRef foundItem = findStartupItemInList(listSnapshot, loginItems, bitcoinAppUrl); |
759 | | - |
760 | | - if(fAutoStart && !foundItem) { |
761 | | - // add bitcoin app to startup item list |
762 | | - LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst, nullptr, nullptr, bitcoinAppUrl, nullptr, nullptr); |
763 | | - } |
764 | | - else if(!fAutoStart && foundItem) { |
765 | | - // remove item |
766 | | - LSSharedFileListItemRemove(loginItems, foundItem); |
767 | | - } |
768 | | - |
769 | | - CFRelease(bitcoinAppUrl); |
770 | | - CFRelease(loginItems); |
771 | | - CFRelease(listSnapshot); |
772 | | - return true; |
773 | | -} |
774 | | -#pragma GCC diagnostic pop |
775 | 691 | #else |
776 | 692 |
|
777 | 693 | bool GetStartOnSystemStartup() { return false; } |
|
0 commit comments