Is it possible to create a custom scene that would provide a Window instance backed by NSPanel on macOS instead of regular NSWindow?
Ideally, I would have the following in my app:
@main
struct MaccyApp: App {
var body: some Scene {
Panel("Maccy", id: "org.p0deje.Maccy") { // similar to Window(...)
ContentView()
}
}
}
where Panel would implement a custom logic to present itself so the views could access scenePhase, openWindow and dismiss and other common environment values.
I know there is a way to access window and customize it by implement an NSViewRepresentable view with makeNSView(context:), however there is no way to replace the used window with a different implementation class such as NSPanel.
Post
Replies
Boosts
Views
Activity
Sonoma beta release notes mention that NSMenu was rewritten from scratch using AppKit, however, it seems like a lot of behavior was removed along the way which breaks applications. I've filed several requests using Feedback Assistant, but none of them were fixed in the 3 following betas.
FB12867496: NSMenu no longer receives keyboard events from GetEventDispatcherTarget (there is a workaround)
FB12867573: NSMenuItem custom view window is nil
FB12887219 : NSMenu performSelector highlightItem doesn't highlight menu item
FB12938907: NSMenu not properly updated when adding/removing NSMenuItem
I wonder if anyone else has experienced similar problems and can share workarounds for them:
Is there any modern example of how to create a sandboxed application that provides a spelling service to other macOS applications? The example out there are all in Objective-C and doesn't work when run in modern Xcode.
I have the following piece of code that is used to trigger pasting of what is currently in the pasteboard:
let vCode = UInt16(kVK_ANSI_V)
let source = CGEventSource(stateID: .combinedSessionState)
source?.setLocalEventsFilterDuringSuppressionState([.permitLocalMouseEvents, .permitSystemDefinedEvents],
																									 state: .eventSuppressionStateSuppressionInterval)
let keyVDown = CGEvent(keyboardEventSource: source, virtualKey: vCode, keyDown: true)
let keyVUp = CGEvent(keyboardEventSource: source, virtualKey: vCode, keyDown: false)
keyVDown?.flags = .maskCommand
keyVUp?.flags = .maskCommand
keyVDown?.post(tap: .cgAnnotatedSessionEventTap)
keyVUp?.post(tap: .cgAnnotatedSessionEventTap)
The code worked fine and reliably until I enabled App Sandbox. Now, the code still works in Catalina and Mojave, but silently fails in High Sierra. The application has full accessibility permissions.
This code is used in my open source clipboard manager - Maccy. You can see full code in https://github.com/p0deje/Maccy/blob/16ded91a2779b67ebafec92188a61d0b7e713680/Maccy/Clipboard.swift#L87-L100.