Files
sst/Sources/Sst/Sidebar.swift
T

64 lines
2.2 KiB
Swift

import SstUI
import SwiftUI
struct Sidebar: View {
@EnvironmentObject private var model: AppModel
var body: some View {
VStack(alignment: .leading, spacing: Layout.panelGap) {
SilkLabel(AppIdentity.brandCaption)
ForEach(AppModel.Section.allCases) { section in
Button {
model.section = section
} label: {
Text(title(for: section)).frame(maxWidth: .infinity)
}
.buttonStyle(KeyButtonStyle(latched: model.section == section))
}
Spacer()
ControlsBlock()
}
.padding(Layout.panelPadding)
.frame(width: Layout.sidebarWidth)
}
private func title(for section: AppModel.Section) -> String {
switch section {
case .transcripts: Strings.transcripts
case .dictionary: Strings.dictionary
}
}
}
/// Four lamps: the three macOS permissions and the speech model.
struct ControlsBlock: View {
@EnvironmentObject private var model: AppModel
var body: some View {
VStack(alignment: .leading, spacing: Space.s3) {
SilkLabel(Strings.controls)
SeamDivider()
ForEach(PermissionMonitor.Kind.allCases) { kind in
let granted = model.permissions.isGranted(kind)
HStack(spacing: Space.s3) {
LampView(isOn: granted, tint: .amber)
Text(kind.title).textStyle(Typography.meta).foregroundStyle(Palette.inkSecondary)
Spacer()
if !granted {
Button(Strings.open) { model.permissions.openSettings(for: kind) }
.buttonStyle(KeyButtonStyle())
.help(Strings.openSystemSettings)
}
}
}
HStack(spacing: Space.s3) {
LampView(isOn: model.modelReady, tint: .amber)
Text(Strings.modelLamp).textStyle(Typography.meta).foregroundStyle(Palette.inkSecondary)
Spacer()
}
}
.onAppear { model.permissions.startPolling() }
.onDisappear { model.permissions.stopPolling() }
}
}