chore: inital commit
Split project into a Cargo workspace with two crates: - core/ (noctua_core): UI-independent document library - ui/ (noctua_ui): COSMIC application scaffold (empty) justfile for workspace (run, run-cli, check, test, build)
This commit is contained in:
commit
c85f35310e
31 changed files with 9768 additions and 0 deletions
49
core/src/document/store.rs
Normal file
49
core/src/document/store.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// src/document/store.rs
|
||||
//
|
||||
// RON-based persistence for session data: load and save session lists.
|
||||
//
|
||||
// For the session concept and the meaning of each field see `session.rs`.
|
||||
//
|
||||
// On disk a session file contains a RON list of SessionData records:
|
||||
//
|
||||
// [
|
||||
// (
|
||||
// name: "Pictures",
|
||||
// kind: DirectoryBrowser,
|
||||
// path: Some("/home/user/Pictures"),
|
||||
// items: [],
|
||||
// current_index: None,
|
||||
// ),
|
||||
// (
|
||||
// name: "Project Docs",
|
||||
// kind: DocumentCollection,
|
||||
// path: None,
|
||||
// items: [
|
||||
// (path: "/home/user/docs/spec.pdf", page_index: 0),
|
||||
// (path: "/home/user/docs/notes.pdf", page_index: 2),
|
||||
// ],
|
||||
// current_index: Some(0),
|
||||
// ),
|
||||
// ]
|
||||
|
||||
use crate::document::session::SessionData;
|
||||
use crate::error::{Error, Result};
|
||||
use std::path::Path;
|
||||
|
||||
/// Loads all sessions from a RON file.
|
||||
pub fn load_sessions(path: &Path) -> Result<Vec<SessionData>> {
|
||||
let content = std::fs::read_to_string(path).map_err(Error::Io)?;
|
||||
|
||||
ron::from_str(&content)
|
||||
.map_err(|e| Error::Session(format!("Failed to parse session file {:?}: {}", path, e)))
|
||||
}
|
||||
|
||||
/// Saves all sessions to a RON file.
|
||||
#[allow(dead_code)]
|
||||
pub fn save_sessions(path: &Path, sessions: &[SessionData]) -> Result<()> {
|
||||
let content = ron::ser::to_string_pretty(sessions, ron::ser::PrettyConfig::default())
|
||||
.map_err(|e| Error::Session(format!("Failed to serialize sessions: {}", e)))?;
|
||||
|
||||
std::fs::write(path, content).map_err(Error::Io)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue