From 6f3461730eeb5593eb45d34667e7308792eb7ffa Mon Sep 17 00:00:00 2001 From: jess Date: Sat, 25 Apr 2026 13:55:51 -0700 Subject: [PATCH] logs --- src/bin/layers_shell.rs | 1 + src/paths.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/bin/layers_shell.rs b/src/bin/layers_shell.rs index cd7632a..771f080 100644 --- a/src/bin/layers_shell.rs +++ b/src/bin/layers_shell.rs @@ -27,6 +27,7 @@ fn main() { tracing::info!( plugin_root = ?plugin_root, + data_dir = ?layers::paths::data_dir(), log_dir = ?layers::paths::log_dir(), "layers shell: starting native event loop", ); diff --git a/src/paths.rs b/src/paths.rs index a6d02b0..b562f51 100644 --- a/src/paths.rs +++ b/src/paths.rs @@ -5,6 +5,7 @@ use sha2::{Digest, Sha256}; const PLUGIN_ID: &str = "com.jesshunter.layers"; const KICAD_MAJOR_DIR: &str = "KiCad/10.0/plugins"; +const USER_DATA_DOTDIR: &str = ".layers"; pub fn plugin_data_dir() -> PathBuf { plugin_root() @@ -14,8 +15,18 @@ pub fn plugin_dir() -> PathBuf { plugin_root() } +/// User-writable runtime data root: logs, state, cache, settings, runtime sockets. +/// Decoupled from the plugin install location so a flatpak KiCad (which sandboxes +/// its own data dirs) still writes somewhere we can `tail -f` from a normal shell. pub fn data_dir() -> PathBuf { - plugin_root() + if let Ok(v) = std::env::var("LAYERS_DATA_DIR") { + if !v.is_empty() { + return PathBuf::from(v); + } + } + dirs::home_dir() + .map(|h| h.join(USER_DATA_DOTDIR)) + .unwrap_or_else(|| PathBuf::from("/tmp").join(USER_DATA_DOTDIR)) } pub fn state_dir() -> PathBuf {