1use crate::AppConfig; 2use crate::input::GenericInput; 3use crate::input::mappings::HotkeyConfig; 4use serde::{Deserialize, Serialize}; 5 6pub fn migrate_config_0_8_3(config: &mut AppConfig, config_str: &str) { 7 #[derive(Debug, Clone, Default, Serialize, Deserialize)] 8 struct OldHotkeyMapping { 9 #[serde(default)] 10 pub quit: Option<Vec<GenericInput>>, 11 } 12 13 #[derive(Debug, Clone, Default, Serialize, Deserialize)] 14 struct OldHotkeyConfig { 15 #[serde(default)] 16 pub mapping_1: OldHotkeyMapping, 17 #[serde(default)] 18 pub mapping_2: OldHotkeyMapping, 19 } 20 21 #[derive(Debug, Clone, Default, Serialize, Deserialize)] 22 struct OldInputConfig { 23 #[serde(default)] 24 pub hotkeys: OldHotkeyConfig, 25 } 26 27 #[derive(Debug, Clone, Serialize, Deserialize)] 28 struct OldAppConfig { 29 #[serde(default)] 30 pub input: OldInputConfig, 31 } 32 33 // Quit hotkey renamed to PowerOff 34 if let Ok(mut old_config) = toml::from_str::<OldAppConfig>(config_str) { 35 if let Some(mapping) = old_config.input.hotkeys.mapping_1.quit.take() { 36 log::info!( 37 "Migrating hotkey mapping #1 for 'quit' to 'power_off': ({})", 38 stringify_mapping(&mapping) 39 ); 40 config.input.hotkeys.mapping_1.power_off = Some(mapping); 41 } 42 43 if let Some(mapping) = old_config.input.hotkeys.mapping_2.quit.take() { 44 log::info!( 45 "Migrating hotkey mapping #2 for 'quit' to 'power_off': ({})", 46 stringify_mapping(&mapping) 47 ); 48 config.input.hotkeys.mapping_2.power_off = Some(mapping); 49 } 50 } 51 52 // New hotkey Exit 53 if config.input.hotkeys.mapping_1.exit.is_none() { 54 let default = HotkeyConfig::default(); 55 if let Some(mapping) = default.mapping_1.exit { 56 log::info!( 57 "Setting default mapping for new 'exit' hotkey: ({})", 58 stringify_mapping(&mapping) 59 ); 60 config.input.hotkeys.mapping_1.exit = Some(mapping); 61 } 62 } 63} 64 65fn stringify_mapping(mapping: &[GenericInput]) -> String { 66 let strings: Vec<_> = mapping.iter().map(GenericInput::to_string).collect(); 67 strings.join(" + ") 68} 69 70pub fn migrate_config_0_8_4(config: &mut AppConfig) { 71 // New hotkey ToggleOverclocking 72 config.input.hotkeys.mapping_1.toggle_overclocking = 73 HotkeyConfig::default().mapping_1.toggle_overclocking; 74}