feat(macos): add menu link to dashboard

This commit is contained in:
Peter Steinberger
2025-12-19 04:28:32 +00:00
parent d80d112e09
commit 00fc731d64

View File

@@ -44,6 +44,11 @@ struct MenuContent: View {
Button("Open Chat") {
WebChatManager.shared.show(sessionKey: WebChatManager.shared.preferredSessionKey())
}
Button("Open Dashboard") {
Task { @MainActor in
await self.openDashboard()
}
}
Toggle(
isOn: Binding(
get: { self.browserControlEnabled },
@@ -225,6 +230,40 @@ struct MenuContent: View {
NotificationCenter.default.post(name: .clawdisSelectSettingsTab, object: tab)
}
@MainActor
private func openDashboard() async {
do {
let config = try await GatewayEndpointStore.shared.requireConfig()
let wsURL = config.url
guard var components = URLComponents(url: wsURL, resolvingAgainstBaseURL: false) else {
throw NSError(domain: "Dashboard", code: 1, userInfo: [
NSLocalizedDescriptionKey: "Invalid gateway URL",
])
}
switch components.scheme?.lowercased() {
case "ws":
components.scheme = "http"
case "wss":
components.scheme = "https"
default:
components.scheme = "http"
}
components.path = "/ui/"
components.query = nil
guard let url = components.url else {
throw NSError(domain: "Dashboard", code: 2, userInfo: [
NSLocalizedDescriptionKey: "Failed to build dashboard URL",
])
}
NSWorkspace.shared.open(url)
} catch {
let alert = NSAlert()
alert.messageText = "Dashboard unavailable"
alert.informativeText = error.localizedDescription
alert.runModal()
}
}
private var healthStatus: (label: String, color: Color) {
if let activity = self.activityStore.current {
let color: Color = activity.role == .main ? .accentColor : .gray