From f5acb86d3c3029d6a2ab23d5f47bc11432174562 Mon Sep 17 00:00:00 2001 From: Oguz Kagan EREN Date: Sat, 28 Mar 2026 22:54:08 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20#183?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 6 +++++- src/utils.rs | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 20744cc..ecb3016 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,7 +55,11 @@ fn get_saved_locale() -> Option { fn get_saved_json(preferences: &serde_json::Value) -> serde_json::Value { let save_path = fix_path(preferences["save_path"].as_str().unwrap()); if Path::new(&save_path).exists() { - read_json(save_path.as_str()) + let val = read_json(save_path.as_str()); + if val.is_null() { + return json!({"locale": ""}); + } + val } else { json!({"locale": ""}) } diff --git a/src/utils.rs b/src/utils.rs index fc8c51f..6e28d34 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -29,6 +29,9 @@ pub fn fix_path(path: &str) -> String { pub fn read_json(path: &str) -> serde_json::Value { let buf = fix_path(path); let data = fs::read_to_string(buf).expect("Unable to read file"); + if data.trim().is_empty() { + return serde_json::Value::Null; + } serde_json::from_str(&data).expect("Unable to parse") }