diagnose failure to stash or restore layer states across sessions on flatpak

This commit is contained in:
jess 2026-04-25 14:39:10 -07:00
parent 6f3461730e
commit 0cde65839c
2 changed files with 47 additions and 1 deletions

View File

@ -264,8 +264,21 @@ impl App {
} }
crate::ipc::Event::OpenDocuments(paths) => { crate::ipc::Event::OpenDocuments(paths) => {
if let Some(pcb) = paths.into_iter().next() { if let Some(pcb) = paths.into_iter().next() {
let canonical = pcb
.canonicalize()
.ok()
.map(|p| p.display().to_string())
.unwrap_or_else(|| "<canonicalize-failed>".to_string());
let hash = crate::paths::project_hash(&pcb); let hash = crate::paths::project_hash(&pcb);
let state_path = crate::paths::state_path(&hash); let state_path = crate::paths::state_path(&hash);
tracing::info!(
pcb_raw = %pcb.display(),
pcb_canonical = %canonical,
project_hash = %hash,
state_path = %state_path.display(),
state_exists = state_path.exists(),
"open document: resolving project state"
);
self.current_project = Some(ProjectContext { self.current_project = Some(ProjectContext {
project_hash: hash, project_hash: hash,
kicad_pcb_path: pcb, kicad_pcb_path: pcb,
@ -274,6 +287,11 @@ impl App {
self.has_pruned_orphans = false; self.has_pruned_orphans = false;
match crate::layers::persistence::load(&state_path) { match crate::layers::persistence::load(&state_path) {
Ok(tree) => { Ok(tree) => {
tracing::info!(
state_path = %state_path.display(),
layer_count = tree.layers.len(),
"loaded layer tree from disk"
);
self.layer_tree = tree; self.layer_tree = tree;
self.rebuild_panel_content(); self.rebuild_panel_content();
} }

View File

@ -618,13 +618,23 @@ fn persist_if_due(app: &mut App) {
return; return;
} }
let state_path = paths::state_path(&project.project_hash); let state_path = paths::state_path(&project.project_hash);
let layer_count = app.layer_tree.layers.len();
match crate::layers::persistence::save(&app.layer_tree, &state_path) { match crate::layers::persistence::save(&app.layer_tree, &state_path) {
Ok(()) => { Ok(()) => {
tracing::debug!(
state_path = %state_path.display(),
layer_count,
"saved layer tree"
);
app.dirty = false; app.dirty = false;
app.last_save = Some(std::time::Instant::now()); app.last_save = Some(std::time::Instant::now());
} }
Err(e) => { Err(e) => {
tracing::warn!("layer state save failed: {e}"); tracing::warn!(
state_path = %state_path.display(),
layer_count,
"layer state save failed: {e}"
);
app.last_save = Some(std::time::Instant::now()); app.last_save = Some(std::time::Instant::now());
} }
} }
@ -671,10 +681,28 @@ pub fn init_native_shell(plugin_root: Option<&std::path::Path>) -> anyhow::Resul
paths::create_dirs_if_missing()?; paths::create_dirs_if_missing()?;
let _ = init_logging_file_only(); let _ = init_logging_file_only();
dump_invocation_context_file_only(); dump_invocation_context_file_only();
probe_data_dir_writable();
crate::ui::colors::init(plugin_root); crate::ui::colors::init(plugin_root);
Ok(()) Ok(())
} }
fn probe_data_dir_writable() {
let dir = paths::data_dir();
let probe = dir.join(".write-probe");
match std::fs::write(&probe, b"ok") {
Ok(()) => {
let _ = std::fs::remove_file(&probe);
tracing::info!(data_dir = %dir.display(), "data dir is writable");
}
Err(e) => {
tracing::error!(
data_dir = %dir.display(),
"data dir NOT writable: {e} — state and logs won't persist; check flatpak --filesystem=home"
);
}
}
}
fn init_logging_file_only() -> anyhow::Result<()> { fn init_logging_file_only() -> anyhow::Result<()> {
use tracing_subscriber::{fmt, prelude::*, EnvFilter}; use tracing_subscriber::{fmt, prelude::*, EnvFilter};
let filter = EnvFilter::try_from_default_env() let filter = EnvFilter::try_from_default_env()