forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioSourceSelector.swift
More file actions
104 lines (92 loc) · 2.87 KB
/
Copy pathAudioSourceSelector.swift
File metadata and controls
104 lines (92 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import OmiTheme
import SwiftUI
/// Audio source selector for the macOS capture path.
struct AudioSourceSelector: View {
@ObservedObject var appState: AppState
var body: some View {
HStack(spacing: OmiSpacing.md) {
audioSourceButton(
source: .microphone,
isSelected: true,
isAvailable: true
)
}
.onAppear {
guard appState.audioSource != .microphone else { return }
appState.audioSource = .microphone
}
}
private func audioSourceButton(
source: AudioSource,
isSelected: Bool,
isAvailable: Bool
) -> some View {
Button(action: {
guard isAvailable && !appState.isTranscribing else { return }
appState.audioSource = source
}) {
HStack(spacing: OmiSpacing.sm) {
Image(systemName: source.iconName)
.scaledFont(size: OmiType.body)
VStack(alignment: .leading, spacing: OmiSpacing.hairline) {
Text(source.displayName)
.scaledFont(size: OmiType.body, weight: .medium)
Text(AudioCaptureService.getCurrentMicrophoneName() ?? "Default")
.scaledFont(size: OmiType.caption)
.foregroundColor(Ink.secondary)
.lineLimit(1)
}
Spacer()
if isSelected {
Image(systemName: "checkmark.circle.fill")
.foregroundColor(Ink.accent)
}
}
.padding(.horizontal, OmiSpacing.md)
.padding(.vertical, OmiSpacing.sm)
.background(
RoundedRectangle(cornerRadius: OmiChrome.smallControlRadius)
.fill(isSelected ? Ink.accent.opacity(0.15) : Ink.rowFillHover.opacity(0.5))
.overlay(
RoundedRectangle(cornerRadius: OmiChrome.smallControlRadius)
.stroke(isSelected ? Ink.accent : Color.clear, lineWidth: 1.5)
)
)
.foregroundColor(isAvailable ? Ink.primary : Ink.secondary)
.opacity(isAvailable ? 1.0 : 0.5)
}
.buttonStyle(.plain)
.disabled(!isAvailable || appState.isTranscribing)
}
}
/// Compact audio source indicator for display in headers
struct AudioSourceIndicator: View {
@ObservedObject var appState: AppState
var body: some View {
HStack(spacing: OmiSpacing.xs) {
Image(systemName: AudioSource.microphone.iconName)
.scaledFont(size: OmiType.caption)
.foregroundColor(Ink.accent)
Text("Mic")
.scaledFont(size: OmiType.caption, weight: .medium)
.foregroundColor(Ink.secondary)
}
.padding(.horizontal, OmiSpacing.sm)
.padding(.vertical, OmiSpacing.xxs)
.background(
Capsule()
.fill(Ink.rowFillHover.opacity(0.5))
)
}
}
// MARK: - Preview
#if canImport(PreviewsMacros)
#Preview("Audio Source Selector") {
VStack(spacing: OmiSpacing.xl) {
AudioSourceSelector(appState: AppState())
AudioSourceIndicator(appState: AppState())
}
.padding()
.background(Ink.surface)
}
#endif