-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourcePicker.swift
More file actions
56 lines (50 loc) · 1.9 KB
/
Copy pathSourcePicker.swift
File metadata and controls
56 lines (50 loc) · 1.9 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
import SwiftUI
/// Lets the user choose whether to record all system audio or just one app.
/// Shared by the main window and the menu-bar panel.
struct SourcePicker: View {
@ObservedObject var model: RecorderModel
var body: some View {
HStack(spacing: 6) {
Image(systemName: isApp ? "app.dashed" : "speaker.wave.2.fill")
.foregroundStyle(.secondary)
.frame(width: 16)
Picker("Record from", selection: Binding(
get: { model.source },
set: { model.selectSource($0) })) {
Text("All system audio").tag(AudioSource.system)
if !options.isEmpty {
Divider()
ForEach(options) { app in
Text(app.name).tag(AudioSource.app(bundleID: app.bundleID))
}
}
}
.labelsHidden()
.disabled(model.isRecording)
Button {
Task { await model.refreshApps() }
} label: {
Image(systemName: "arrow.clockwise")
}
.buttonStyle(.borderless)
.help("Refresh the list of running apps")
.disabled(model.isRecording)
}
.task { await model.refreshApps() }
}
private var isApp: Bool {
if case .app = model.source { return true }
return false
}
/// The pickable apps, guaranteeing the currently-selected app is present even
/// if it isn't running right now (so the picker still shows its name).
private var options: [AudioApp] {
var list = model.availableApps
if case .app(let bid) = model.source,
!list.contains(where: { $0.bundleID == bid }) {
let name = (model.sourceName ?? bid) + " (not running)"
list.insert(AudioApp(bundleID: bid, name: name), at: 0)
}
return list
}
}