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.
This commit is contained in:
1 parent
3dfef1961d
commit
c7fee5beeb
8 files changed
+805
-203
No files matched your search
+256
-168
@@ -1,7 +1,7 @@
|
||||
//! Settings: a quick tab of everyday choices, then recording, audio and the daemon.
|
||||
|
||||
use rune::tok::{radius, space, type_};
|
||||
use rune::{El, TextEdit, col, row, text};
|
||||
use rune::{Color, El, TextEdit, col, el, row, text};
|
||||
use rune_kit::Select;
|
||||
|
||||
use crate::app::{App, SettingsTab};
|
||||
@@ -24,7 +24,7 @@ pub struct Form {
|
||||
pub bitrate: TextEdit,
|
||||
pub source_name: TextEdit,
|
||||
pub source_device: TextEdit,
|
||||
pub source_type: AudioSourceType,
|
||||
pub add_open: bool,
|
||||
}
|
||||
|
||||
impl Form {
|
||||
@@ -40,7 +40,7 @@ impl Form {
|
||||
bitrate: TextEdit::new(draft.audio.bitrate.to_string()),
|
||||
source_name: TextEdit::new(""),
|
||||
source_device: TextEdit::new(""),
|
||||
source_type: AudioSourceType::Application,
|
||||
add_open: false,
|
||||
draft,
|
||||
loaded: false,
|
||||
dirty: false,
|
||||
@@ -103,6 +103,19 @@ impl Form {
|
||||
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" => {
|
||||
@@ -119,13 +132,6 @@ impl Form {
|
||||
"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()),
|
||||
"source-type" => {
|
||||
self.source_type = match value {
|
||||
"Output device" => AudioSourceType::DeviceOutput,
|
||||
"Input device" => AudioSourceType::DeviceInput,
|
||||
_ => AudioSourceType::Application,
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
self.dirty = true;
|
||||
@@ -136,7 +142,6 @@ 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"];
|
||||
const SOURCE_TYPES: [&str; 3] = ["Application", "Output device", "Input device"];
|
||||
|
||||
/// A row with a single-line field on the right.
|
||||
fn text_row(
|
||||
@@ -627,7 +632,7 @@ fn audio(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, content:
|
||||
let mut sources = col().key("sources").gap(2.0);
|
||||
if a.capture_apps.is_empty() {
|
||||
sources = sources.child(
|
||||
text("No applications yet. Add one below and its audio joins the clip.")
|
||||
text("No applications yet. Add one and its audio joins the clip.")
|
||||
.key("sources-empty")
|
||||
.font(body(12.0))
|
||||
.color(p.muted())
|
||||
@@ -636,76 +641,7 @@ fn audio(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, content:
|
||||
);
|
||||
}
|
||||
for (index, source) in a.capture_apps.iter().enumerate() {
|
||||
let id = source.id.clone();
|
||||
let volume = source.volume.unwrap_or(100);
|
||||
sources = sources.child(
|
||||
row()
|
||||
.key(format!("source-{}", source.id))
|
||||
.h(48.0)
|
||||
.px(space::S3)
|
||||
.center_y()
|
||||
.gap(space::S3)
|
||||
.justify_between()
|
||||
.radius(radius::MD)
|
||||
.child(
|
||||
col()
|
||||
.key("source-labels")
|
||||
.grow(1.0)
|
||||
.gap(1.0)
|
||||
.child(
|
||||
text(source.name.clone())
|
||||
.key("name")
|
||||
.font(type_::BODY)
|
||||
.color(p.t.text),
|
||||
)
|
||||
.child(
|
||||
text(format!(
|
||||
"{} · {}",
|
||||
source.source_type.label(),
|
||||
source.device
|
||||
))
|
||||
.key("detail")
|
||||
.font(body(11.0))
|
||||
.color(p.muted()),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
row()
|
||||
.key("source-volume")
|
||||
.gap(space::S2)
|
||||
.center_y()
|
||||
.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);
|
||||
},
|
||||
)),
|
||||
);
|
||||
sources = sources.child(source_row(app, p, index, source));
|
||||
}
|
||||
|
||||
content
|
||||
@@ -777,100 +713,242 @@ fn audio(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, content:
|
||||
mic_row(p, kit, layer, app, "mic-device"),
|
||||
],
|
||||
))
|
||||
.child(ui::card(
|
||||
.child(ui::card_action(
|
||||
p,
|
||||
Some("Applications"),
|
||||
vec![sources, add_source(app, p, kit, layer)],
|
||||
Some(ui::icon_button(
|
||||
p,
|
||||
"add-source",
|
||||
"+",
|
||||
"Add an application",
|
||||
true,
|
||||
|app: &mut App| app.form.open_add(),
|
||||
)),
|
||||
vec![sources],
|
||||
))
|
||||
}
|
||||
|
||||
/// The row that adds an application source: a name, the process or device, and its kind.
|
||||
fn add_source(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>) -> El {
|
||||
let open = app.form.open_select == Some("source-type");
|
||||
let kind = Select::new("source-type", &SOURCE_TYPES)
|
||||
.current(Some(app.form.source_type.label()))
|
||||
.open(open)
|
||||
.label("Type")
|
||||
.width(170.0)
|
||||
.on_toggle(|app: &mut App| {
|
||||
app.form.open_select = if app.form.open_select == Some("source-type") {
|
||||
None
|
||||
} else {
|
||||
Some("source-type")
|
||||
};
|
||||
})
|
||||
.on_close(|app: &mut App| app.form.open_select = None)
|
||||
.on_choose(|app: &mut App, value: &str, _: &mut rune::Tx| {
|
||||
app.form.choose("source-type", value);
|
||||
app.form.open_select = None;
|
||||
})
|
||||
.build(kit, layer);
|
||||
col()
|
||||
.key("add-source")
|
||||
.gap(space::S2)
|
||||
/// 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)
|
||||
.pb(space::S3)
|
||||
.center_y()
|
||||
.gap(space::S3)
|
||||
.child(ui::process_icon(app, p, &source.device, 24.0))
|
||||
.child(
|
||||
text("Add an application")
|
||||
.key("add-title")
|
||||
.font(type_::SECTION)
|
||||
.color(p.muted()),
|
||||
)
|
||||
.child(
|
||||
row()
|
||||
.key("add-fields")
|
||||
.gap(space::S3)
|
||||
.center_y()
|
||||
.child(labelled_field(
|
||||
p,
|
||||
"Name",
|
||||
"source-name",
|
||||
&app.form.source_name,
|
||||
|app| &mut app.form.source_name,
|
||||
))
|
||||
.child(labelled_field(
|
||||
p,
|
||||
"Process or device",
|
||||
"source-device",
|
||||
&app.form.source_device,
|
||||
|app| &mut app.form.source_device,
|
||||
))
|
||||
.child(kind)
|
||||
.child(ui::button(
|
||||
p,
|
||||
"add-source-button",
|
||||
"Add",
|
||||
true,
|
||||
|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() {
|
||||
app.notify_error(
|
||||
"An audio source needs a name and a process or device",
|
||||
);
|
||||
return;
|
||||
}
|
||||
let source = AudioSource {
|
||||
id: String::new(),
|
||||
name,
|
||||
source_type: app.form.source_type,
|
||||
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}"))
|
||||
}
|
||||
}
|
||||
},
|
||||
)),
|
||||
)
|
||||
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);
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
/// A field with its name above it, for a row of controls that has no room for setting labels.
|
||||
fn labelled_field(
|
||||
/// 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,
|
||||
@@ -879,9 +957,19 @@ fn labelled_field(
|
||||
) -> 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(p, key, label, edit, to))
|
||||
.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 {
|
||||
|
||||
Reference in new issue
Block a user