Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a proper way to activate based on the bundle info on macOS #226

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

matyalatte
Copy link
Contributor

This PR will make it possible to detect if the program is running as an app bundle or not, and call proper functions for activation.

Closes #225

Copy link
Contributor

@cody271 cody271 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

../darwin/main.m:116:31: warning: incompatible pointer types passing 'NSString *' to parameter of type 'CFStringRef' (aka 'const struct __CFString *') [-Wincompatible-pointer-types]
        if (!CFStringHasSuffix(path, @".app")) {
                                     ^~~~~~~
/Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFString.h:483:62: note: passing argument to parameter 'suffix' here
Boolean CFStringHasSuffix(CFStringRef theString, CFStringRef suffix);
                                                             ^
1 warning generated.

darwin/main.m Outdated Show resolved Hide resolved
@cody271
Copy link
Contributor

cody271 commented Sep 18, 2023

Will have to manually build some .app bundles to test this before merge. Our tooling can't do this yet. Otherwise looks good!

Copy link
Contributor

@szanni szanni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pushing this issue.
I would be very happy to close this topic as it is highly annoying, even just while debugging.

Comment on lines +120 to +124

// don't check for a NO return;
// something (launch services?) causes running from application bundles to always return NO
// when asking to change activation policy, even if the change is to the same activation policy!
// see https://github.com/andlabs/ui/issues/6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems redundant to me, as the context of setActivationPolicy is now within a non application bundle.
TBH - while maybe a weird API decision - returning NO on change to the same policy is what is to be expected according to the docs:

true if the policy switch succeded; otherwise, false.

If we really want to check the return code we could check it first via activationPolicy and only set it if it is !=NSApplicationActivationPolicyRegular. Then check the return code if it is that important?

activate = YES;
} else if ([uiprivNSApp() activationPolicy] == NSApplicationActivationPolicyAccessory) {
// The app is an agent app that runs in the background and doesn't appear in the Dock.
activate = YES;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is my understanding correct, that we need to call activateIgnoringOtherApps even if we are in an app bundle for NSApplicationActivationPolicyAccessory? As @cody271 suggested, could we expand that comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Menu bar is frozen when launching the app on macOS
3 participants