From 3762e410f82df1c3ae7fba5b1258bb2a5195a490 Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Mon, 3 May 2021 12:35:28 +0200 Subject: [PATCH] Log if setting up launch on start fails on mac Signed-off-by: Camila Ayres --- src/common/utility_mac.cpp | 60 +++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/src/common/utility_mac.cpp b/src/common/utility_mac.cpp index 9a220527f..bd8e9bc07 100644 --- a/src/common/utility_mac.cpp +++ b/src/common/utility_mac.cpp @@ -16,6 +16,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "utility.h" + #include #include @@ -88,34 +90,40 @@ void setLaunchOnStartup_private(const QString &appName, const QString &guiName, CFURLRef urlRef = CFURLCreateWithFileSystemPath(0, folderCFStr, kCFURLPOSIXPathStyle, true); LSSharedFileListRef loginItems = LSSharedFileListCreate(0, kLSSharedFileListSessionLoginItems, 0); - if (loginItems && enable) { - //Insert an item to the list. - LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(loginItems, - kLSSharedFileListItemLast, 0, 0, - urlRef, 0, 0); - if (item) - CFRelease(item); - CFRelease(loginItems); - } else if (loginItems && !enable) { - // We need to iterate over the items and check which one is "ours". - UInt32 seedValue; - CFArrayRef itemsArray = LSSharedFileListCopySnapshot(loginItems, &seedValue); - CFStringRef appUrlRefString = CFURLGetString(urlRef); - for (int i = 0; i < CFArrayGetCount(itemsArray); i++) { - LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(itemsArray, i); - CFURLRef itemUrlRef = nullptr; - - if (LSSharedFileListItemResolve(item, 0, &itemUrlRef, nullptr) == noErr && itemUrlRef) { - CFStringRef itemUrlString = CFURLGetString(itemUrlRef); - if (CFStringCompare(itemUrlString, appUrlRefString, 0) == kCFCompareEqualTo) { - LSSharedFileListItemRemove(loginItems, item); // remove it! - } - CFRelease(itemUrlRef); + if (!loginItems) { + qCWarning(lcUtility) << "Failed to retrieve loginItems"; + } else { + if (enable) { + //Insert an item to the list. + LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(loginItems, + kLSSharedFileListItemLast, 0, 0, + urlRef, 0, 0); + if (item) { + CFRelease(item); + } else { + qCWarning(lcUtility) << "Failed to insert ourself into launch on startup list"; } - } - CFRelease(itemsArray); + } else { + // We need to iterate over the items and check which one is "ours". + UInt32 seedValue; + CFArrayRef itemsArray = LSSharedFileListCopySnapshot(loginItems, &seedValue); + CFStringRef appUrlRefString = CFURLGetString(urlRef); + for (int i = 0; i < CFArrayGetCount(itemsArray); i++) { + LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(itemsArray, i); + CFURLRef itemUrlRef = NULL; + + if (LSSharedFileListItemResolve(item, 0, &itemUrlRef, NULL) == noErr && itemUrlRef) { + CFStringRef itemUrlString = CFURLGetString(itemUrlRef); + if (CFStringCompare(itemUrlString, appUrlRefString, 0) == kCFCompareEqualTo) { + LSSharedFileListItemRemove(loginItems, item); // remove it! + } + CFRelease(itemUrlRef); + } + } + CFRelease(itemsArray); + }; CFRelease(loginItems); - }; + } CFRelease(folderCFStr); CFRelease(urlRef);