diff options
| author | Dustin Mierau <dustin@mierau.me> | 2025-10-28 10:06:33 -0700 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2025-10-28 10:06:33 -0700 |
| commit | c5165d348c1efbcc553b3c31dbeaa23353914fb6 (patch) | |
| tree | 6ba4121a34c095d1180d3025f59e5a300b533937 /Hotline/macOS | |
| parent | d23d0ad9405c1622569415e6ce16d3768af2936a (diff) | |
Some state cleanup and banner color caching in ServerState.
Diffstat (limited to 'Hotline/macOS')
| -rw-r--r-- | Hotline/macOS/HotlinePanelView.swift | 13 | ||||
| -rw-r--r-- | Hotline/macOS/ServerView.swift | 22 |
2 files changed, 22 insertions, 13 deletions
diff --git a/Hotline/macOS/HotlinePanelView.swift b/Hotline/macOS/HotlinePanelView.swift index 4ae4924..ee4d198 100644 --- a/Hotline/macOS/HotlinePanelView.swift +++ b/Hotline/macOS/HotlinePanelView.swift @@ -4,16 +4,9 @@ struct HotlinePanelView: View { @Environment(\.openWindow) var openWindow @Environment(\.colorScheme) var colorScheme - private var colorArt: ColorArt? { - if let banner = AppState.shared.activeServerBanner { - return ColorArt(image: banner, scaledSize: NSSize(width: 100, height: 100)) - } - return nil - } - var body: some View { VStack(spacing: 0) { - Image(nsImage: AppState.shared.activeServerBanner ?? NSImage(named: "Default Banner")!) + Image(nsImage: AppState.shared.activeServerState?.serverBanner ?? NSImage(named: "Default Banner")!) .interpolation(.high) .resizable() .scaledToFill() @@ -123,8 +116,8 @@ struct HotlinePanelView: View { .padding(.top, 12) .padding(.bottom, 12) .padding([.leading, .trailing], 12) - .background(colorArt.map { Color(nsColor: $0.backgroundColor) } ?? Color(nsColor: .controlBackgroundColor)) - .foregroundStyle(colorArt.map { Color(nsColor: $0.primaryColor) } ?? Color.primary) + .background(AppState.shared.activeServerState?.bannerColors.map { Color(nsColor: $0.backgroundColor) } ?? Color(nsColor: .controlBackgroundColor)) + .foregroundStyle(AppState.shared.activeServerState?.bannerColors.map { Color(nsColor: $0.primaryColor) } ?? Color.primary) // .background(Color.red.opacity(0.5).blendMode(.multiply)) // GroupBox { diff --git a/Hotline/macOS/ServerView.swift b/Hotline/macOS/ServerView.swift index 77b6dc8..6d5743c 100644 --- a/Hotline/macOS/ServerView.swift +++ b/Hotline/macOS/ServerView.swift @@ -6,11 +6,14 @@ import AppKit class ServerState: Equatable { var id: UUID = UUID() var selection: ServerNavigationType - + var serverName: String? = nil + var serverBanner: NSImage? = nil + var bannerColors: ColorArt? = nil + init(selection: ServerNavigationType) { self.selection = selection } - + static func == (lhs: ServerState, rhs: ServerState) -> Bool { return lhs.id == rhs.id } @@ -104,7 +107,7 @@ extension FocusedValues { get { self[ActiveHotlineModelFocusedValueKey.self] } set { self[ActiveHotlineModelFocusedValueKey.self] = newValue } } - + var activeServerState: ServerState? { get { self[ActiveServerStateFocusedValueKey.self] } set { self[ActiveServerStateFocusedValueKey.self] = newValue } @@ -238,6 +241,19 @@ struct ServerView: View { .onDisappear { model.disconnect() } + .onChange(of: model.serverTitle) { oldTitle, newTitle in + state.serverName = newTitle + } + .onChange(of: model.bannerImage) { oldBanner, newBanner in + withAnimation { + state.serverBanner = newBanner + if let banner = newBanner { + state.bannerColors = ColorArt(image: banner, scaledSize: NSSize(width: 100, height: 100)) + } else { + state.bannerColors = nil + } + } + } .alert(model.errorMessage ?? "Server Error", isPresented: $model.errorDisplayed) { Button("OK") {} } |