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
+207 -138

No files matched your search

+67 -18
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) {
Ok(settings) => {
self.form.apply(&settings);
self.settings = Some(settings);
(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),
}
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)
// The draft carries the encoder this machine settled on, which is what a save keeps.
let name = app
.settings
.as_ref()
.map(|_| app.form.draft.video.encoder_preset.label().to_string())
.or_else(|| {
app.settings
.as_ref()
.map(|settings| settings.video.encoder_preset.label().to_string())
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")),