Skip to content

Commit

Permalink
perf: improve showAboutWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng committed May 3, 2024
1 parent 22873ad commit 85d6ef5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
22 changes: 22 additions & 0 deletions Easydict/App/EasydictApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions Easydict/Swift/View/SettingView/Tabs/TabView/AboutTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 85d6ef5

Please sign in to comment.