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
+129
-25
@@ -10,6 +10,7 @@ use crate::history::{self, QueueCategory, Timeline};
|
||||
use crate::ipc::{self, Daemon};
|
||||
use crate::os;
|
||||
use crate::portraits;
|
||||
use crate::process;
|
||||
use crate::screens;
|
||||
use crate::settings::{AudioSource, AudioSourceType, Settings};
|
||||
use crate::ui::{self, Paint, body, heading};
|
||||
@@ -116,6 +117,13 @@ pub struct App {
|
||||
pub filter: Option<QueueCategory>,
|
||||
pub review: screens::review::Review,
|
||||
pub portraits: Option<portraits::Portraits>,
|
||||
/// The icons of the processes the audio sources name, decoded from their executables.
|
||||
pub icons: Option<rune::ImageCache>,
|
||||
/// Which of those processes are running, refreshed while the audio tab is open.
|
||||
pub processes: process::Processes,
|
||||
pub processes_rx: Option<Receiver<process::Processes>>,
|
||||
/// When the process table was last read, in the clock `poll` gets.
|
||||
pub processes_at: f64,
|
||||
pub scroll: ui::ScrollBar,
|
||||
pub highlights_scroll: ui::ScrollBar,
|
||||
pub events_scroll: ui::ScrollBar,
|
||||
@@ -153,6 +161,10 @@ impl App {
|
||||
filter: None,
|
||||
review: screens::review::Review::default(),
|
||||
portraits: None,
|
||||
icons: None,
|
||||
processes: process::Processes::new(),
|
||||
processes_rx: None,
|
||||
processes_at: 0.0,
|
||||
scroll: ui::ScrollBar::new(),
|
||||
highlights_scroll: ui::ScrollBar::new(),
|
||||
events_scroll: ui::ScrollBar::new(),
|
||||
@@ -231,6 +243,23 @@ impl App {
|
||||
},
|
||||
];
|
||||
self.form.apply(&settings);
|
||||
// The sample sources read as a running process and one that is not, so a snapshot
|
||||
// shows both states of the chip.
|
||||
self.processes = settings
|
||||
.audio
|
||||
.capture_apps
|
||||
.iter()
|
||||
.map(|source| {
|
||||
let running = source.device.eq_ignore_ascii_case("Discord.exe");
|
||||
(
|
||||
process::normalize(&source.device),
|
||||
process::Found {
|
||||
running,
|
||||
path: None,
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
self.settings = Some(settings);
|
||||
}
|
||||
|
||||
@@ -252,6 +281,46 @@ impl App {
|
||||
self.daemon.get_settings();
|
||||
}
|
||||
|
||||
/// The process names the audio sources refer to, plus whatever is being typed into the
|
||||
/// add dialog.
|
||||
fn watch_names(&self) -> Vec<String> {
|
||||
let mut names: Vec<String> = self
|
||||
.form
|
||||
.draft
|
||||
.audio
|
||||
.capture_apps
|
||||
.iter()
|
||||
.filter(|source| source.source_type == AudioSourceType::Application)
|
||||
.map(|source| source.device.clone())
|
||||
.collect();
|
||||
if self.form.add_open {
|
||||
let typed = self.form.source_device.text.trim();
|
||||
if !typed.is_empty() {
|
||||
names.push(typed.to_string());
|
||||
}
|
||||
}
|
||||
names.sort();
|
||||
names.dedup();
|
||||
names
|
||||
}
|
||||
|
||||
/// Look at the process table on a thread of its own; `poll` picks the answer up.
|
||||
pub fn refresh_processes(&mut self) {
|
||||
if self.processes_rx.is_some() {
|
||||
return;
|
||||
}
|
||||
let names = self.watch_names();
|
||||
if names.is_empty() {
|
||||
self.processes.clear();
|
||||
return;
|
||||
}
|
||||
let (tx, rx) = channel();
|
||||
std::thread::spawn(move || {
|
||||
let _ = tx.send(process::snapshot(names));
|
||||
});
|
||||
self.processes_rx = Some(rx);
|
||||
}
|
||||
|
||||
/// Read the timelines on a thread of their own; `poll` picks the list up.
|
||||
pub fn refresh_games(&mut self) {
|
||||
if self.games_rx.is_some() {
|
||||
@@ -307,6 +376,7 @@ fn hide_window() {
|
||||
pub fn setup(app: &mut App, waker: rune::Waker) {
|
||||
app.waker = Some(waker.clone());
|
||||
app.portraits = Some(portraits::Portraits::new(waker.clone()));
|
||||
app.icons = Some(rune::ImageCache::new(waker.clone()));
|
||||
app.daemon.set_waker(waker.clone());
|
||||
app.refresh_settings();
|
||||
app.refresh_games();
|
||||
@@ -447,6 +517,18 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(rx) = &self.processes_rx {
|
||||
match rx.try_recv() {
|
||||
Ok(processes) => {
|
||||
self.processes = processes;
|
||||
self.processes_rx = None;
|
||||
changed = true;
|
||||
}
|
||||
Err(TryRecvError::Empty) => {}
|
||||
Err(TryRecvError::Disconnected) => self.processes_rx = None,
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(rx) = &self.games_rx {
|
||||
match rx.try_recv() {
|
||||
Ok(games) => {
|
||||
@@ -491,6 +573,16 @@ impl App {
|
||||
self.last_status = t;
|
||||
self.daemon.get_status();
|
||||
}
|
||||
|
||||
// The audio tab says whether each process is up, so it reads the process table again
|
||||
// every couple of seconds while it is on screen.
|
||||
if self.screen == Screen::Settings
|
||||
&& (self.settings_tab == SettingsTab::Audio || self.form.add_open)
|
||||
&& t - self.processes_at >= 2.0
|
||||
{
|
||||
self.processes_at = t;
|
||||
self.refresh_processes();
|
||||
}
|
||||
// Keep the clock running so the status stays live even when nothing draws.
|
||||
tx.wake_after(Duration::from_millis(1000));
|
||||
|
||||
@@ -520,6 +612,10 @@ pub fn on_key(app: &mut App, event: &KeyEvent, _tx: &mut Tx) -> bool {
|
||||
app.screen = Screen::Settings;
|
||||
true
|
||||
}
|
||||
(Key::Escape, _) if app.form.add_open => {
|
||||
app.form.close_add();
|
||||
true
|
||||
}
|
||||
(Key::Escape, _) if app.screen == Screen::Review => {
|
||||
screens::review::leave(app);
|
||||
app.screen = Screen::History;
|
||||
@@ -616,30 +712,32 @@ fn titlebar(p: Paint, app: &App) -> El {
|
||||
.font(heading(13.0))
|
||||
.color(p.t.text),
|
||||
);
|
||||
let actions = row()
|
||||
.key("actions")
|
||||
.gap(8.0)
|
||||
.center_y()
|
||||
.child(ui::button(
|
||||
p,
|
||||
"refresh",
|
||||
"Refresh",
|
||||
false,
|
||||
|app: &mut App| {
|
||||
app.refresh_games();
|
||||
app.daemon.get_status();
|
||||
},
|
||||
))
|
||||
.child(ui::button(
|
||||
p,
|
||||
"open-settings",
|
||||
"Settings",
|
||||
false,
|
||||
|app: &mut App| {
|
||||
screens::review::leave(app);
|
||||
app.screen = Screen::Settings;
|
||||
},
|
||||
));
|
||||
let mut actions = row().key("actions").gap(8.0).center_y();
|
||||
// On the settings screen the title bar has nothing to offer: refreshing and opening
|
||||
// settings again would only repeat what the screen already does.
|
||||
if app.screen != Screen::Settings {
|
||||
actions = actions
|
||||
.child(ui::button(
|
||||
p,
|
||||
"refresh",
|
||||
"Refresh",
|
||||
false,
|
||||
|app: &mut App| {
|
||||
app.refresh_games();
|
||||
app.daemon.get_status();
|
||||
},
|
||||
))
|
||||
.child(ui::button(
|
||||
p,
|
||||
"open-settings",
|
||||
"Settings",
|
||||
false,
|
||||
|app: &mut App| {
|
||||
screens::review::leave(app);
|
||||
app.screen = Screen::Settings;
|
||||
},
|
||||
));
|
||||
}
|
||||
row()
|
||||
.key("titlebar")
|
||||
.h(48.0)
|
||||
@@ -706,7 +804,7 @@ pub fn view(app: &App, cx: &mut Cx<App>) -> El {
|
||||
.child(titlebar(p, app))
|
||||
.child(main)
|
||||
.child(statusbar(p, app));
|
||||
match app.screen {
|
||||
let content = match app.screen {
|
||||
Screen::Review => window
|
||||
.child(
|
||||
app.highlights_scroll
|
||||
@@ -722,7 +820,13 @@ pub fn view(app: &App, cx: &mut Cx<App>) -> El {
|
||||
"list-scroller"
|
||||
},
|
||||
)),
|
||||
};
|
||||
// The add-application dialog covers the whole window, title bar included.
|
||||
let mut overlays = Vec::new();
|
||||
if app.screen == Screen::Settings && app.form.add_open {
|
||||
screens::settings::add_dialog(app, p, &mut overlays);
|
||||
}
|
||||
rune_kit::root(content, overlays)
|
||||
}
|
||||
|
||||
/// Whether this is a headless run (`--snap out.png`, `--tree`, …) rather than a window.
|
||||
|
||||
Reference in new issue
Block a user