Phase 0: menu-bar scaffold, permissions, backend health check
Native SwiftUI menu-bar app (LSUIElement, macOS 13+), generated from project.yml via XcodeGen. Includes: - PermissionsManager (Microphone / Screen Recording / Accessibility) + UI - SparkControlHealth: GET /api/status over self-signed TLS (InsecureTrustDelegate) - AppSettings persistence (host, TLS-skip, output folder, adapter toggles) - Menu-bar panel + Settings, app sandbox & hardened runtime off (LAN tool)
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
|
||||
/// The menu-bar panel: permission statuses, backend health, and a link to
|
||||
/// Settings. Shown when the user clicks the status-bar item.
|
||||
struct MenuBarView: View {
|
||||
@EnvironmentObject private var settings: AppSettings
|
||||
@EnvironmentObject private var permissions: PermissionsManager
|
||||
@EnvironmentObject private var health: SparkControlHealth
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
header
|
||||
Divider()
|
||||
permissionsSection
|
||||
Divider()
|
||||
backendSection
|
||||
Divider()
|
||||
footer
|
||||
}
|
||||
.padding(14)
|
||||
.frame(width: 320)
|
||||
}
|
||||
.onAppear { permissions.refresh() }
|
||||
.task { await refreshHealth() }
|
||||
}
|
||||
|
||||
private var header: some View {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("Ten31 Transcripts").font(.headline)
|
||||
Text("Phase 0 · setup & status")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
private var permissionsSection: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Permissions").font(.subheadline).bold()
|
||||
PermissionRow(
|
||||
title: "Microphone",
|
||||
state: permissions.microphone,
|
||||
onGrant: permissions.requestMicrophone,
|
||||
onOpenSettings: { permissions.openSettings(.microphone) }
|
||||
)
|
||||
PermissionRow(
|
||||
title: "Screen Recording",
|
||||
state: permissions.screenRecording,
|
||||
onGrant: permissions.requestScreenRecording,
|
||||
onOpenSettings: { permissions.openSettings(.screenRecording) }
|
||||
)
|
||||
PermissionRow(
|
||||
title: "Accessibility",
|
||||
state: permissions.accessibility,
|
||||
onGrant: permissions.requestAccessibility,
|
||||
onOpenSettings: { permissions.openSettings(.accessibility) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private var backendSection: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
Text("Backend").font(.subheadline).bold()
|
||||
Spacer()
|
||||
Button("Check") { Task { await refreshHealth() } }
|
||||
.disabled(health.status == .checking)
|
||||
}
|
||||
Text(settings.backendBaseURL)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.middle)
|
||||
HStack(spacing: 8) {
|
||||
StatusDot(color: healthColor)
|
||||
Text(healthText).font(.caption)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var footer: some View {
|
||||
HStack {
|
||||
NavigationLink("Settings…") {
|
||||
SettingsView()
|
||||
}
|
||||
Spacer()
|
||||
Button("Quit") { NSApplication.shared.terminate(nil) }
|
||||
}
|
||||
}
|
||||
|
||||
private func refreshHealth() async {
|
||||
await health.check(
|
||||
baseURL: settings.backendBaseURL,
|
||||
skipTLS: settings.skipTLSVerification
|
||||
)
|
||||
}
|
||||
|
||||
private var healthColor: Color {
|
||||
switch health.status {
|
||||
case .online: return .green
|
||||
case .offline: return .red
|
||||
case .checking: return .orange
|
||||
case .unknown: return .gray
|
||||
}
|
||||
}
|
||||
|
||||
private var healthText: String {
|
||||
switch health.status {
|
||||
case .unknown: return "Not checked yet"
|
||||
case .checking: return "Checking…"
|
||||
case .online(let detail): return "Online · \(detail)"
|
||||
case .offline(let error): return "Offline · \(error)"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Small status indicator dot.
|
||||
struct StatusDot: View {
|
||||
let color: Color
|
||||
var body: some View {
|
||||
Circle().fill(color).frame(width: 9, height: 9)
|
||||
}
|
||||
}
|
||||
|
||||
/// One permission line: status dot, label, and a context-appropriate action.
|
||||
struct PermissionRow: View {
|
||||
let title: String
|
||||
let state: PermissionState
|
||||
let onGrant: () -> Void
|
||||
let onOpenSettings: () -> Void
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 8) {
|
||||
StatusDot(color: dotColor)
|
||||
Text(title)
|
||||
Spacer()
|
||||
actionButton
|
||||
}
|
||||
}
|
||||
|
||||
private var dotColor: Color {
|
||||
switch state {
|
||||
case .granted: return .green
|
||||
case .denied: return .red
|
||||
case .notDetermined: return .orange
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var actionButton: some View {
|
||||
switch state {
|
||||
case .granted:
|
||||
Image(systemName: "checkmark.circle.fill").foregroundStyle(.green)
|
||||
case .notDetermined:
|
||||
// Native prompt (Microphone). The request also registers the app.
|
||||
Button("Grant", action: onGrant)
|
||||
case .denied:
|
||||
// Screen Recording / Accessibility report binary granted/denied, so
|
||||
// "not yet asked" looks like denied. "Grant" calls the request API,
|
||||
// which registers the app in the relevant list and shows the system
|
||||
// prompt the first time; "Open Settings" is the manual fallback.
|
||||
HStack(spacing: 6) {
|
||||
Button("Grant", action: onGrant)
|
||||
Button("Open Settings", action: onOpenSettings)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
|
||||
/// Settings panel (pushed from the menu-bar panel).
|
||||
struct SettingsView: View {
|
||||
@EnvironmentObject private var settings: AppSettings
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section("SparkControl backend") {
|
||||
TextField("Base URL", text: $settings.backendBaseURL)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
Toggle("Skip TLS verification (self-signed cert)",
|
||||
isOn: $settings.skipTLSVerification)
|
||||
}
|
||||
|
||||
Section("Output") {
|
||||
HStack {
|
||||
Text(settings.outputFolderPath)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.middle)
|
||||
.foregroundStyle(.secondary)
|
||||
Spacer()
|
||||
Button("Choose…", action: chooseFolder)
|
||||
}
|
||||
}
|
||||
|
||||
Section("Adapters") {
|
||||
Text("Inert in Phase 0 — these toggles only persist for now.")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
ForEach(AppSettings.adapterKeys, id: \.key) { adapter in
|
||||
Toggle(adapter.label, isOn: binding(for: adapter.key))
|
||||
}
|
||||
}
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
.frame(width: 320)
|
||||
.navigationTitle("Settings")
|
||||
}
|
||||
|
||||
private func binding(for key: String) -> Binding<Bool> {
|
||||
Binding(
|
||||
get: { settings.adapterEnabled[key] ?? true },
|
||||
set: { settings.adapterEnabled[key] = $0 }
|
||||
)
|
||||
}
|
||||
|
||||
private func chooseFolder() {
|
||||
let panel = NSOpenPanel()
|
||||
panel.canChooseDirectories = true
|
||||
panel.canChooseFiles = false
|
||||
panel.allowsMultipleSelection = false
|
||||
panel.prompt = "Choose"
|
||||
panel.directoryURL = settings.outputFolderURL
|
||||
|
||||
// The app is a menu-bar accessory and this is invoked from the transient
|
||||
// MenuBarExtra(.window) popover. Use the async begin(...) API rather than
|
||||
// runModal() — a nested modal loop can let the popover dismiss the panel
|
||||
// out from under it. Activate first so the panel comes to the front.
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
panel.begin { response in
|
||||
guard response == .OK, let url = panel.url else { return }
|
||||
settings.outputFolderPath = url.path
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user