Make diagnostics safe for running instances

This commit is contained in:
2026-09-12 11:53:37 +02:00
parent b76c4ba809
commit 53369904b4
3 changed files with 31 additions and 10 deletions

View File

@@ -52,6 +52,9 @@ Each bounded iteration must:
- [x] Replace the conflict-prone `Ctrl+R` pause shortcut with `Ctrl+Alt+R`, and expose the configured global shortcut in the window title/status (Docker GTK/X11 build; live tray/capture verified, 2026-09-10).
- [ ] Verify tray activation/menu behavior and graceful tray unavailability.
- [ ] Verify second invocation/show behavior including diagnostics.
- [x] Make `--diagnostics` inspect the running installation without triggering a
show request, and report the log directory plus instance state (20 tests and
Docker GTK/X11/package build, 2026-09-12).
## Configuration and application state
@@ -88,5 +91,7 @@ Each bounded iteration must:
packages are still not installed.
- Clippy is unavailable in the current Rust toolchain.
- No GUI, X11, Cinnamon, or packaging integration tests are present in the tree.
- Diagnostics previously printed a fixed log filename even though the rolling
logger creates date-suffixed files; this is now reported as the log directory.
- The initial implementation is now committed; future work must keep the tree
clean at each checkpoint.

View File

@@ -107,6 +107,14 @@ impl InstanceGuard {
.context("failed to request the running Cliphoard instance to show")?;
Ok(())
}
pub fn is_running() -> bool {
let path = runtime_dir().join("clipbhoard.lock");
let Ok(file) = File::open(path) else {
return false;
};
file.try_lock_exclusive().is_err()
}
}
impl Drop for InstanceGuard {

View File

@@ -48,25 +48,25 @@ fn main() -> Result<()> {
.context("failed to start the background Cliphoard process")?;
return Ok(());
}
let instance = match lifecycle::InstanceGuard::acquire() {
Ok(instance) => instance,
Err(lock_error) => {
lifecycle::InstanceGuard::signal_show().with_context(|| lock_error.to_string())?;
return Ok(());
}
};
let database = Database::open_default()?;
if args.iter().any(|arg| arg == "--diagnostics") {
println!("Version: {}", env!("CARGO_PKG_VERSION"));
println!("Database: OK ({})", database.path().display());
println!("Config: OK");
println!("Instance lock: OK ({})", instance.path().display());
println!(
"Log: {}",
"Instance: {}",
if lifecycle::InstanceGuard::is_running() {
"running"
} else {
"not running"
}
);
println!(
"Log directory: {}",
dirs::state_dir()
.unwrap_or_else(|| std::env::temp_dir())
.join("clipbhoard/clipbhoard.log")
.join("clipbhoard")
.display()
);
println!(
@@ -80,6 +80,14 @@ fn main() -> Result<()> {
return Ok(());
}
let instance = match lifecycle::InstanceGuard::acquire() {
Ok(instance) => instance,
Err(lock_error) => {
lifecycle::InstanceGuard::signal_show().with_context(|| lock_error.to_string())?;
return Ok(());
}
};
#[cfg(feature = "gui")]
return gui::run(config, database, instance, show_on_start);