Files
leaguerecorder/app/src/screens/settings.rs
T
vhaudiquet c7fee5beeb app: add applications from a dialog, with icons and a running state
The add row under the sources offered a type selector for device
sources, which the daemon cannot capture reliably, and nothing told a
right process name from a wrong one. A plus in the card header now
opens a dialog asking for a name and a process, and Add stays grey
until both are filled.

Every source shows its executable's icon, read from the running
process or found on disk when the program is closed, and a chip saying
whether that process is running. The process table is read off the UI
thread every couple of seconds while the audio tab is open, and the
disk search remembers its misses so a name costs one walk per run.

Settings drops Refresh and Settings from the title bar, where both only
repeated what the screen already shows.
2026-11-16 20:01:59 +01:00

1141 lines
37 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! Settings: a quick tab of everyday choices, then recording, audio and the daemon.
use rune::tok::{radius, space, type_};
use rune::{Color, El, TextEdit, col, el, row, text};
use rune_kit::Select;
use crate::app::{App, SettingsTab};
use crate::settings::{AudioSource, AudioSourceType, Quality, Settings};
use crate::ui::{self, Paint, body, heading};
/// The daemon's settings plus the text fields the user is typing into.
pub struct Form {
pub draft: Settings,
pub loaded: bool,
pub dirty: bool,
pub saving: bool,
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,
pub bitrate: TextEdit,
pub source_name: TextEdit,
pub source_device: TextEdit,
pub add_open: bool,
}
impl Form {
pub fn empty() -> Self {
let draft = Settings::default();
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()),
bitrate: TextEdit::new(draft.audio.bitrate.to_string()),
source_name: TextEdit::new(""),
source_device: TextEdit::new(""),
add_open: false,
draft,
loaded: false,
dirty: false,
saving: false,
open_select: None,
}
}
/// Take the daemon's copy. Unsaved edits are kept unless `force`.
pub fn apply(&mut self, settings: &Settings) {
if self.dirty && self.loaded {
return;
}
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
.replace_text(settings.output.split_time_minutes.to_string());
self.poll_interval
.replace_text(settings.daemon.poll_interval_ms.to_string());
self.bitrate
.replace_text(settings.audio.bitrate.to_string());
self.loaded = true;
self.dirty = false;
self.saving = false;
}
/// Pull the text fields into the draft and hand it to `updateSettings`.
pub fn settings(&mut self) -> Settings {
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
.poll_interval
.text
.trim()
.parse()
.unwrap_or(1000)
.max(100);
out.audio.bitrate = self
.bitrate
.text
.trim()
.parse()
.unwrap_or(160)
.clamp(32, 320);
out
}
/// Open the add-application dialog on empty fields.
pub fn open_add(&mut self) {
self.add_open = true;
self.open_select = None;
self.source_name = TextEdit::new("");
self.source_device = TextEdit::new("");
}
/// Close the add-application dialog, whatever was typed.
pub fn close_add(&mut self) {
self.add_open = false;
}
pub fn choose(&mut self, key: &str, value: &str) {
match key {
"encoder" => {
self.draft.video.encoder_preset = self.draft.video.encoder_preset.with_kind(value)
}
"quality" => {
self.draft.video.quality = match value {
"Low" => Quality::Low,
"Medium" => Quality::Medium,
"Ultra" => Quality::Ultra,
_ => Quality::High,
}
}
"container" => self.draft.output.container = value.to_ascii_lowercase(),
"log-level" => self.draft.daemon.log_level = value.to_ascii_lowercase(),
"mic-device" => self.draft.audio.mic_device = Some(value.to_string()),
_ => {}
}
self.dirty = true;
}
}
const ENCODERS: [&str; 3] = ["NVIDIA NVENC", "AMD AMF", "x264 (Software)"];
const QUALITIES: [&str; 4] = ["Low", "Medium", "High", "Ultra"];
const CONTAINERS: [&str; 4] = ["mp4", "mkv", "mov", "flv"];
const LOG_LEVELS: [&str; 5] = ["trace", "debug", "info", "warn", "error"];
/// A row with a single-line field on the right.
fn text_row(
p: Paint,
key: &'static str,
label: &str,
hint: &str,
edit: &TextEdit,
to: fn(&mut App) -> &mut TextEdit,
) -> El {
ui::setting_row_with(p, key, label, hint, ui::text_field(p, key, label, edit, to))
}
#[allow(clippy::too_many_arguments)] // the columns of a settings row
fn select_row(
p: Paint,
kit: &rune_kit::Kit,
layer: &mut Vec<El>,
key: &'static str,
label: &str,
hint: &str,
options: &[&str],
current: Option<String>,
app: &App,
) -> El {
let open = app.form.open_select == Some(key);
let control = Select::new(key, options)
.current(current.as_deref())
.open(open)
.label(label)
.width(220.0)
.on_toggle(move |app: &mut App| {
app.form.open_select = if app.form.open_select == Some(key) {
None
} else {
Some(key)
};
})
.on_close(move |app: &mut App| app.form.open_select = None)
.on_choose(move |app: &mut App, value: &str, _: &mut rune::Tx| {
app.form.choose(key, value);
app.form.open_select = None;
})
.build(kit, layer);
ui::setting_row_with(p, key, label, hint, control)
}
fn tabs(p: Paint, app: &App) -> El {
let mut row = row().key("tabs").gap(4.0).center_y();
for (tab, label) in [
(SettingsTab::Quick, "Quick"),
(SettingsTab::Recording, "Recording"),
(SettingsTab::Audio, "Audio"),
(SettingsTab::Advanced, "Advanced"),
] {
row = row.child(ui::tab(
p,
label,
label,
app.settings_tab == tab,
move |app: &mut App| {
app.settings_tab = tab;
app.form.open_select = None;
},
));
}
row
}
pub fn view(app: &App, p: Paint) -> El {
let kit = rune_kit::Kit::neutral(app.dark);
let mut layer = Vec::new();
let (save_text, save_ink) = save_label(app, p);
// The scroll bar gets its own strip at the end, clear of the cards.
let content = col()
.key("tab-content")
.w_full()
.gap(20.0)
.pb(space::S6)
.pr(14.0);
let content = match app.settings_tab {
SettingsTab::Quick => quick(app, p, &kit, &mut layer, content),
SettingsTab::Recording => recording(app, p, &kit, &mut layer, content),
SettingsTab::Audio => audio(app, p, &kit, &mut layer, content),
SettingsTab::Advanced => advanced(app, p, &kit, &mut layer, content),
};
let body = col()
.key("settings")
.w_full()
.h_full()
.padding(space::S6)
.gap(16.0)
.child(
row()
.key("header")
.w_full()
.justify_between()
.center_y()
.child(
text("Settings")
.key("title")
.font(heading(20.0))
.color(p.t.text),
)
.child(
row()
.key("save-actions")
.gap(8.0)
.center_y()
.child(
row().key("save-state").mr(4.0).center_y().child(
text(save_text)
.key("save-label")
.font(body(11.5))
.color(save_ink),
),
)
.child(ui::button(p, "revert", "Revert", false, |app: &mut App| {
if let Some(settings) = app.settings.clone() {
app.form.dirty = false;
app.form.apply(&settings);
}
}))
.child(ui::button(p, "save", "Save", true, |app: &mut App| {
if !app.form.loaded {
return;
}
let settings = app.form.settings();
match serde_json::to_value(&settings) {
Ok(value) => app.daemon.save_settings(value),
Err(e) => {
app.notify_error(format!("settings did not serialize: {e}"))
}
}
})),
),
)
.child(tabs(p, app))
.child(
app.scroll.follow(
"scroller",
col()
.w_full()
.grow(1.0)
.min_h(0.0)
.scroll(rune::ScrollSpec {
stick_bottom: false,
})
.child(content),
),
)
.child(save_footer(p, app));
rune_kit::root(body, layer)
}
fn save_label(app: &App, p: Paint) -> (String, rune::Color) {
if !app.connected {
("Daemon offline".into(), p.danger)
} else if app.form.dirty {
("Unsaved changes".into(), p.warning)
} else if app.form.loaded {
("Saved".into(), p.muted())
} else {
("Loading".into(), p.muted())
}
}
/// The last line: where settings are written and when they take effect.
fn save_footer(p: Paint, _app: &App) -> El {
row().key("footer").w_full().center_y().child(
text("Settings are stored by the recorder and survive its restart.")
.key("footer-note")
.font(body(11.5))
.color(p.muted()),
)
}
/// The settings most people touch: how a clip looks, whether it has sound, and where it lands.
fn quick(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;
content
.child(
text("Recording starts on its own when a game begins, and the game shows up here when it ends.")
.key("quick-note")
.font(body(12.5))
.color(p.muted()),
)
.child(ui::card(
p,
Some("Recording"),
vec![
select_row(
p,
kit,
layer,
"quality",
"Quality",
v.quality.detail(),
&QUALITIES,
Some(v.quality.label().to_string()),
app,
),
ui::toggle_row(
p,
"quick-audio",
"Record 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,
"quick-mic",
"Record my microphone",
a.capture_mic,
|app: &mut App| {
app.form.draft.audio.capture_mic ^= true;
app.form.dirty = true;
},
),
mic_row(p, kit, layer, app, "quick-mic-device"),
],
))
.child(ui::card(
p,
Some("Startup"),
vec![ui::toggle_row(
p,
"autostart",
"Launch League Recorder at startup",
app.autostart,
|app: &mut App| {
let next = !app.autostart;
match crate::os::set_autostart(next) {
Ok(()) => {
app.autostart = next;
app.notify(if next {
"League Recorder will start with Windows"
} else {
"League Recorder will no longer start with Windows"
});
}
Err(e) => app.notify_error(e),
}
},
)],
))
.child(ui::card(
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(
p,
"open-recordings",
"Open folder",
false,
|_app: &mut App| {
crate::daemon::open_folder(&crate::daemon::recordings_dir());
},
)),
],
))
}
/// 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;
let normalized = path.replace(sep, "/");
let parts: Vec<&str> = normalized.split('/').filter(|p| !p.is_empty()).collect();
match parts.len() {
0 => path.to_string(),
1 | 2 => parts.join(&sep.to_string()),
n => format!("…{sep}{}{sep}{}", parts[n - 2], parts[n - 1]),
}
}
fn recording(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, content: El) -> El {
let v = &app.form.draft.video;
let o = &app.form.draft.output;
let available = if app.encoders.available.is_empty() {
String::new()
} else {
app.encoders
.available
.iter()
.filter(|e| e.available)
.map(|e| {
let kind = if e.is_hardware {
"hardware"
} else {
"software"
};
format!("{} ({}, {kind})", e.name, e.id)
})
.collect::<Vec<_>>()
.join(", ")
};
let mut video_rows = vec![
select_row(
p,
kit,
layer,
"encoder",
"Encoder",
"Hardware encoding is faster; x264 uses the CPU",
&ENCODERS,
Some(v.encoder_preset.label().to_string()),
app,
),
select_row(
p,
kit,
layer,
"quality",
"Quality",
v.quality.detail(),
&QUALITIES,
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(
p,
Some("Output"),
vec![
text_row(
p,
"output-path",
"Folder",
"Where finished recordings are written",
&app.form.path,
|app| &mut app.form.path,
),
text_row(
p,
"naming",
"File name",
"{date}, {time}, {champion} and {queue_type} are filled in",
&app.form.naming,
|app| &mut app.form.naming,
),
select_row(
p,
kit,
layer,
"container",
"Container",
"The file type recordings are saved as",
&CONTAINERS,
Some(o.container.clone()),
app,
),
text_row(
p,
"split-size",
"Split at size",
"Start a new file past this many MB (0 for never)",
&app.form.split_size,
|app| &mut app.form.split_size,
),
text_row(
p,
"split-time",
"Split at time",
"Start a new file after this many minutes (0 for never)",
&app.form.split_time,
|app| &mut app.form.split_time,
),
],
))
.child(row().key("recording-actions").gap(8.0).child(ui::button(
p,
"open-output",
"Open recordings folder",
false,
|_app: &mut App| {
crate::daemon::open_folder(&crate::daemon::recordings_dir());
},
)))
}
/// The microphone picker: the system default plus every input device the daemon reports.
fn mic_row(p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, app: &App, key: &'static str) -> El {
let devices = &app.devices.input_devices;
let current = app
.form
.draft
.audio
.mic_device
.as_ref()
.and_then(|id| devices.iter().find(|d| &d.id == id))
.map(|d| d.name.clone())
.unwrap_or_else(|| "System default".to_string());
let mut options = vec!["System default".to_string()];
options.extend(devices.iter().map(|d| d.name.clone()));
let names: Vec<&str> = options.iter().map(String::as_str).collect();
let open = app.form.open_select == Some(key);
let select = Select::new(key, &names)
.current(Some(&current))
.open(open)
.label("Microphone")
.width(220.0)
.on_toggle(move |app: &mut App| {
app.form.open_select = if app.form.open_select == Some(key) {
None
} else {
Some(key)
};
})
.on_close(|app: &mut App| app.form.open_select = None)
.on_choose(|app: &mut App, value: &str, _: &mut rune::Tx| {
app.form.draft.audio.mic_device = if value == "System default" {
None
} else {
app.devices
.input_devices
.iter()
.find(|d| d.name == value)
.map(|d| d.id.clone())
};
app.form.dirty = true;
app.form.open_select = None;
})
.build(kit, layer);
let hint = match devices.iter().find(|d| d.is_default) {
_ if devices.is_empty() => "The recorder sees no microphone".to_string(),
Some(d) => format!("System default is {}", d.name),
None => "What the recorder captures when the microphone is on".to_string(),
};
ui::setting_row_with(p, key, "Microphone", &hint, select)
}
fn audio(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, content: El) -> El {
let a = &app.form.draft.audio;
let mut sources = col().key("sources").gap(2.0);
if a.capture_apps.is_empty() {
sources = sources.child(
text("No applications yet. Add one and its audio joins the clip.")
.key("sources-empty")
.font(body(12.0))
.color(p.muted())
.ml(space::S3)
.h(36.0),
);
}
for (index, source) in a.capture_apps.iter().enumerate() {
sources = sources.child(source_row(app, p, index, source));
}
content
.child(ui::card(
p,
Some("Levels"),
vec![
ui::setting_row(
p,
"game-volume",
"Game volume",
ui::slider(
p,
"game-volume",
"Game volume",
a.game_volume,
|app, value| {
app.form.draft.audio.game_volume = value;
app.form.dirty = true;
},
),
),
ui::setting_row(
p,
"mic-volume",
"Microphone volume",
ui::slider(
p,
"mic-volume",
"Microphone volume",
a.mic_volume,
|app, value| {
app.form.draft.audio.mic_volume = value;
app.form.dirty = true;
},
),
),
ui::setting_row(
p,
"apps-volume",
"Applications volume",
ui::slider(
p,
"apps-volume",
"Applications volume",
a.apps_volume,
|app, value| {
app.form.draft.audio.apps_volume = value;
app.form.dirty = true;
},
),
),
],
))
.child(ui::card(
p,
Some("Microphone"),
vec![
ui::toggle_row(
p,
"capture-mic",
"Capture microphone",
a.capture_mic,
|app: &mut App| {
app.form.draft.audio.capture_mic ^= true;
app.form.dirty = true;
},
),
mic_row(p, kit, layer, app, "mic-device"),
],
))
.child(ui::card_action(
p,
Some("Applications"),
Some(ui::icon_button(
p,
"add-source",
"+",
"Add an application",
true,
|app: &mut App| app.form.open_add(),
)),
vec![sources],
))
}
/// One captured application: its icon, name, whether it is running, its volume and Remove.
fn source_row(app: &App, p: Paint, index: usize, source: &AudioSource) -> El {
let id = source.id.clone();
let volume = source.volume.unwrap_or(100);
let mut row = row()
.key(format!("source-{}", source.id))
.h(52.0)
.px(space::S3)
.center_y()
.gap(space::S3)
.child(ui::process_icon(app, p, &source.device, 24.0))
.child(
col()
.key("source-labels")
.grow(1.0)
.min_w(0.0)
.gap(1.0)
.child(
text(source.name.clone())
.key("name")
.font(type_::BODY)
.color(p.t.text)
.truncate(),
)
.child(
text(source_detail(source))
.key("detail")
.font(body(11.0))
.color(p.muted())
.truncate(),
),
);
// Only a process source can be looked up; a device source names a device instead.
if source.source_type == AudioSourceType::Application
&& let Some(found) = app
.processes
.get(&crate::process::normalize(&source.device))
{
row = row.child(ui::process_state(p, found.running, 88.0));
}
row.radius(radius::MD)
.child(ui::slider(
p,
format!("volume-{}", source.id),
"Application volume",
volume,
move |app: &mut App, value| {
let payload = {
let Some(source) = app.form.draft.audio.capture_apps.get_mut(index) else {
return;
};
source.volume = Some(value);
serde_json::to_value(&*source).ok()
};
app.form.dirty = true;
if let Some(payload) = payload {
app.daemon.update_audio_source(payload);
}
},
))
.child(ui::button(
p,
&format!("remove-{}", source.id),
"Remove",
false,
move |app: &mut App| {
app.daemon.remove_audio_source(&id);
},
))
}
/// What a source captures, under its name in the list.
fn source_detail(source: &AudioSource) -> String {
match source.source_type {
AudioSourceType::Application => source.device.clone(),
other => format!("{} · {}", other.label(), source.device),
}
}
/// Send the dialog's name and process to the daemon as a new application source.
fn submit_source(app: &mut App) {
let name = app.form.source_name.text.trim().to_string();
let device = app.form.source_device.text.trim().to_string();
if name.is_empty() || device.is_empty() {
return;
}
let source = AudioSource {
id: String::new(),
name,
source_type: AudioSourceType::Application,
device,
enabled: true,
volume: None,
};
match serde_json::to_value(&source) {
Ok(value) => app.daemon.add_audio_source(value),
Err(e) => app.notify_error(format!("audio source did not serialize: {e}")),
}
app.form.close_add();
app.refresh_processes();
}
/// The dialog the card's plus opens: what to call the application, and the process to listen
/// to. `app::view` draws it over the whole window, title bar included.
pub fn add_dialog(app: &App, p: Paint, layer: &mut Vec<El>) {
let typed = app.form.source_device.text.trim();
let found = app
.processes
.get(&crate::process::normalize(typed))
.filter(|_| !typed.is_empty());
let hint = match found {
Some(found) if found.running => "That process is running.".to_string(),
Some(_) => "That process is not running right now.".to_string(),
None => "The name Windows gives the program, for example Discord.exe.".to_string(),
};
let valid = !app.form.source_name.text.trim().is_empty() && !typed.is_empty();
let actions = row()
.key("dialog-actions")
.w_full()
.gap(space::S2)
.justify_end()
.child(ui::button(
p,
"add-cancel",
"Cancel",
false,
|app: &mut App| {
app.form.close_add();
},
))
.child(if valid {
ui::button(p, "add-confirm", "Add", true, |app: &mut App| {
submit_source(app);
})
} else {
ui::button_muted(p, "add-confirm", "Add")
});
let panel = col()
.key("add-dialog")
.role("dialog")
.label("Add an application")
.w(400.0)
.padding(space::S6)
.gap(space::S3)
.radius(radius::LG)
.fill(p.t.card)
.border(p.hair, p.t.card_border)
.shadow(4.0, 12.0, p.t.shadow)
.shadow(24.0, 48.0, p.t.shadow_soft)
.modal(true, |app: &mut App| app.form.close_add())
.child(
row()
.key("dialog-header")
.w_full()
.justify_between()
.center_y()
.child(
text("Add an application")
.key("dialog-title")
.font(heading(15.0))
.color(p.t.text),
)
.child(ui::icon_button(
p,
"add-close",
"×",
"Close",
false,
|app: &mut App| app.form.close_add(),
)),
)
.child(
text("Its audio is mixed into the clip beside the game's.")
.key("dialog-note")
.font(body(12.0))
.color(p.muted()),
)
.child(captioned_field(
p,
"Name",
"add-name",
&app.form.source_name,
|app| &mut app.form.source_name,
))
.child(captioned_field(
p,
"Process",
"add-process",
&app.form.source_device,
|app| &mut app.form.source_device,
))
.child(
text(hint)
.key("dialog-hint")
.font(body(11.0))
.color(p.muted()),
)
.child(actions);
layer.push(
el().key("add-scrim")
.absolute(0.0, 0.0)
.w_full()
.h_full()
.fill(Color::BLACK.alpha(if app.dark { 0.55 } else { 0.28 }))
.a11y_hidden(),
);
layer.push(
el().key("add-layer")
.absolute(0.0, 0.0)
.w_full()
.h_full()
.padding(16.0)
.center()
.child(panel),
);
}
/// A wide field under its own caption, for a dialog where labels do not fit beside it.
fn captioned_field(
p: Paint,
label: &'static str,
key: &'static str,
edit: &TextEdit,
to: fn(&mut App) -> &mut TextEdit,
) -> El {
col()
.key(key)
.w_full()
.gap(space::S1)
.child(text(label).key("caption").font(body(11.0)).color(p.muted()))
.child(ui::text_field_width(
p,
key,
label,
352.0,
rune::Align::Start,
edit,
to,
|_app| {},
))
}
fn advanced(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, content: El) -> El {
let status_row = |key: &str, label: &'static str, value: String| {
row()
.key(key)
.h(36.0)
.px(space::S3)
.center_y()
.justify_between()
.child(text(label).key("label").font(type_::BODY).color(p.t.text))
.child(
text(value)
.key("value")
.font(type_::MONO_CAPTION)
.color(p.muted()),
)
};
let recording = if app.status.is_recording { "yes" } else { "no" };
content
.child(ui::card(
p,
Some("Daemon"),
vec![
status_row("daemon-status", "Status", app.status.label()),
status_row(
"daemon-connection",
"Pipe",
if app.connected {
"connected".into()
} else {
"not connected".into()
},
),
status_row(
"daemon-client",
"League Client",
if app.status.client_connected {
"connected".into()
} else {
"not running".into()
},
),
status_row("daemon-recording", "Recording", recording.into()),
status_row(
"daemon-game",
"Current game",
app.status
.current_game_id
.map(|id| id.to_string())
.unwrap_or_else(|| "none".into()),
),
status_row(
"daemon-log",
"Log file",
short_path(&crate::daemon::log_path()),
),
],
))
.child(ui::card(
p,
Some("Recorder"),
vec![
text_row(
p,
"poll-interval",
"Client poll interval",
"How often the recorder checks the League Client, in milliseconds",
&app.form.poll_interval,
|app| &mut app.form.poll_interval,
),
select_row(
p,
kit,
layer,
"log-level",
"Log level",
"How much the recorder writes to its log",
&LOG_LEVELS,
Some(app.form.draft.daemon.log_level.clone()),
app,
),
],
))
.child(ui::card(
p,
Some("Audio"),
vec![
status_row(
"audio-devices",
"Devices",
format!(
"{} in · {} out",
app.devices.input_devices.len(),
app.devices.output_devices.len()
),
),
text_row(
p,
"audio-bitrate",
"Bitrate",
"Audio bitrate in kbps",
&app.form.bitrate,
|app| &mut app.form.bitrate,
),
],
))
.child(
row()
.key("daemon-actions")
.gap(8.0)
.child(ui::button(
p,
"daemon-check",
"Check connection",
false,
|app: &mut App| {
app.daemon.ensure_running();
app.daemon.get_status();
},
))
.child(ui::button(
p,
"daemon-logs",
"Reload log",
false,
|app: &mut App| {
app.daemon.logs();
},
))
.child(ui::button(
p,
"daemon-shutdown",
"Stop daemon",
false,
|app: &mut App| {
app.daemon.shutdown();
},
))
.child(ui::button(
p,
"reset-settings",
"Reset to defaults",
false,
|app: &mut App| {
app.daemon.reset_settings();
},
)),
)
.child(ui::card(
p,
Some("Log"),
vec![
col().key("log").padding(space::S3).h(300.0).gap(0.0).child(
text(if app.logs.is_empty() {
"No log loaded. Press Reload log."
} else {
&app.logs
})
.key("log-text")
.font(type_::MONO_CAPTION)
.color(p.muted())
.w_full(),
),
],
))
}