Giter Club home page Giter Club logo

Comments (3)

orchetect avatar orchetect commented on July 26, 2024

Might be a SwiftUI bug, or a change in behavior (hopefully not though).

Does your app run as a dockless menubar app? You may need to call NSApp.activate first to give your app frontmost focus. That might help.

The demo app does it this way using the custom SettingsLink wrapper init:

SettingsLink {
Text("Settings...")
} preAction: {
// code to run before Settings opens
NSApp.activate(ignoringOtherApps: true) // this does nothing if running from Xcode, but running as a standalone app it will work
} postAction: {
// code to run after Settings opens
}

from settingsaccess.

tgrushka avatar tgrushka commented on July 26, 2024

Thank you so much!! This code now works for me:

SettingsLink {
    Text("Settings")
} preAction: {
    NSApp.activate(ignoringOtherApps: true)
} postAction: {
    for window in NSApplication.shared.windows {
        if window.level == NSWindow.Level.popUpMenu {
            window.close()
            break
        }
    }
}

(For some reason, I was using the openSettingsAccess() injection method before, but SettingsLink now works for me.) EDIT: Could not get SettingsLink to close the popup before, but now works with postAction.

I think the culprit was: for window in NSApplication.shared.windows.... The reason for this code is that it was not closing the menu extra popup when I clicked on Settings. I tried again and confirmed that this code is required in my case. (Why can't SwiftUI just handle that? I think the whole focus is on iOS/watchOS and now the overpriced VR goggles; SwiftUI macOS bugs are taking a back seat. Steve Jobs is rolling his eyes...)

But, problem solved!! The settings window now comes to front, and I don't have to hide all my other windows to get back to it. Man, keeping up with all these frameworks' quirks on different platforms is really something else.

from settingsaccess.

orchetect avatar orchetect commented on July 26, 2024

closing the menu extra popup when I clicked on Settings
Why can't SwiftUI just handle that?

I assume you're using a window-based MenuBarExtra? SwiftUI will not auto-dismiss the window since it doesn't inherently know when you'd want to. Definitely a huge issue/shortcoming with MenuBarExtra, and yes it seems another symptom of macOS being second-class citizen to Apple's mobile platforms. There is no native way to dismiss the window programmatically other than the user clicking outside of the window. I built another package called MenuBarExtraAccess that can provide programmatic access to showing/dismissing the window - maybe it will help. But it sounds like your solution may be adequate for your situation.

from settingsaccess.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.