Skip to content

Commit 082e0e5

Browse files
committed
refactor: use custom json marshaler
sorts the keys; this is to make easier for users to edit their settings through the file
1 parent 9bcd25c commit 082e0e5

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src-tauri/src/json.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use std::collections::BTreeMap;
2+
use tauri_plugin_svelte::{Marshaler, MarshalingError, StoreState};
3+
4+
pub struct JsonMarshaler;
5+
6+
impl Marshaler for JsonMarshaler {
7+
fn serialize(&self, state: &StoreState) -> Result<Vec<u8>, MarshalingError> {
8+
let ordered: BTreeMap<_, _> = state.entries().collect();
9+
Ok(serde_json::to_vec_pretty(&ordered)?)
10+
}
11+
12+
fn deserialize(&self, bytes: &[u8]) -> Result<StoreState, MarshalingError> {
13+
Ok(serde_json::from_slice(bytes)?)
14+
}
15+
16+
fn extension(&self) -> &'static str {
17+
"json"
18+
}
19+
}

src-tauri/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use tauri::async_runtime::{self, Mutex};
1111
use tauri::ipc::Invoke;
1212
use tauri::{Manager, WindowEvent};
1313
use tauri_plugin_cache::{CacheConfig, CompressionMethod};
14-
use tauri_plugin_svelte::{ManagerExt, PrettyJsonMarshaler};
14+
use tauri_plugin_svelte::ManagerExt;
1515
use twitch_api::HelixClient;
1616
use twitch_api::twitch_oauth2::{AccessToken, UserToken};
1717

@@ -20,6 +20,7 @@ mod commands;
2020
mod error;
2121
mod eventsub;
2222
mod irc;
23+
mod json;
2324
mod log;
2425
mod server;
2526
mod seventv;
@@ -94,7 +95,7 @@ pub fn run() {
9495

9596
let svelte = tauri_plugin_svelte::Builder::new()
9697
.path(app_handle.path().app_data_dir()?)
97-
.marshaler(Box::new(PrettyJsonMarshaler))
98+
.marshaler(Box::new(json::JsonMarshaler))
9899
.build();
99100

100101
app_handle.plugin(svelte)?;

0 commit comments

Comments
 (0)