added filesystem abstraction layer and implemented basic filesystem - testing not complete yet, still features missing
Continuous integration / build (push) Has been cancelled

This commit is contained in:
2025-08-21 23:07:46 +01:00
parent c891a8be58
commit 9614d2884b
12 changed files with 477 additions and 348 deletions
+17 -12
View File
@@ -1,13 +1,19 @@
use std::fs;
use std::path::Path;
use egui::TextEdit;
use serde::{Deserialize, Serialize};
use crate::{PROJECT_FOLDER, editors::tags::Tag, util};
use crate::{
editors::tags::Tag,
filesystem::{FILESYSTEM, LegacyFileSystem},
util,
};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Note {
pub id: String,
pub name: String,
#[serde(default)]
pub content: String,
#[serde(default)]
@@ -17,12 +23,14 @@ pub struct Note {
pub tags: Vec<String>,
#[serde(skip)]
pub id: String,
#[serde(skip)]
#[serde(default = "default_saved")]
pub saved: bool,
}
pub fn default_saved() -> bool {
true
}
impl Default for Note {
fn default() -> Self {
Self {
@@ -48,18 +56,15 @@ impl Note {
}
}
pub fn save(&mut self) -> std::io::Result<()> {
pub fn save(&mut self) -> Result<(), Box<dyn std::error::Error>> {
let id = &self.id;
let path = PROJECT_FOLDER.join("notes").join(format!("{id}.json"));
fs::write(path, serde_json::to_string(&self)?)?;
FILESYSTEM.write(Path::new(&format!("notes/{id}.json")), self.clone())?;
self.saved = true;
Ok(())
}
pub fn load(id: &str) -> std::io::Result<Self> {
let path = PROJECT_FOLDER.join("notes").join(format!("{id}.json"));
let content = fs::read_to_string(path)?;
let mut note: Note = serde_json::from_str(&content)?;
pub fn load(id: &str) -> Result<Self, Box<dyn std::error::Error>> {
let mut note: Self = FILESYSTEM.read(Path::new(&format!("notes/{id}.json")))?;
note.id = id.to_string();
note.saved = true;
Ok(note)