Replaces the Vue/Tauri front end with a rune app that speaks the daemon's existing IPC protocol: settings (general, recording, audio), match history and game review with a scrubber, event markers and ffmpeg highlight export. Includes tray icon, launch at login, single instance, toasts, a headless snapshot path for checking screens, and a cargo-packager NSIS config. Rune is pinned to 4ddf696b0f and its three patched crates are vendored under app/vendor, since a dependency's [patch.crates-io] does not apply to the app. The daemon's OBS bootstrap never reached its IPC server on this machine, so the live check is a `--probe` command; the wire format is covered by tests.
155 lines
4.9 KiB
Rust
155 lines
4.9 KiB
Rust
//! Finding, starting and logging the record-daemon process.
|
|
//!
|
|
//! Ported from `tauri-app/src-tauri/src/daemon_ipc.rs`. The daemon binary ships next to the
|
|
//! app; inside a checkout it is found in `record-daemon/target/{release,debug}`.
|
|
|
|
use std::path::{Path, PathBuf};
|
|
use std::time::Duration;
|
|
|
|
use crate::ipc::Client;
|
|
|
|
/// The daemon's data directory, shared with the daemon itself.
|
|
pub fn data_dir() -> Option<PathBuf> {
|
|
directories::ProjectDirs::from("com", "leaguerecorder", "record-daemon")
|
|
.map(|dirs| dirs.data_dir().to_path_buf())
|
|
}
|
|
|
|
/// Where recordings and timelines live.
|
|
pub fn recordings_dir() -> PathBuf {
|
|
data_dir()
|
|
.map(|p| p.join("recordings"))
|
|
.unwrap_or_else(|| PathBuf::from("./recordings"))
|
|
}
|
|
|
|
/// Where the daemon writes its log.
|
|
pub fn log_file() -> Option<PathBuf> {
|
|
let dir = data_dir()?.join("logs");
|
|
std::fs::create_dir_all(&dir).ok()?;
|
|
Some(dir.join("daemon.log"))
|
|
}
|
|
|
|
/// Find the record-daemon binary next to the app, in an installed `resources` folder, or in a
|
|
/// development checkout.
|
|
pub fn find_binary() -> Option<PathBuf> {
|
|
let name = if cfg!(windows) {
|
|
"record-daemon.exe"
|
|
} else {
|
|
"record-daemon"
|
|
};
|
|
|
|
if let Ok(exe) = std::env::current_exe() {
|
|
let exe_dir = exe.parent()?;
|
|
let beside = exe_dir.join(name);
|
|
if beside.exists() {
|
|
return Some(beside);
|
|
}
|
|
if let Some(parent) = exe_dir.parent() {
|
|
let resources = parent.join("resources").join(name);
|
|
if resources.exists() {
|
|
return Some(resources);
|
|
}
|
|
}
|
|
let mut dir = exe_dir.to_path_buf();
|
|
for _ in 0..6 {
|
|
for suffix in ["record-daemon/target/release", "record-daemon/target/debug"] {
|
|
let candidate = dir.join(suffix).join(name);
|
|
if candidate.exists() {
|
|
return Some(candidate);
|
|
}
|
|
}
|
|
if !dir.pop() {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
let cwd = std::env::current_dir().ok()?;
|
|
let mut dir = cwd.as_path();
|
|
for _ in 0..5 {
|
|
for suffix in ["record-daemon/target/release", "record-daemon/target/debug"] {
|
|
let candidate = dir.join(suffix).join(name);
|
|
if candidate.exists() {
|
|
return Some(candidate);
|
|
}
|
|
}
|
|
dir = dir.parent()?;
|
|
}
|
|
None
|
|
}
|
|
|
|
/// Start the daemon detached, so it outlives the app.
|
|
pub fn spawn() -> Result<PathBuf, String> {
|
|
let binary = find_binary().ok_or_else(|| {
|
|
"record-daemon was not found next to the app or in record-daemon/target".to_string()
|
|
})?;
|
|
let log = log_file().ok_or_else(|| "no data directory for the daemon log".to_string())?;
|
|
|
|
let mut command = std::process::Command::new(&binary);
|
|
command.arg("--foreground").arg("--log-file").arg(&log);
|
|
if let Some(dir) = binary.parent() {
|
|
// The daemon finds its bundled OBS plugin data relative to itself.
|
|
command.current_dir(dir);
|
|
}
|
|
#[cfg(windows)]
|
|
{
|
|
use std::os::windows::process::CommandExt;
|
|
// CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS
|
|
command.creation_flags(0x0000_0200 | 0x0000_0008);
|
|
}
|
|
command
|
|
.stdin(std::process::Stdio::null())
|
|
.stdout(std::process::Stdio::null())
|
|
.stderr(std::process::Stdio::null());
|
|
command
|
|
.spawn()
|
|
.map_err(|e| format!("cannot start record-daemon: {e}"))?;
|
|
Ok(binary)
|
|
}
|
|
|
|
/// Is a daemon answering on the pipe?
|
|
|
|
/// Wait up to `timeout` for the daemon to answer, starting it if it isn't running yet.
|
|
pub async fn ensure_running() -> Result<(), String> {
|
|
let client = Client::new();
|
|
if client.is_running().await {
|
|
return Ok(());
|
|
}
|
|
spawn()?;
|
|
let deadline = std::time::Instant::now() + Duration::from_secs(30);
|
|
loop {
|
|
if client.is_running().await {
|
|
return Ok(());
|
|
}
|
|
if std::time::Instant::now() >= deadline {
|
|
return Err("record-daemon did not answer within 30 s".to_string());
|
|
}
|
|
tokio::time::sleep(Duration::from_millis(500)).await;
|
|
}
|
|
}
|
|
|
|
/// The last `n` lines of the daemon log.
|
|
pub fn read_logs(n: usize) -> Result<String, String> {
|
|
let path = log_file().ok_or_else(|| "no data directory for the daemon log".to_string())?;
|
|
let text = std::fs::read_to_string(&path)
|
|
.map_err(|e| format!("cannot read {}: {e}", path.display()))?;
|
|
let lines: Vec<&str> = text.lines().rev().take(n).collect();
|
|
Ok(lines.into_iter().rev().collect::<Vec<_>>().join("\n"))
|
|
}
|
|
|
|
/// The log path as text, for the About tab.
|
|
pub fn log_path() -> String {
|
|
log_file()
|
|
.map(|p| p.display().to_string())
|
|
.unwrap_or_default()
|
|
}
|
|
|
|
/// Open a folder.
|
|
pub fn open_folder(path: &Path) {
|
|
#[cfg(windows)]
|
|
{
|
|
let _ = std::process::Command::new("explorer").arg(path).spawn();
|
|
}
|
|
#[cfg(not(windows))]
|
|
let _ = path;
|
|
}
|