Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ fn get_saved_locale() -> Option<String> {
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": ""})
}
Expand Down
3 changes: 3 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down