@ -54,10 +54,7 @@
# include <QUrlQuery>
# if defined(Q_OS_MAC)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
# include <CoreServices/CoreServices.h>
# include <QProcess>
void ForceActivation ( ) ;
@ -691,87 +688,6 @@ bool SetStartOnSystemStartup(bool fAutoStart)
return true ;
}
# elif defined(Q_OS_MAC) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED <= 101100
// based on: https://github.com/Mozketo/LaunchAtLoginController/blob/master/LaunchAtLoginController.m
LSSharedFileListItemRef findStartupItemInList ( CFArrayRef listSnapshot , LSSharedFileListRef list , CFURLRef findUrl )
{
if ( listSnapshot = = nullptr ) {
return nullptr ;
}
// loop through the list of startup items and try to find the bitcoin app
for ( int i = 0 ; i < CFArrayGetCount ( listSnapshot ) ; i + + ) {
LSSharedFileListItemRef item = ( LSSharedFileListItemRef ) CFArrayGetValueAtIndex ( listSnapshot , i ) ;
UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes ;
CFURLRef currentItemURL = nullptr ;
# if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= 10100
if ( & LSSharedFileListItemCopyResolvedURL )
currentItemURL = LSSharedFileListItemCopyResolvedURL ( item , resolutionFlags , nullptr ) ;
# if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED < 10100
else
LSSharedFileListItemResolve ( item , resolutionFlags , & currentItemURL , nullptr ) ;
# endif
# else
LSSharedFileListItemResolve ( item , resolutionFlags , & currentItemURL , nullptr ) ;
# endif
if ( currentItemURL ) {
if ( CFEqual ( currentItemURL , findUrl ) ) {
// found
CFRelease ( currentItemURL ) ;
return item ;
}
CFRelease ( currentItemURL ) ;
}
}
return nullptr ;
}
bool GetStartOnSystemStartup ( )
{
CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL ( CFBundleGetMainBundle ( ) ) ;
if ( bitcoinAppUrl = = nullptr ) {
return false ;
}
LSSharedFileListRef loginItems = LSSharedFileListCreate ( nullptr , kLSSharedFileListSessionLoginItems , nullptr ) ;
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot ( loginItems , nullptr ) ;
bool res = ( findStartupItemInList ( listSnapshot , loginItems , bitcoinAppUrl ) ! = nullptr ) ;
CFRelease ( bitcoinAppUrl ) ;
CFRelease ( loginItems ) ;
CFRelease ( listSnapshot ) ;
return res ;
}
bool SetStartOnSystemStartup ( bool fAutoStart )
{
CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL ( CFBundleGetMainBundle ( ) ) ;
if ( bitcoinAppUrl = = nullptr ) {
return false ;
}
LSSharedFileListRef loginItems = LSSharedFileListCreate ( nullptr , kLSSharedFileListSessionLoginItems , nullptr ) ;
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot ( loginItems , nullptr ) ;
LSSharedFileListItemRef foundItem = findStartupItemInList ( listSnapshot , loginItems , bitcoinAppUrl ) ;
if ( fAutoStart & & ! foundItem ) {
// add bitcoin app to startup item list
LSSharedFileListInsertItemURL ( loginItems , kLSSharedFileListItemBeforeFirst , nullptr , nullptr , bitcoinAppUrl , nullptr , nullptr ) ;
}
else if ( ! fAutoStart & & foundItem ) {
// remove item
LSSharedFileListItemRemove ( loginItems , foundItem ) ;
}
CFRelease ( bitcoinAppUrl ) ;
CFRelease ( loginItems ) ;
CFRelease ( listSnapshot ) ;
return true ;
}
# pragma GCC diagnostic pop
# else
bool GetStartOnSystemStartup ( ) { return false ; }