M4: TranslationSession actor with epochs/one-in-flight streaming, PanelViewModel, non-activating NSPanel, streaming panel UI, searchable/recent target languages, warnings/errors and Copy/Retry/Replace actions. M5: InsertionCoordinator with target capture, AX direct replacement, secure-field/own-PID refusal, frontmost and selected-text verification, snapshot/⌘V/restore fallback, cancellation-safe restore and blocking-warning gate. M6: versioned AppSettings/SettingsStore, onboarding for Ollama/model/target/Accessibility, General/Model/Translation/Privacy/Diagnostics settings, launch-at-login via SMAppService, status menu (target, copy/replace last, setup, diagnostics, about), text-free diagnostics and first-run setup. Docs: PROGRESS M4–M6, ARCHITECTURE §10–§12, ADR-019/020, SELECTION_AND_CLIPBOARD and TESTING. Manual 10-app matrices, real AX/paste delivery, VoiceOver and focus checks remain open. Verified: make verify green (format, strict lint, scripts, privacy, Debug+Release signatures, 217 package tests); app launches and a two-copy clipboard smoke test opens the panel.
96 lines
3.2 KiB
Swift
96 lines
3.2 KiB
Swift
import AppKit
|
|
import SprachmittlerCore
|
|
import SwiftUI
|
|
|
|
/// The diagnostics window. It shows no text, only versions, digests, timings and error kinds.
|
|
struct DiagnosticsView: View {
|
|
@Bindable var model: DiagnosticsViewModel
|
|
let onCopy: @MainActor (String) -> Void
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 12) {
|
|
HStack {
|
|
Text(String(localized: "Diagnostics"))
|
|
.font(.title2.bold())
|
|
Spacer()
|
|
Button(String(localized: "Refresh")) {
|
|
Task { await model.refresh() }
|
|
}
|
|
.disabled(model.isRefreshing)
|
|
Button(String(localized: "Copy report")) {
|
|
onCopy(model.report())
|
|
}
|
|
Button(String(localized: "Clear")) {
|
|
Task { await model.clear() }
|
|
}
|
|
}
|
|
|
|
GroupBox(String(localized: "Ollama")) {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Text("Version: \(model.serverVersion ?? String(localized: "unknown"))")
|
|
Text(
|
|
"Models: "
|
|
+ model.models.map { "\($0.name) [\($0.digest.prefix(12))]" }
|
|
.joined(separator: ", ")
|
|
)
|
|
if let error = model.error {
|
|
Text(error).foregroundStyle(.red)
|
|
}
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
|
|
Text(String(localized: "Last 50 events"))
|
|
.font(.headline)
|
|
List {
|
|
ForEach(Array(model.events.enumerated()), id: \.offset) { _, event in
|
|
HStack {
|
|
Text(event.kind)
|
|
Spacer()
|
|
if let duration = event.durationMs {
|
|
Text("\(duration) ms").foregroundStyle(.secondary)
|
|
}
|
|
if let detail = event.detail {
|
|
Text(detail).foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
.font(.callout)
|
|
}
|
|
}
|
|
.frame(minHeight: 220)
|
|
}
|
|
.padding(20)
|
|
.frame(width: 620, height: 520)
|
|
.task {
|
|
await model.refresh()
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The diagnostics window controller.
|
|
@MainActor
|
|
final class DiagnosticsWindowController {
|
|
private let window: NSWindow
|
|
|
|
init(model: DiagnosticsViewModel, onCopy: @escaping @MainActor (String) -> Void) {
|
|
let window = NSWindow(
|
|
contentRect: NSRect(x: 0, y: 0, width: 620, height: 520),
|
|
styleMask: [.titled, .closable, .resizable],
|
|
backing: .buffered,
|
|
defer: false
|
|
)
|
|
self.window = window
|
|
window.title = String(localized: "Sprachmittler Diagnostics")
|
|
window.isReleasedWhenClosed = false
|
|
window.contentViewController = NSHostingController(
|
|
rootView: DiagnosticsView(model: model, onCopy: onCopy)
|
|
)
|
|
window.center()
|
|
}
|
|
|
|
func show() {
|
|
NSApp.activate(ignoringOtherApps: true)
|
|
window.makeKeyAndOrderFront(nil)
|
|
}
|
|
}
|