blob: 71877dcc220c9cb480ed715a2b5bf814fdb61f33 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
import SwiftUI
import BubombCore
#if canImport(AppKit)
import AppKit
/// Controls creation, display, and lifecycle of native macOS windows for Bubomb.
@MainActor
public final class WindowManager: NSObject, NSWindowDelegate {
public static let shared = WindowManager()
private var settingsWindow: NSWindow?
override private init() {
super.init()
}
/// Opens or brings the Settings window to the front.
public func showSettingsWindow(settingsStore: SettingsStore = .shared, executor: PayloadExecutor? = nil) {
let exec = executor ?? PayloadExecutor.shared
if let window = settingsWindow {
window.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)
return
}
let contentView = SettingsView(settingsStore: settingsStore, executor: exec)
let hostingController = NSHostingController(rootView: contentView)
let window = NSWindow(contentViewController: hostingController)
window.title = "Bubomb Settings"
window.styleMask = [.titled, .closable, .miniaturizable, .resizable]
window.titlebarAppearsTransparent = true
window.titleVisibility = .hidden
window.isReleasedWhenClosed = false
window.delegate = self
window.backgroundColor = NSColor(calibratedRed: 0.08, green: 0.08, blue: 0.10, alpha: 1.0)
window.setContentSize(NSSize(width: 680, height: 580))
window.center()
self.settingsWindow = window
window.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)
}
public func closeSettingsWindow() {
settingsWindow?.orderOut(nil)
}
// MARK: - NSWindowDelegate
public func windowWillClose(_ notification: Notification) {
// Keep window reference around for fast reopening
}
}
#endif
|