Skip to content

Commit

Permalink
macOS: Fix path comparison in launch-on-startup code
Browse files Browse the repository at this point in the history
When checking if the client is auto-started, the list of all login-items
is retrieved, and each item is compared to the path of the .app bundle.
This comparison needs to be done ignoring the case, as most macOS file
systems are case-insensitive.

#9387
  • Loading branch information
erikjv committed Feb 11, 2022
1 parent 68eacec commit 18caeee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/9387
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Fix toggling launch-on-login for macOS

This would fail when upgrading the application, and the upgraded version
has one or more letters in the name changed from/to upper-case.

https://github.com/owncloud/client/issues/9387
https://github.com/owncloud/client/pull/9433
16 changes: 14 additions & 2 deletions src/common/utility_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ bool hasLaunchOnStartup_private(const QString &)

if (LSSharedFileListItemResolve(item, 0, &itemUrlRef, NULL) == noErr && itemUrlRef) {
CFStringRef itemUrlString = CFURLGetString(itemUrlRef);
if (CFStringCompare(itemUrlString, appUrlRefString, 0) == kCFCompareEqualTo) {

// Check if we found "our" app url.
// IMPORTANT: this needs to be a case-insensitive compare, because (most) macOS
// file systems are case insensitive, so if e.g. "btr.app" is replaced by "BtR.app"
// in an update, they should be treated the same.
// See also: https://github.com/owncloud/client/issues/9387
if (CFStringCompare(itemUrlString, appUrlRefString, kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
returnValue = true;
}
CFRelease(itemUrlRef);
Expand Down Expand Up @@ -108,7 +114,13 @@ void setLaunchOnStartup_private(const QString &appName, const QString &guiName,

if (LSSharedFileListItemResolve(item, 0, &itemUrlRef, NULL) == noErr && itemUrlRef) {
CFStringRef itemUrlString = CFURLGetString(itemUrlRef);
if (CFStringCompare(itemUrlString, appUrlRefString, 0) == kCFCompareEqualTo) {

// Check if we found "our" app url.
// IMPORTANT: this needs to be a case-insensitive compare, because (most) macOS
// file systems are case insensitive, so if e.g. "btr.app" is replaced by "BtR.app"
// in an update, they should be treated the same.
// See also: https://github.com/owncloud/client/issues/9387
if (CFStringCompare(itemUrlString, appUrlRefString, kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
LSSharedFileListItemRemove(loginItems, item); // remove it!
}
CFRelease(itemUrlRef);
Expand Down

0 comments on commit 18caeee

Please sign in to comment.