admin管理员组文章数量:1405508
I have a MacOS application I'm trying to migrate to the SwiftUI scene instead of doing the Windows management by myself. I connect my scene with a AppDelegate.
import Foundation
import SwiftUI
@main
struct iMarketApp: App {
@NSApplicationDelegateAdaptor var delegate: AppDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
If the user closes the main window, I want to be able to reopen it programmatically from my AppDelegate (doing programmatically the equivalent of clicking on the App Icon again). I don't want to use openWindow
with an id
as it tries to recreate a new window every time and I want this window to be unique and reuse if it already exists.
From my delegate, I just want to put the window in the foreground if it exists or reopen it and put it on the foreground if it doesn't exist.
I would like to also avoid parsing NSApp.windows
and searching for my window.
Is it possible to do it in a simple SwiftUI way nowadays or do I have to manage it the old school way with NSWindow
manipulation, check if my window exists, makeKeyAndOrderFront
, etc...
本文标签: SwiftUI Reactivate scene after window close on MacOSStack Overflow
版权声明:本文标题:SwiftUI Reactivate scene after window close on MacOS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744897725a2631163.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论