From a037710e03b690a73d30320bf7378bf5cc119c44 Mon Sep 17 00:00:00 2001 From: Dustin Mierau Date: Thu, 4 Jan 2024 08:36:46 -0800 Subject: Add Connect to Server to menu with classic cmd-K shortcut. Make sure globe next to server name dims when window is inactive. --- Hotline/Application.swift | 27 +++++++++++++-------------- Hotline/macOS/ServerView.swift | 3 +++ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Hotline/Application.swift b/Hotline/Application.swift index 8e1b4d9..91f8dac 100644 --- a/Hotline/Application.swift +++ b/Hotline/Application.swift @@ -1,17 +1,16 @@ import SwiftUI import SwiftData -enum ServerWindowDestination: Hashable, Codable { - case server(server: Server) - case none -} - @main struct Application: App { #if os(iOS) private var model = Hotline(trackerClient: HotlineTrackerClient(), client: HotlineClient()) #endif + #if os(macOS) + @Environment(\.openWindow) private var openWindow + #endif + @State private var preferences = Prefs() var body: some Scene { @@ -33,16 +32,16 @@ struct Application: App { .frame(minWidth: 400, minHeight: 300) .environment(preferences) } - .defaultSize(width: 700, height: 800) + .defaultSize(width: 750, height: 700) .defaultPosition(.center) -// .commandsRemoved() -// .commands { -// CommandGroup(before: CommandGroupPlacement.newItem) { -// Button("before item") { -// print("before item") -// } -// } -// } + .commands { + CommandGroup(replacing: CommandGroupPlacement.newItem) { + Button("Connect to Server...") { + openWindow(id: "server") + } + .keyboardShortcut(.init("K"), modifiers: .command) + } + } Settings { SettingsView() diff --git a/Hotline/macOS/ServerView.swift b/Hotline/macOS/ServerView.swift index 7589744..a7dc90d 100644 --- a/Hotline/macOS/ServerView.swift +++ b/Hotline/macOS/ServerView.swift @@ -390,9 +390,12 @@ struct ServerView: View { .toolbar { ToolbarItem(placement: .navigation) { Image(systemName: "globe.americas.fill") + .renderingMode(.template) + .resizable() .scaledToFit() .frame(width: 18) + .opacity(controlActiveState == .inactive ? 0.4 : 1.0) } } } -- cgit