Merge pull request #197 from NotThorny/Config-Fix

Fix crashing on null configs
This commit is contained in:
SpikeHD 2023-08-30 12:24:44 -07:00 committed by GitHub
commit 1d4cf94643
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,7 @@ use std::path::PathBuf;
use std::string::String;
// Config may not exist, or may be old, so it's okay if these are optional
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Default)]
pub struct Configuration {
pub toggle_grasscutter: Option<bool>,
pub game_install_path: Option<String>,
@ -41,7 +41,7 @@ pub fn config_path() -> PathBuf {
pub fn get_config() -> Configuration {
let path = config_path();
let config = std::fs::read_to_string(path).unwrap_or("{}".to_string());
let config: Configuration = serde_json::from_str(&config).unwrap();
let config: Configuration = serde_json::from_str(&config).unwrap_or_default();
config
}