Skip to content

Commit

Permalink
Merge bitcoin#17567: gui: remove macOS start on login code
Browse files Browse the repository at this point in the history
27d82b6 gui: remove macOS start on login code (fanquake)

Pull request description:

  The macOS startup item code was disabled for builds targeting macOS >
  `10.11` in bitcoin#15208. Now that we require macOS `10.12` as a minimum (bitcoin#17550),
  we can remove the startup item code entirely. The API we were using, `LSSharedFileListItemCopyResolvedURL`, `LSSharedFileListCopySnapshot` etc,
  was removed in macOS `10.12` SDK.

ACKs for top commit:
  jonasschnelli:
    utACK 27d82b6
  jonasschnelli:
    Tested ACK 27d82b6 - successfully compiled on 10.15.1

Tree-SHA512: 7420757b91c7820e6a63280887155394547134a9cebcf3721af0284da23292627f94cd431241e033075b3fd86d79ace3ebf1b25d17763acbf71e07a742395409
  • Loading branch information
fanquake authored and sidhujag committed Nov 27, 2019
1 parent 3815259 commit 0435902
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 87 deletions.
2 changes: 2 additions & 0 deletions doc/release-notes.md
Expand Up @@ -90,6 +90,8 @@ Low-level Changes section below.
GUI changes
-----------

- The "Start Syscoin Core on system login" option has been removed on macOS.

Wallet
------

Expand Down
84 changes: 0 additions & 84 deletions src/qt/guiutil.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -699,87 +696,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 syscoin 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 syscoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
if (syscoinAppUrl == nullptr) {
return false;
}

LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(loginItems, nullptr);
bool res = (findStartupItemInList(listSnapshot, loginItems, syscoinAppUrl) != nullptr);
CFRelease(syscoinAppUrl);
CFRelease(loginItems);
CFRelease(listSnapshot);
return res;
}

bool SetStartOnSystemStartup(bool fAutoStart)
{
CFURLRef syscoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
if (syscoinAppUrl == nullptr) {
return false;
}

LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(loginItems, nullptr);
LSSharedFileListItemRef foundItem = findStartupItemInList(listSnapshot, loginItems, syscoinAppUrl);

if(fAutoStart && !foundItem) {
// add syscoin app to startup item list
LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst, nullptr, nullptr, syscoinAppUrl, nullptr, nullptr);
}
else if(!fAutoStart && foundItem) {
// remove item
LSSharedFileListItemRemove(loginItems, foundItem);
}

CFRelease(syscoinAppUrl);
CFRelease(loginItems);
CFRelease(listSnapshot);
return true;
}
#pragma GCC diagnostic pop
#else

bool GetStartOnSystemStartup() { return false; }
Expand Down
4 changes: 1 addition & 3 deletions src/qt/optionsdialog.cpp
Expand Up @@ -71,12 +71,10 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
#ifdef Q_OS_MAC
/* remove Window tab on Mac */
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWindow));
#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED > 101100
/* hide launch at startup option if compiled against macOS > 10.11 (removed API) */
/* hide launch at startup option on macOS */
ui->syscoinAtStartup->setVisible(false);
ui->verticalLayout_Main->removeWidget(ui->syscoinAtStartup);
ui->verticalLayout_Main->removeItem(ui->horizontalSpacer_0_Main);
#endif
#endif

/* remove Wallet tab in case of -disablewallet */
Expand Down

0 comments on commit 0435902

Please sign in to comment.