Serialize project to json

This commit is contained in:
Jaby 2025-03-19 20:47:21 +01:00
parent 7a197d9b71
commit d42fe2776c
4 changed files with 17 additions and 5 deletions

View File

@ -3677,9 +3677,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.137" version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "930cfb6e6abf99298aaad7d29abbef7a9999a9a8806a40088f55f0dcec03146b" checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
dependencies = [ dependencies = [
"itoa", "itoa",
"memchr", "memchr",
@ -4113,6 +4113,8 @@ version = "0.1.0"
dependencies = [ dependencies = [
"png", "png",
"rfd", "rfd",
"serde",
"serde_json",
"slint", "slint",
"slint-build", "slint-build",
"tiny-skia", "tiny-skia",

View File

@ -11,6 +11,8 @@ png = "0.17.16"
rfd = "0.15.2" rfd = "0.15.2"
slint = "1.9.2" slint = "1.9.2"
tiny-skia = "0.11.4" tiny-skia = "0.11.4"
serde = {version = "1.0.140", features = ["derive"]}
serde_json = "1.0"
tool_helper = {path = "../tool_helper"} tool_helper = {path = "../tool_helper"}
[build-dependencies] [build-dependencies]

View File

@ -95,7 +95,14 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
project.push(cur_job); project.push(cur_job);
} }
Err(Error::from_text(format!("Adding {:?} jobs", project))) let string = match serde_json::to_string(&project) {
Ok(string) => string,
Err(error) => {
return Err(Error::from_error(error));
}
};
Err(Error::from_text(format!("Adding {} jobs", string)))
} }
} }

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
use std::path::PathBuf; use std::path::PathBuf;
#[derive(Debug)] #[derive(Debug, Serialize, Deserialize)]
pub struct Job { pub struct Job {
name: String, name: String,
file_path: PathBuf, file_path: PathBuf,
@ -12,7 +13,7 @@ impl Job {
} }
} }
#[derive(Debug)] #[derive(Debug, Serialize, Deserialize)]
pub struct Project { pub struct Project {
jobs: Vec<Job> jobs: Vec<Job>
} }