Changeset View
Changeset View
Standalone View
Standalone View
src/qt/guiutil.cpp
Show First 20 Lines • Show All 787 Lines • ▼ Show 20 Lines | |||||
// https://github.com/Mozketo/LaunchAtLoginController/blob/master/LaunchAtLoginController.m | // https://github.com/Mozketo/LaunchAtLoginController/blob/master/LaunchAtLoginController.m | ||||
// NB: caller must release returned ref if it's not NULL | // NB: caller must release returned ref if it's not NULL | ||||
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, | LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, | ||||
CFURLRef findUrl); | CFURLRef findUrl); | ||||
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, | LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, | ||||
CFURLRef findUrl) { | CFURLRef findUrl) { | ||||
LSSharedFileListItemRef foundItem = nullptr; | LSSharedFileListItemRef foundItem = nullptr; | ||||
// loop through the list of startup items and try to find the bitcoin app | |||||
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(list, nullptr); | CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(list, nullptr); | ||||
if (listSnapshot == nullptr) { | |||||
return nullptr; | |||||
} | |||||
// loop through the list of startup items and try to find the bitcoin app | |||||
for (int i = 0; !foundItem && i < CFArrayGetCount(listSnapshot); ++i) { | for (int i = 0; !foundItem && i < CFArrayGetCount(listSnapshot); ++i) { | ||||
LSSharedFileListItemRef item = | LSSharedFileListItemRef item = | ||||
(LSSharedFileListItemRef)CFArrayGetValueAtIndex(listSnapshot, i); | (LSSharedFileListItemRef)CFArrayGetValueAtIndex(listSnapshot, i); | ||||
UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | | UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | | ||||
kLSSharedFileListDoNotMountVolumes; | kLSSharedFileListDoNotMountVolumes; | ||||
CFURLRef currentItemURL = nullptr; | CFURLRef currentItemURL = nullptr; | ||||
#if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && \ | #if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && \ | ||||
Show All 9 Lines | MAC_OS_X_VERSION_MIN_REQUIRED < 10100 | ||||
nullptr); | nullptr); | ||||
} | } | ||||
#endif | #endif | ||||
#else | #else | ||||
LSSharedFileListItemResolve(item, resolutionFlags, ¤tItemURL, | LSSharedFileListItemResolve(item, resolutionFlags, ¤tItemURL, | ||||
nullptr); | nullptr); | ||||
#endif | #endif | ||||
if (currentItemURL && CFEqual(currentItemURL, findUrl)) { | if (currentItemURL) { | ||||
if (CFEqual(currentItemURL, findUrl)) { | |||||
// found | // found | ||||
CFRetain(foundItem = item); | CFRetain(foundItem = item); | ||||
deadalnix: Here this is retained. | |||||
CFRelease(listSnapshot); | |||||
CFRelease(currentItemURL); | |||||
return item; | |||||
} | } | ||||
if (currentItemURL) { | |||||
CFRelease(currentItemURL); | CFRelease(currentItemURL); | ||||
} | } | ||||
} | } | ||||
CFRelease(listSnapshot); | CFRelease(listSnapshot); | ||||
return foundItem; | return foundItem; | ||||
} | } | ||||
bool GetStartOnSystemStartup() { | bool GetStartOnSystemStartup() { | ||||
CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle()); | CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle()); | ||||
if (bitcoinAppUrl == nullptr) { | |||||
return false; | |||||
} | |||||
LSSharedFileListRef loginItems = LSSharedFileListCreate( | LSSharedFileListRef loginItems = LSSharedFileListCreate( | ||||
nullptr, kLSSharedFileListSessionLoginItems, nullptr); | nullptr, kLSSharedFileListSessionLoginItems, nullptr); | ||||
LSSharedFileListItemRef foundItem = | LSSharedFileListItemRef foundItem = | ||||
findStartupItemInList(loginItems, bitcoinAppUrl); | findStartupItemInList(loginItems, bitcoinAppUrl); | ||||
// findStartupItemInList retains the item it returned, need to release | // findStartupItemInList retains the item it returned, need to release | ||||
if (foundItem) { | if (foundItem) { | ||||
CFRelease(foundItem); | CFRelease(foundItem); | ||||
deadalnixUnsubmitted Not Done Inline ActionsTo be almost immediately freed in what appears to be the only callsite. deadalnix: To be almost immediately freed in what appears to be the only callsite. | |||||
} | } | ||||
CFRelease(loginItems); | CFRelease(loginItems); | ||||
CFRelease(bitcoinAppUrl); | CFRelease(bitcoinAppUrl); | ||||
return foundItem; | return foundItem; | ||||
} | } | ||||
bool SetStartOnSystemStartup(bool fAutoStart) { | bool SetStartOnSystemStartup(bool fAutoStart) { | ||||
CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle()); | CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle()); | ||||
if (bitcoinAppUrl == nullptr) { | |||||
return false; | |||||
} | |||||
LSSharedFileListRef loginItems = LSSharedFileListCreate( | LSSharedFileListRef loginItems = LSSharedFileListCreate( | ||||
nullptr, kLSSharedFileListSessionLoginItems, nullptr); | nullptr, kLSSharedFileListSessionLoginItems, nullptr); | ||||
LSSharedFileListItemRef foundItem = | LSSharedFileListItemRef foundItem = | ||||
findStartupItemInList(loginItems, bitcoinAppUrl); | findStartupItemInList(loginItems, bitcoinAppUrl); | ||||
if (fAutoStart && !foundItem) { | if (fAutoStart && !foundItem) { | ||||
// add bitcoin app to startup item list | // add bitcoin app to startup item list | ||||
LSSharedFileListInsertItemURL(loginItems, | LSSharedFileListInsertItemURL(loginItems, | ||||
▲ Show 20 Lines • Show All 166 Lines • Show Last 20 Lines |
Here this is retained.