Reputation: 29
I'm encountering an issue while developing my Mac app and I have a question.
Even in a test app with no additional features, after Hide (cmd + h) or Minimize (cmd + m) and then activating the app again, the 'View' menu in the top tab of NSMenu does not display 'Enter Full Screen' when clicked.
That's the menu I'm referring to.
Pressing the shortcut for Enter Full Screen, Fn + F, also does not produce any response. However, the Window menu, the green button, works fine.
I have tried the following attempts.
# Active state of scenePhase
.onChange(of: scenePahse){ scene in
switch scene {
case .active :
NSApplication.shared.mainMenu?.autoenablesItems = true
NSApplication.shared.windows.forEach{ window in
window.menu?.autoenablesItems = true
window.menu?.items.forEach {
if $0.title == "View" {
$0.submenu?.items.forEach{ item in
item.isEnabled = true
item.isHidden = false
}
}
}
}
NSApplication.shared.presentationOptions.insert(.fullScreen)
NSApplication.shared.mainMenu?.setAccessibilityFullScreenButton(true)
}
}
--------------------------------
//second try
NSApplication.shared.mainMenu.item(at: 3)?.submenu?.addItem(NSMenuItem(title: "Enter Full Screen", action: #selector(NSWindow.toggleFullScreen(_:)), keyEquivalent: "F"))
or
NSApplication.shared.mainMenu?.item(at: 3)?.submenu?.items = [NSMenuItem(title: "Enter Full Screen", action: #selector(NSWindow.toggleFullScreen(_:)), keyEquivalent: "F")]
//third try
ContentView()
.onAppear{
NSApplication.shared.mainMenu?.autoenablesItems = false
}
But I don't want to disable hiding or minimizing
++
After confirming today, I discovered that when creating a Scene with a Window struct, 'Enter Full Screen' enabled when the app becomes active after Hide or Minimize.
"Here is the environment of my project. Please note:
Using WindowGroup (Note: Window usage not available -> only available after version 13) This is a rough structure for a single window in my project app.
WindowGroup("title", id: "id") {
ContentView().handlesExternalEvents(preferring: ["*"], allowing: ["*"])
}
.commands {
CommandGroup(replacing: .newItem){}
CommandGroup(replacing: .windowList){}
.handlesExternalEvents(matching: [])
}
Is there a way to resolve this persistent problem?
Upvotes: 1
Views: 111