mac: add browser webchat debug entry

This commit is contained in:
Peter Steinberger
2025-12-10 01:33:15 +01:00
parent 7871e705bf
commit 08f8f58971
3 changed files with 43 additions and 0 deletions

View File

@@ -240,6 +240,12 @@ enum DebugActions {
typealias PortListener = PortGuardian.ReportListener
typealias PortReport = PortGuardian.PortReport
@MainActor
static func openChatInBrowser() async {
let session = WebChatManager.shared.preferredSessionKey()
await WebChatManager.shared.openInBrowser(sessionKey: session)
}
static func checkGatewayPorts() async -> [PortReport] {
let mode = CommandResolver.connectionSettings().mode
return await PortGuardian.shared.diagnose(mode: mode)

View File

@@ -141,6 +141,11 @@ struct MenuContent: View {
} label: {
Label("Send Test Notification", systemImage: "bell")
}
Button {
Task { await DebugActions.openChatInBrowser() }
} label: {
Label("Open Chat in Browser…", systemImage: "safari")
}
Divider()
Button {
DebugActions.restartGateway()

View File

@@ -447,6 +447,7 @@ final class WebChatManager {
static let shared = WebChatManager()
private var windowController: WebChatWindowController?
private var panelController: WebChatWindowController?
private var browserTunnel: WebChatTunnel?
var onPanelVisibilityChanged: ((Bool) -> Void)?
func show(sessionKey: String) {
@@ -513,6 +514,37 @@ final class WebChatManager {
return "+1003"
}
@MainActor
func openInBrowser(sessionKey: String) async {
let port = AppStateStore.webChatPort
let base: URL
if CommandResolver.connectionModeIsRemote() {
do {
// Prefer the configured port; fall back if busy.
let tunnel = try await WebChatTunnel.create(
remotePort: port,
preferredLocalPort: UInt16(port))
self.browserTunnel?.terminate()
self.browserTunnel = tunnel
guard let local = tunnel.localPort else {
throw NSError(domain: "WebChat", code: 7, userInfo: [NSLocalizedDescriptionKey: "Tunnel missing local port"])
}
base = URL(string: "http://127.0.0.1:\(local)/")!
} catch {
NSAlert(error: error).runModal()
return
}
} else {
base = URL(string: "http://127.0.0.1:\(port)/")!
}
var comps = URLComponents(url: base, resolvingAgainstBaseURL: false)
comps?.path = "/webchat/"
comps?.queryItems = [URLQueryItem(name: "session", value: sessionKey)]
guard let url = comps?.url else { return }
NSWorkspace.shared.open(url)
}
func close() {
self.windowController?.shutdown()
self.windowController?.close()