mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-29 01:34:37 +01:00
The desktop app started in a new, empty file on every launch, and with a control port open (FIGCRAFT_CONTROL_PORT set for an attached agent) even the Start on the Home screen preference was overridden, so the files you worked in had to be found and opened again each time. Quitting now keeps the paths of the open tabs' files, in tab order, and the one in front (Prefs::open_files, Prefs::front_file); the next start opens them again and brings that one forward, as Figma's desktop app reopens its tabs. Files without a path (new, imported, joined live) and branch tabs are left out. A file named on the command line stays in front, a recovered copy keeps its one tab (file.open switches to an open path), a file gone since is skipped, and one that won't open is reported like a file named on the command line. With nothing to reopen the window starts on the Home screen; only with a control port open does it still start in a new file (#874: control callers expect a document). Start on the Home screen now means Home instead of the reopened files. The list is written at quit only, with the other preferences. Keeping it on every tab change would cover a crash too, but a crash already brings back the unsaved files through recovery copies, and the list from the last quit is a fair fallback for the rest.
39 lines
1.7 KiB
Rust
39 lines
1.7 KiB
Rust
//! The files open when the desktop app quit open again at its next start, in their tabs' order
|
|
//! with the same one in front, as Figma's desktop app reopens its tabs.
|
|
|
|
use serde_json::json;
|
|
|
|
use crate::{EngineError, Session};
|
|
|
|
impl Session {
|
|
/// Keep the open files to reopen at the next start: each tab's file that has a path, in tab
|
|
/// order, and the one in front. Files without one (new, imported, joined from a live session)
|
|
/// and branch tabs are left out.
|
|
pub fn remember_open_files(&mut self) {
|
|
let path = |i: usize| self.docs.get(i).filter(|d| d.branch_of.is_none()).and_then(|d| d.path.clone());
|
|
self.prefs.open_files = (0..self.docs.len()).filter_map(path).collect();
|
|
self.prefs.front_file = path(self.active);
|
|
}
|
|
|
|
/// Open the files [`remember_open_files`](Self::remember_open_files) kept, then bring the one
|
|
/// that was in front forward. A file that is no longer there is skipped; the others that don't
|
|
/// open come back with why. A file already open (a recovered copy, one named at start) keeps
|
|
/// its tab.
|
|
pub fn reopen_files(&mut self) -> Vec<(String, EngineError)> {
|
|
let mut failed = Vec::new();
|
|
for path in self.prefs.open_files.clone() {
|
|
if !crate::file_access::exists(&path) {
|
|
continue;
|
|
}
|
|
if let Err(e) = self.execute("file.open", &json!({"path": path})) {
|
|
failed.push((path, e));
|
|
}
|
|
}
|
|
let front = self.prefs.front_file.as_deref();
|
|
if let Some(i) = self.docs.iter().position(|d| front.is_some() && d.path.as_deref() == front) {
|
|
self.active = i;
|
|
}
|
|
failed
|
|
}
|
|
}
|