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
+81
-32
No files matched your search
+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 {
|
||||
|
||||
+36
-14
@@ -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 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) => parsed.lock().unwrap().push(timeline),
|
||||
Err(e) => eprintln!("skipping {}: {e}", path.display()),
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
let Ok(text) = std::fs::read_to_string(&path) else {
|
||||
continue;
|
||||
};
|
||||
match serde_json::from_str::<Timeline>(&text) {
|
||||
Ok(timeline) => out.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