Skip to content

Commit

Permalink
misc: keep it simple for now and use json to store state
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaDve committed Jan 27, 2024
1 parent 8105ac7 commit 2070910
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
41 changes: 24 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ gtk_source = { package = "sourceview5", version = "0.7", features = ["v5_10"] }
indexmap = "2.1"
regex = "1.10.2"
serde = { version = "1", features = ["derive"] }
serde_cbor = "0.11.2"
serde_json = "1.0.112"
tracing = "0.1.37"
tracing-subscriber = "0.3"
webkit = { package = "webkit6", version = "0.2.0", features = ["v2_42"] }
6 changes: 3 additions & 3 deletions src/recent_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mod imp {

fn new() -> Self {
Self {
state_file: gio::File::for_path(APP_DATA_DIR.join("recents.cbor")),
state_file: gio::File::for_path(APP_DATA_DIR.join("recents.json")),
list: RefCell::new(IndexMap::new()),
}
}
Expand Down Expand Up @@ -80,7 +80,7 @@ impl RecentList {
let now = Instant::now();

let state = match imp.state_file.load_bytes_future().await {
Ok((bytes, _)) => serde_cbor::from_slice::<State>(&bytes)?,
Ok((bytes, _)) => serde_json::from_slice::<State>(&bytes)?,
Err(err) => {
if !err.matches(gio::IOErrorEnum::NotFound) {
return Err(err.into());
Expand Down Expand Up @@ -136,7 +136,7 @@ impl RecentList {
};
tracing::trace!(?state, "State stored");

let bytes = serde_cbor::to_vec(&state)?;
let bytes = serde_json::to_vec(&state)?;
imp.state_file
.replace_contents_future(
bytes,
Expand Down
6 changes: 3 additions & 3 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ mod imp {

fn new() -> Self {
Self {
state_file: gio::File::for_path(APP_DATA_DIR.join("state.cbor")),
state_file: gio::File::for_path(APP_DATA_DIR.join("state.json")),
default_window_width: Cell::new(DEFAULT_WINDOW_WIDTH),
default_window_height: Cell::new(DEFAULT_WINDOW_HEIGHT),
windows: RefCell::default(),
Expand Down Expand Up @@ -358,7 +358,7 @@ impl Session {
let now = Instant::now();

let state = match imp.state_file.load_bytes_future().await {
Ok((bytes, _)) => serde_cbor::from_slice::<State>(&bytes)?,
Ok((bytes, _)) => serde_json::from_slice::<State>(&bytes)?,
Err(err) => {
if !err.matches(gio::IOErrorEnum::NotFound) {
return Err(err.into());
Expand Down Expand Up @@ -417,7 +417,7 @@ impl Session {
};
tracing::trace!(?state, "State stored");

let bytes = serde_cbor::to_vec(&state)?;
let bytes = serde_json::to_vec(&state)?;
imp.state_file
.replace_contents_future(
bytes,
Expand Down

0 comments on commit 2070910

Please sign in to comment.