app: reach the daemon and load the real history
The pipe path was missing a backslash, so every client call went to a path Windows never resolves and the app reported a dead daemon. With the path fixed, --probe answers against the running daemon and parses its settings with the app's model; a recording made through it lands on disk. Reading a large history (288 timelines, 524 MB of raw API responses) took eleven seconds, so the files are parsed on up to eight threads now. The history refresh also runs in headless runs, and `--live` renders a snapshot from the daemon and the real timelines instead of sample data.
This commit is contained in:
1 parent
8883e93d2b
commit
b06ec4be7b
5 files changed
+76
-27
No files matched your search
+16
-8
@@ -10,7 +10,8 @@ cargo run
|
||||
```
|
||||
|
||||
The app starts the daemon if it isn't running, then reads its settings and status. `cargo run --
|
||||
--probe` does the same without a window and prints the daemon's answers.
|
||||
--probe` does the same without a window and prints the daemon's answers; `cargo run -- --games`
|
||||
prints how many timelines load from disk.
|
||||
|
||||
Headless renders, for looking at a screen without a window:
|
||||
|
||||
@@ -22,8 +23,15 @@ cargo run -- --snap audio.png --scene audio
|
||||
cargo run -- --snap review.png --scene review
|
||||
```
|
||||
|
||||
A headless run never starts the daemon or touches the disk: `App::new` loads the sample
|
||||
recordings from `history::sample` when it sees rune's tooling flags.
|
||||
`--live` renders without sample data: the app talks to the daemon and reads the real timelines
|
||||
from disk. Loading them takes a few seconds with a large history, so give it time before `--at`.
|
||||
|
||||
```sh
|
||||
cargo run -- --snap live.png --live --at 40
|
||||
```
|
||||
|
||||
Without `--live`, a headless run never starts the daemon or touches the disk: `App::new` loads the
|
||||
sample recordings from `history::sample` when it sees rune's tooling flags.
|
||||
|
||||
## Test
|
||||
|
||||
@@ -54,8 +62,10 @@ reading (`history::tests`), highlight clipping (`highlight::tests`) and formatti
|
||||
|
||||
1. Skeleton: done. Rune is pinned to `4ddf696b0f13ec618fdeb80b4c9ea1a6246547f1`; the window
|
||||
opens and `--snap` writes PNGs.
|
||||
2. Pipe client: done. Requests are typed (`Command`), the worker thread keeps the UI off tokio.
|
||||
The same types are tested against the daemon's serde names.
|
||||
2. Pipe client: done and checked against the running daemon here: `--probe` prints status,
|
||||
settings, encoders and audio devices, and parses the settings reply with the app's model.
|
||||
Requests are typed (`Command`), the worker thread keeps the UI off tokio, and the same types
|
||||
are tested against the daemon's serde names.
|
||||
3. Settings: done. General, recording, audio and daemon tabs; device and encoder lists come from
|
||||
`getAudioDevices` and `getEncoders`; changes go out through `updateSettings`, and each
|
||||
application volume slider sends `updateAudioSource` as it moves.
|
||||
@@ -77,11 +87,9 @@ reading (`history::tests`), highlight clipping (`highlight::tests`) and formatti
|
||||
|
||||
### Known gaps
|
||||
|
||||
- A live daemon check was not possible in this checkout: the daemon spends its startup in OBS
|
||||
initialization and does not reach the IPC server here, so `--probe` times out. The client's
|
||||
JSON matches the daemon's `IpcCommand` and response types in tests.
|
||||
- Champion and item images are not drawn: the app has no Data Dragon image cache yet, so cards
|
||||
show names and numbers.
|
||||
- The installer has not been run on a clean VM.
|
||||
|
||||
## The vendored crates
|
||||
|
||||
|
||||
+9
-8
@@ -128,11 +128,13 @@ impl App {
|
||||
pub fn new() -> Self {
|
||||
let autostart = os::autostart_enabled();
|
||||
let headless = headless();
|
||||
// `--live` renders headless but talks to the daemon and reads the real recordings.
|
||||
let live = std::env::args().any(|arg| arg == "--live");
|
||||
let mut app = Self {
|
||||
screen: Screen::History,
|
||||
settings_tab: SettingsTab::General,
|
||||
dark: true,
|
||||
daemon: Daemon::start(headless),
|
||||
daemon: Daemon::start(headless && !live),
|
||||
connected: false,
|
||||
status: Status::default(),
|
||||
settings: None,
|
||||
@@ -153,7 +155,7 @@ impl App {
|
||||
tray_recording: false,
|
||||
waker: None,
|
||||
};
|
||||
if headless {
|
||||
if headless && !live {
|
||||
app.demo();
|
||||
}
|
||||
app
|
||||
@@ -293,6 +295,11 @@ fn hide_window() {
|
||||
pub fn setup(app: &mut App, waker: rune::Waker) {
|
||||
app.waker = Some(waker.clone());
|
||||
app.daemon.set_waker(waker.clone());
|
||||
app.refresh_settings();
|
||||
app.refresh_games();
|
||||
app.daemon.get_status();
|
||||
app.daemon.get_encoders();
|
||||
app.daemon.get_audio_devices();
|
||||
if headless() {
|
||||
return;
|
||||
}
|
||||
@@ -312,12 +319,6 @@ pub fn setup(app: &mut App, waker: rune::Waker) {
|
||||
}
|
||||
Err(e) => eprintln!("tray icon unavailable: {e}"),
|
||||
}
|
||||
|
||||
app.refresh_settings();
|
||||
app.refresh_games();
|
||||
app.daemon.get_status();
|
||||
app.daemon.get_encoders();
|
||||
app.daemon.get_audio_devices();
|
||||
}
|
||||
|
||||
impl App {
|
||||
|
||||
+31
-9
@@ -131,25 +131,47 @@ pub fn timeline_dir() -> PathBuf {
|
||||
}
|
||||
|
||||
/// Every timeline on disk, newest first. Files that fail to parse are skipped.
|
||||
/// Every timeline on disk, newest first. The raw API responses make each file large (hundreds
|
||||
/// of kilobytes), so the files are parsed in parallel.
|
||||
pub fn load_all() -> Vec<Timeline> {
|
||||
let dir = timeline_dir();
|
||||
let mut out = Vec::new();
|
||||
let Ok(entries) = std::fs::read_dir(&dir) else {
|
||||
return out;
|
||||
return Vec::new();
|
||||
};
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
if path.extension().and_then(|e| e.to_str()) != Some("json") {
|
||||
continue;
|
||||
}
|
||||
let Ok(text) = std::fs::read_to_string(&path) else {
|
||||
let paths: Vec<PathBuf> = entries
|
||||
.flatten()
|
||||
.map(|entry| entry.path())
|
||||
.filter(|path| path.extension().and_then(|e| e.to_str()) == Some("json"))
|
||||
.collect();
|
||||
|
||||
let next = std::sync::atomic::AtomicUsize::new(0);
|
||||
let parsed = std::sync::Mutex::new(Vec::with_capacity(paths.len()));
|
||||
let threads = std::thread::available_parallelism()
|
||||
.map(|count| count.get())
|
||||
.unwrap_or(4)
|
||||
.clamp(1, 8);
|
||||
|
||||
std::thread::scope(|scope| {
|
||||
for _ in 0..threads {
|
||||
scope.spawn(|| {
|
||||
loop {
|
||||
let index = next.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
let Some(path) = paths.get(index) else {
|
||||
break;
|
||||
};
|
||||
let Ok(text) = std::fs::read_to_string(path) else {
|
||||
continue;
|
||||
};
|
||||
match serde_json::from_str::<Timeline>(&text) {
|
||||
Ok(timeline) => out.push(timeline),
|
||||
Ok(timeline) => parsed.lock().unwrap().push(timeline),
|
||||
Err(e) => eprintln!("skipping {}: {e}", path.display()),
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
let mut out = parsed.into_inner().unwrap();
|
||||
out.sort_by(|a, b| b.start_time.cmp(&a.start_time));
|
||||
out
|
||||
}
|
||||
|
||||
+2
-2
@@ -73,7 +73,7 @@ pub struct IpcResponse {
|
||||
pub fn default_socket_path() -> PathBuf {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
PathBuf::from(r"\.\pipe\record-daemon")
|
||||
PathBuf::from(r"\\.\pipe\record-daemon")
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
@@ -483,7 +483,7 @@ mod tests {
|
||||
fn the_pipe_name_matches_the_daemon() {
|
||||
assert_eq!(
|
||||
default_socket_path().to_string_lossy(),
|
||||
r"\.\pipe\record-daemon"
|
||||
r"\\.\pipe\record-daemon"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,10 @@ mod ui;
|
||||
use rune::AppSpec;
|
||||
|
||||
fn main() {
|
||||
if std::env::args().any(|arg| arg == "--games") {
|
||||
println!("{} timelines", crate::history::load_all().len());
|
||||
return;
|
||||
}
|
||||
if std::env::args().any(|arg| arg == "--probe") {
|
||||
probe();
|
||||
return;
|
||||
@@ -102,5 +106,19 @@ fn probe() {
|
||||
Err(e) => println!("{name}: error: {e}"),
|
||||
}
|
||||
}
|
||||
// Parse with the app model, which is what the settings screen receives.
|
||||
match client.call(ipc::Command::GetSettings, None).await {
|
||||
Ok(data) => match crate::settings::from_response(&data) {
|
||||
Ok(settings) => println!(
|
||||
"parsed: {} fps, {:?}, {} application sources, encoder {}",
|
||||
settings.video.frame_rate,
|
||||
settings.video.quality,
|
||||
settings.audio.capture_apps.len(),
|
||||
settings.video.encoder_preset.encoder_id(),
|
||||
),
|
||||
Err(e) => println!("parsed: failed: {e}"),
|
||||
},
|
||||
Err(e) => println!("parsed: {e}"),
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user