diff --git a/Easydict/App/EasydictApp.swift b/Easydict/App/EasydictApp.swift index 82b133893..5dbf9f90e 100644 --- a/Easydict/App/EasydictApp.swift +++ b/Easydict/App/EasydictApp.swift @@ -91,6 +91,28 @@ struct EasydictApp: App { @Default(.selectedMenuBarIcon) private var menuBarIcon @StateObject private var languageState = LanguageState() + + @State var aboutWindow: NSWindow? + + private func showAboutWindow() { + if let aboutWindow = aboutWindow { + aboutWindow.makeKeyAndOrderFront(nil) + } else { + aboutWindow = NSWindow( + contentRect: NSRect(x: 0, y: 0, width: 500, height: 220), + styleMask: [.titled, .closable], + backing: .buffered, defer: false + ) + aboutWindow?.titleVisibility = .hidden + aboutWindow?.titlebarAppearsTransparent = true + aboutWindow?.isReleasedWhenClosed = false + aboutWindow?.center() + if #available(macOS 13, *) { + aboutWindow?.contentView = NSHostingView(rootView: SettingsAboutTab()) + } + aboutWindow?.makeKeyAndOrderFront(nil) + } + } } // MARK: - FakeViewToOpenSettingsInSonoma diff --git a/Easydict/Swift/View/SettingView/Tabs/TabView/AboutTab.swift b/Easydict/Swift/View/SettingView/Tabs/TabView/AboutTab.swift index 8d187f9bc..f012ccc7f 100644 --- a/Easydict/Swift/View/SettingView/Tabs/TabView/AboutTab.swift +++ b/Easydict/Swift/View/SettingView/Tabs/TabView/AboutTab.swift @@ -92,18 +92,3 @@ struct AboutTab: View { #Preview { AboutTab() } - -@available(macOS 13, *) -func showAboutWindow() { - let aboutWindow = NSWindow( - contentRect: NSRect(x: 0, y: 0, width: 500, height: 220), - styleMask: [.titled, .closable], - backing: .buffered, defer: false - ) - aboutWindow.titleVisibility = .hidden - aboutWindow.titlebarAppearsTransparent = true - aboutWindow.center() - aboutWindow.contentView = NSHostingView(rootView: SettingsAboutTab()) - aboutWindow.isReleasedWhenClosed = false - aboutWindow.makeKeyAndOrderFront(nil) -}