diff options
author | Jonas Schnelli <jonas.schnelli@include7.ch> | 2013-05-03 15:18:28 +0200 |
---|---|---|
committer | Jonas Schnelli <jonas.schnelli@include7.ch> | 2013-06-03 12:26:56 +0200 |
commit | f679b2900a3a9f863f888cfb0b1a5e593628e37b (patch) | |
tree | 0df6f7125e4a9c8c9e583f4a36e8e1451eec3030 /src/qt/guiutil.cpp | |
parent | eef2091fe9ee39ecd8e874c91d3ab0ff023c5356 (diff) |
MaxOSX: settings fixes (#2371)
- Launch-At-Startup implementation for mac
- Remove "Window" tab in settings
Signed-off-by: Jonas Schnelli <jonas.schnelli@include7.ch>
Diffstat (limited to 'src/qt/guiutil.cpp')
-rw-r--r-- | src/qt/guiutil.cpp | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 2105f0730e..d7d59fc880 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -408,10 +408,61 @@ bool SetStartOnSystemStartup(bool fAutoStart) } return true; } -#else -// TODO: OSX startup stuff; see: -// https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Articles/CustomLogin.html + +#elif defined(Q_OS_MAC) +// based on: https://github.com/Mozketo/LaunchAtLoginController/blob/master/LaunchAtLoginController.m + +#include <CoreFoundation/CoreFoundation.h> +#include <CoreServices/CoreServices.h> + +LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl); +LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl) +{ + // loop through the list of startup items and try to find the bitcoin app + CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(list, NULL); + for(int i = 0; i < CFArrayGetCount(listSnapshot); i++) { + LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(listSnapshot, i); + UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes; + CFURLRef currentItemURL = NULL; + LSSharedFileListItemResolve(item, resolutionFlags, ¤tItemURL, NULL); + if(currentItemURL && CFEqual(currentItemURL, findUrl)) { + // found + CFRelease(currentItemURL); + return item; + } + if(currentItemURL) { + CFRelease(currentItemURL); + } + } + return NULL; +} + +bool GetStartOnSystemStartup() +{ + CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle()); + LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL); + LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl); + return !!foundItem; // return boolified object +} + +bool SetStartOnSystemStartup(bool fAutoStart) +{ + CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle()); + LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL); + LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl); + + if(fAutoStart && !foundItem) { + // add bitcoin app to startup item list + LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst, NULL, NULL, bitcoinAppUrl, NULL, NULL); + } + else if(!fAutoStart && foundItem) { + // remove item + LSSharedFileListItemRemove(loginItems, foundItem); + } + return true; +} +#else bool GetStartOnSystemStartup() { return false; } bool SetStartOnSystemStartup(bool fAutoStart) { return false; } |