app: offer the encoders this machine has and save from the tab

The encoder picker listed every kind the daemon knows, so a machine with
an AMD card could choose NVENC and only find out when a recording failed
to start. The list now holds what the encoder probe reports as present,
hardware before software, and a saved preset the machine cannot run
switches to the first one with a note saying so.

Recording drops the hardware acceleration switch and the frame rate
field. Both were decided by the encoder and the quality preset, and the
switch in particular changed nothing the daemon reads.

The tab lists the audio sources it will mix, so the game, the microphone
and the added applications are visible without opening the Audio tab,
and the open folder button sits at the right of the recording folder
row where the other rows keep their controls.

Save now writes. The reply to updateSettings carries no settings, which
parsed into a set of defaults and started the screen over; a reply
without them is an error instead. The button shows Saving while the
round trip runs and the form goes clean only once the daemon has the
values.
This commit is contained in:
vhaudiquet committed 2026-11-16 22:20:39 +01:00
1 parent c7fee5beeb
commit 976fcdc354
3 files changed
+178 -109

No files matched your search

+63 -14
View File
@@ -69,7 +69,6 @@ pub struct Encoders {
#[derive(Debug, Clone, serde::Deserialize)]
pub struct EncoderInfo {
pub id: String,
pub name: String,
#[serde(default)]
pub is_hardware: bool,
#[serde(default)]
@@ -217,7 +216,6 @@ impl App {
self.encoders = Encoders {
available: vec![EncoderInfo {
id: "jim_nvenc".into(),
name: "NVIDIA NVENC".into(),
available: true,
is_hardware: true,
}],
@@ -281,6 +279,47 @@ impl App {
self.daemon.get_settings();
}
/// The encoders this machine can run, as the daemon found them, hardware first.
pub fn runnable_encoders(&self) -> Vec<&'static str> {
let mut found: Vec<(&'static str, bool)> = self
.encoders
.available
.iter()
.filter(|encoder| encoder.available)
.filter_map(|encoder| {
let label = crate::settings::EncoderPreset::encoder_name(&encoder.id)?;
Some((label, encoder.is_hardware))
})
.collect();
// Hardware first: it is the choice most people want, and the fallback below uses the
// first entry.
found.sort_by_key(|(_, hardware)| !hardware);
found.into_iter().map(|(label, _)| label).collect()
}
/// Point the draft at an encoder this machine has when the stored one is missing.
///
/// A config written elsewhere can name NVENC on a card that has none. The daemon's encoder
/// list is this machine's own answer, so the draft follows it, and saving keeps it.
fn settle_encoder(&mut self) {
if !self.form.loaded || self.form.dirty {
return;
}
let runnable = self.runnable_encoders();
let Some(pick) = runnable.first() else {
return;
};
let current = self.form.draft.video.encoder_preset.label();
if runnable.contains(&current) {
return;
}
self.form.draft.video.encoder_preset = self.form.draft.video.encoder_preset.with_kind(pick);
self.form.dirty = true;
self.notify(format!(
"{current} is not on this machine; recording will use {pick}"
));
}
/// The process names the audio sources refer to, plus whatever is being typed into the
/// add dialog.
fn watch_names(&self) -> Vec<String> {
@@ -450,19 +489,27 @@ impl App {
self.connected = false;
self.notify_error(e);
}
(
ipc::Request::Settings
| ipc::Request::SaveSettings
| ipc::Request::ResetSettings,
Ok(data),
) => match crate::settings::from_response(&data) {
(ipc::Request::Settings | ipc::Request::ResetSettings, Ok(data)) => {
match crate::settings::from_response(&data) {
Ok(settings) => {
self.form.apply(&settings);
self.settings = Some(settings);
self.settle_encoder();
}
Err(e) => self.notify_error(e),
},
}
}
// The daemon answers a save with `{"success": true}`; the draft is already what
// it holds, so there is nothing to read back.
(ipc::Request::SaveSettings, Ok(_)) => {
self.settings = Some(self.form.settings());
self.form.saving = false;
self.form.dirty = false;
self.form.loaded = true;
self.notify("Settings saved");
}
(ipc::Request::SaveSettings, Err(e)) => {
self.form.saving = false;
self.notify_error(format!("Settings were not saved: {e}"))
}
(ipc::Request::ResetSettings, Err(e)) => {
@@ -483,6 +530,7 @@ impl App {
(ipc::Request::Encoders, Ok(data)) => {
if let Ok(list) = serde_json::from_value(data) {
self.encoders = list;
self.settle_encoder();
}
}
(ipc::Request::AudioDevices, Ok(data)) => {
@@ -653,12 +701,13 @@ fn status_color(p: Paint, app: &App) -> (rune::Color, String) {
/// The thin bar under the screens: daemon state on the left, the encoder on the right.
fn statusbar(p: Paint, app: &App) -> El {
let (dot_color, status) = status_color(p, app);
let name = crate::settings::EncoderPreset::encoder_name(&app.encoders.current)
.map(str::to_string)
.or_else(|| {
app.settings
// The draft carries the encoder this machine settled on, which is what a save keeps.
let name = app
.settings
.as_ref()
.map(|settings| settings.video.encoder_preset.label().to_string())
.map(|_| app.form.draft.video.encoder_preset.label().to_string())
.or_else(|| {
crate::settings::EncoderPreset::encoder_name(&app.encoders.current).map(str::to_string)
});
let recording = match (name, app.settings.as_ref().map(|s| s.video.frame_rate)) {
(Some(name), Some(fps)) => Some(format!("{name} · {fps} fps")),
+93 -89
View File
@@ -17,7 +17,6 @@ pub struct Form {
pub open_select: Option<&'static str>,
pub path: TextEdit,
pub naming: TextEdit,
pub frame_rate: TextEdit,
pub split_size: TextEdit,
pub split_time: TextEdit,
pub poll_interval: TextEdit,
@@ -33,7 +32,6 @@ impl Form {
Self {
path: TextEdit::new(&draft.output.path),
naming: TextEdit::new(&draft.output.naming_pattern),
frame_rate: TextEdit::new(draft.video.frame_rate.to_string()),
split_size: TextEdit::new(draft.output.split_size_mb.to_string()),
split_time: TextEdit::new(draft.output.split_time_minutes.to_string()),
poll_interval: TextEdit::new(draft.daemon.poll_interval_ms.to_string()),
@@ -57,8 +55,6 @@ impl Form {
self.draft = settings.clone();
self.path.replace_text(&settings.output.path);
self.naming.replace_text(&settings.output.naming_pattern);
self.frame_rate
.replace_text(settings.video.frame_rate.to_string());
self.split_size
.replace_text(settings.output.split_size_mb.to_string());
self.split_time
@@ -77,13 +73,6 @@ impl Form {
let mut out = self.draft.clone();
out.output.path = self.path.text.trim().to_string();
out.output.naming_pattern = self.naming.text.trim().to_string();
out.video.frame_rate = self
.frame_rate
.text
.trim()
.parse()
.unwrap_or(60)
.clamp(1, 240);
out.output.split_size_mb = self.split_size.text.trim().parse().unwrap_or(0);
out.output.split_time_minutes = self.split_time.text.trim().parse().unwrap_or(0);
out.daemon.poll_interval_ms = self
@@ -271,6 +260,7 @@ pub fn view(app: &App, p: Paint) -> El {
if !app.form.loaded {
return;
}
app.form.saving = true;
let settings = app.form.settings();
match serde_json::to_value(&settings) {
Ok(value) => app.daemon.save_settings(value),
@@ -303,6 +293,8 @@ pub fn view(app: &App, p: Paint) -> El {
fn save_label(app: &App, p: Paint) -> (String, rune::Color) {
if !app.connected {
("Daemon offline".into(), p.danger)
} else if app.form.saving {
("Saving\u{2026}".into(), p.muted())
} else if app.form.dirty {
("Unsaved changes".into(), p.warning)
} else if app.form.loaded {
@@ -397,24 +389,10 @@ fn quick(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, content:
},
)],
))
.child(ui::card(
.child(ui::card_action(
p,
Some("Files"),
vec![
ui::setting_row(
p,
"recordings-folder",
"Recordings folder",
text(short_path(&app.form.draft.output.path))
.key("path")
.font(body(12.0))
.color(p.muted()),
),
row()
.key("files-actions")
.px(space::S3)
.pb(space::S2)
.child(ui::button(
Some(ui::button(
p,
"open-recordings",
"Open folder",
@@ -423,11 +401,18 @@ fn quick(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, content:
crate::daemon::open_folder(&crate::daemon::recordings_dir());
},
)),
],
vec![ui::setting_row(
p,
"recordings-folder",
"Recordings folder",
text(short_path(&app.form.draft.output.path))
.key("path")
.font(body(12.0))
.color(p.muted()),
)],
))
}
/// A path as it fits on a row: the last two segments, with the rest elided.
/// A path as it fits on a row: the last two segments, with the rest elided.
fn short_path(path: &str) -> String {
let sep = std::path::MAIN_SEPARATOR;
@@ -442,35 +427,35 @@ fn short_path(path: &str) -> String {
fn recording(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, content: El) -> El {
let v = &app.form.draft.video;
let a = &app.form.draft.audio;
let o = &app.form.draft.output;
let available = if app.encoders.available.is_empty() {
String::new()
// Only the encoders this machine reports are offered. The static list stands in until the
// daemon has answered.
let offered = app.runnable_encoders();
let encoders: Vec<&str> = if offered.is_empty() {
ENCODERS.to_vec()
} else {
app.encoders
.available
.iter()
.filter(|e| e.available)
.map(|e| {
let kind = if e.is_hardware {
"hardware"
} else {
"software"
offered
};
format!("{} ({}, {kind})", e.name, e.id)
})
.collect::<Vec<_>>()
.join(", ")
};
let mut video_rows = vec![
// The stored encoder is shown as it is, even when this machine cannot run it, so the row
// never claims something the daemon does not hold.
let encoder = Some(v.encoder_preset.label().to_string());
content
.child(ui::card(
p,
Some("Video"),
vec![
select_row(
p,
kit,
layer,
"encoder",
"Encoder",
"Hardware encoding is faster; x264 uses the CPU",
&ENCODERS,
Some(v.encoder_preset.label().to_string()),
"The encoders this machine can run",
&encoders,
encoder,
app,
),
select_row(
@@ -484,41 +469,20 @@ fn recording(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, cont
Some(v.quality.label().to_string()),
app,
),
text_row(
p,
"frame-rate",
"Frame rate",
"Frames per second the daemon records",
&app.form.frame_rate,
|app| &mut app.form.frame_rate,
),
ui::toggle_row(
p,
"hardware",
"Hardware acceleration",
v.hardware_acceleration,
|app: &mut App| {
app.form.draft.video.hardware_acceleration ^= true;
app.form.dirty = true;
},
),
];
if !available.is_empty() {
video_rows.push(
text(format!("Available on this machine: {available}"))
.key("encoder-note")
.font(body(11.0))
.color(p.muted())
.ml(space::S3)
.mb(6.0),
);
}
content
.child(ui::card(p, Some("Video"), video_rows))
.child(ui::card(
],
))
.child(ui::card_action(
p,
Some("Output"),
Some(ui::button(
p,
"open-output",
"Open folder",
false,
|_app: &mut App| {
crate::daemon::open_folder(&crate::daemon::recordings_dir());
},
)),
vec![
text_row(
p,
@@ -565,15 +529,55 @@ fn recording(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, cont
),
],
))
.child(row().key("recording-actions").gap(8.0).child(ui::button(
.child(ui::card(
p,
"open-output",
"Open recordings folder",
false,
|_app: &mut App| {
crate::daemon::open_folder(&crate::daemon::recordings_dir());
Some("Audio"),
vec![
ui::toggle_row(
p,
"rec-game",
"Game audio",
a.enabled && a.capture_game,
|app: &mut App| {
let on =
!(app.form.draft.audio.enabled && app.form.draft.audio.capture_game);
app.form.draft.audio.enabled = on;
app.form.draft.audio.capture_game = on;
app.form.dirty = true;
},
)))
),
ui::toggle_row(
p,
"rec-mic",
"Microphone",
a.capture_mic,
|app: &mut App| {
app.form.draft.audio.capture_mic ^= true;
app.form.dirty = true;
},
),
mic_row(p, kit, layer, app, "rec-mic-device"),
ui::setting_row_with(
p,
"rec-apps",
"Applications",
&source_summary(&a.capture_apps),
ui::button(p, "edit-apps", "Edit", false, |app: &mut App| {
app.settings_tab = SettingsTab::Audio;
}),
),
],
))
}
/// The applications a clip takes sound from, as one line.
fn source_summary(sources: &[AudioSource]) -> String {
match sources.len() {
0 => "None yet".to_string(),
1 => sources[0].name.clone(),
2 => format!("{} and {}", sources[0].name, sources[1].name),
n => format!("{} and {} more", sources[0].name, n - 1),
}
}
/// The microphone picker: the system default plus every input device the daemon reports.
+22 -6
View File
@@ -116,7 +116,7 @@ impl EncoderPreset {
| EncoderPreset::X264 { bitrate, .. } => *bitrate,
};
match kind {
"amf" | "AMD AMF" => EncoderPreset::Amf {
"amf" | "AMD AMF" | "amd_amf_h264" => EncoderPreset::Amf {
bitrate,
quality: AmfQuality::Balanced,
},
@@ -362,12 +362,17 @@ fn volume() -> u32 {
}
/// Split the daemon's `{ settings: {...} }` wrapper.
///
/// Every field of [`Settings`] has a default, so a reply that carries no settings at all
/// (`{"success": true}`, the answer to `updateSettings`) would parse into the defaults and
/// quietly replace what the user has. The daemon always writes the `video` key, and a reply
/// without it is an error.
pub fn from_response(data: &serde_json::Value) -> Result<Settings, String> {
let inner = data
.get("settings")
.cloned()
.unwrap_or_else(|| data.clone());
serde_json::from_value(inner).map_err(|e| format!("settings did not parse: {e}"))
let inner = data.get("settings").unwrap_or(data);
if inner.get("video").is_none() {
return Err("the daemon's reply carries no settings".to_string());
}
serde_json::from_value(inner.clone()).map_err(|e| format!("settings did not parse: {e}"))
}
#[cfg(test)]
@@ -406,6 +411,12 @@ mod tests {
assert!(from_response(&bare).is_ok());
}
#[test]
fn a_reply_without_settings_is_an_error() {
let replied = json!({"success": true});
assert!(from_response(&replied).is_err());
}
#[test]
fn an_encoder_keeps_its_bitrate_when_it_changes_kind() {
let preset = EncoderPreset::X264 {
@@ -417,6 +428,11 @@ mod tests {
assert_eq!(nvenc.encoder_id(), "jim_nvenc");
assert_eq!(nvenc.bitrate(), 9000);
assert_eq!(preset.with_kind("amf").encoder_id(), "amd_amf_h264");
assert_eq!(
preset.with_kind("amd_amf_h264").encoder_id(),
"amd_amf_h264"
);
assert_eq!(preset.with_kind("x264").encoder_id(), "x264");
}
#[test]