Fix macOS launch-at-startup memory issue
This commit is contained in:
parent
516437a1b7
commit
da6011826a
1 changed files with 10 additions and 10 deletions
|
@ -686,10 +686,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
|
||||||
#elif defined(Q_OS_MAC) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED <= 101100
|
#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
|
// based on: https://github.com/Mozketo/LaunchAtLoginController/blob/master/LaunchAtLoginController.m
|
||||||
|
|
||||||
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl);
|
LSSharedFileListItemRef findStartupItemInList(CFArrayRef listSnapshot, LSSharedFileListRef list, CFURLRef findUrl)
|
||||||
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl)
|
|
||||||
{
|
{
|
||||||
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(list, nullptr);
|
|
||||||
if (listSnapshot == nullptr) {
|
if (listSnapshot == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -714,15 +712,12 @@ LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef
|
||||||
if(currentItemURL) {
|
if(currentItemURL) {
|
||||||
if (CFEqual(currentItemURL, findUrl)) {
|
if (CFEqual(currentItemURL, findUrl)) {
|
||||||
// found
|
// found
|
||||||
CFRelease(listSnapshot);
|
|
||||||
CFRelease(currentItemURL);
|
CFRelease(currentItemURL);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
CFRelease(currentItemURL);
|
CFRelease(currentItemURL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(listSnapshot);
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -734,10 +729,12 @@ bool GetStartOnSystemStartup()
|
||||||
}
|
}
|
||||||
|
|
||||||
LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
|
LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
|
||||||
LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);
|
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(loginItems, nullptr);
|
||||||
|
bool res = (findStartupItemInList(listSnapshot, loginItems, bitcoinAppUrl) != nullptr);
|
||||||
CFRelease(bitcoinAppUrl);
|
CFRelease(bitcoinAppUrl);
|
||||||
return !!foundItem; // return boolified object
|
CFRelease(loginItems);
|
||||||
|
CFRelease(listSnapshot);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetStartOnSystemStartup(bool fAutoStart)
|
bool SetStartOnSystemStartup(bool fAutoStart)
|
||||||
|
@ -748,7 +745,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
|
||||||
}
|
}
|
||||||
|
|
||||||
LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
|
LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
|
||||||
LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);
|
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(loginItems, nullptr);
|
||||||
|
LSSharedFileListItemRef foundItem = findStartupItemInList(listSnapshot, loginItems, bitcoinAppUrl);
|
||||||
|
|
||||||
if(fAutoStart && !foundItem) {
|
if(fAutoStart && !foundItem) {
|
||||||
// add bitcoin app to startup item list
|
// add bitcoin app to startup item list
|
||||||
|
@ -760,6 +758,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(bitcoinAppUrl);
|
CFRelease(bitcoinAppUrl);
|
||||||
|
CFRelease(loginItems);
|
||||||
|
CFRelease(listSnapshot);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
Loading…
Reference in a new issue