Comments (3)
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:
SettingsAccess/Demo/Demo/DemoApp.swift
Lines 37 to 44 in e1083e6
from settingsaccess.
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.
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)
- `openSettings()` fails in menu-based MenuBarExtra HOT 9
- doesn't actually work programmatically (but this code does) HOT 13
- Current readme.md suggests minimum macOS is 11, this is wrong and should be 13 HOT 1
- Settings window can not be open in a space with a fullscreen app HOT 6
- Error in macOS 15.0 Sequoia Beta HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from settingsaccess.