Comments (9)
Oh yeah, that's a menu
-based MenuBarExtra
.
SwiftUI treats standard menus differently. Even though you're using a View, for menu items SwiftUI strips out everything except Button
s (Text
and/or Image
labels) and any view modifiers. Which means SwiftUI won't setup the internals for SettingsAccess to work.
Inside a menu, SettingsLink
is sufficient to open Settings but it won't let you run custom code before or after it's clicked.
I'm not sure there is a solution for this specific scenario. I've tried a few approaches and nothing is sticking yet.
I will add a note to the readme in the interim that this is an unsupported use case until a solution can be worked out.
from settingsaccess.
Usually this happens if compiling with Xcode 14 (it needs Xcode 15).
from settingsaccess.
I've pushed release 1.1.0 which will now only compile on Xcode 15. That was originally intended and was a bit of an oversight to have allowed compiling on Xcode 14 which is where the error came from.
from settingsaccess.
this does not resolve the issue, it had been compiled with xcode 15 already, updating to the next minor still throws this exception
from settingsaccess.
I need more details about where you're using .openSettingsAccess()
and where you're calling openSettings()
.
What it most likely means is the view that is getting .openSettingsAccess()
is not being created or persisted.
from settingsaccess.
it's being chained onto mainmenuview in app.swift here
@main
struct ishare: App {
@Default(.menuBarIcon) var menubarIcon
@Default(.showMainMenu) var showMainMenu
@StateObject private var appState = AppState()
@NSApplicationDelegateAdaptor private var appDelegate : AppDelegate
var body: some Scene {
MenuBarExtra() {
MainMenuView().openSettingsAccess()
}
label: {
switch menubarIcon {
case .DEFAULT: Image(nsImage: GlyphIcon)
case .APPICON: Image(nsImage: AppIcon)
case .SYSTEM: Image(systemName: "photo.on.rectangle.angled")
}
}
.menuBarExtraAccess(isPresented: $showMainMenu)
Settings {
SettingsMenuView()
}
}
}
within MainMenuview the env is declared:
struct MainMenuView: View {
@StateObject private var availableContentProvider = AvailableContentProvider()
@Environment(\.openSettings) private var openSettings
var body: some View {
...
and then the method is called within a button
Button {
NSApplication.shared.activate(ignoringOtherApps: true)
openSettings()
} label: {
Image(systemName: "gearshape")
Label("Settings", image: String())
}.keyboardShortcut("s")
from settingsaccess.
Actually I think I've found solution. I'll try to push it today or tomorrow, just want to polish it up.
from settingsaccess.
Ok try release 1.2.0. The Demo project and readme are updated, but this is the gist:
- Remove
.openSettingsAccess()
from yourMenuBarExtra
menu view - Inside
MainMenuView
, instead of yourButton
, use this:SettingsLink { Image(systemName: "gearshape") Text("Settings") } preAction: { NSApp.activate(ignoringOtherApps: true) } postAction: { // empty } .keyboardShortcut("s")
from settingsaccess.
lovely, whatever you did works much better than the actual SettingsLink component <3
from settingsaccess.
Related Issues (6)
- 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
- macOS 14.4.1: Settings no longer orders front when activated HOT 3
- 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.