Skip to content

Commit 38a89a0

Browse files
committed
Make config extensions resilient
1 parent 97c117f commit 38a89a0

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src-tauri/src/libs/init.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ pub fn init() -> AnyResult<ConfigManager> {
2626
let existing_config = manager.toml::<Config>();
2727

2828
let config = match existing_config {
29-
Ok(config) => ConfigManager::new(manager, config),
29+
Ok(config) => {
30+
// Backfill any missing keys populated by serde defaults.
31+
manager.save_toml(&config).unwrap();
32+
33+
ConfigManager::new(manager, config)
34+
}
3035
Err(_) => {
3136
// The config does not exist, so let's instantiate it with defaults
32-
// Potential issue: if the config is extended, the defaults will be
33-
// reloaded
3437
let default_config = Config::default();
3538
manager.save_toml(&default_config).unwrap();
3639

src-tauri/src/plugins/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub enum TrackViewDensity {
5555

5656
#[derive(Serialize, Deserialize, Debug, Clone, TS)]
5757
#[ts(export, export_to = "../../src/generated/typings.ts")]
58+
#[serde(default)]
5859
pub struct Config {
5960
pub language: String,
6061
pub theme: String,
@@ -80,8 +81,8 @@ pub struct Config {
8081

8182
pub const SYSTEM_THEME: &str = "__system";
8283

83-
impl Config {
84-
pub fn default() -> Self {
84+
impl Default for Config {
85+
fn default() -> Self {
8586
Config {
8687
language: "en".to_owned(),
8788
theme: SYSTEM_THEME.to_owned(),

0 commit comments

Comments
 (0)