Skip to content

Commit 7d7c00f

Browse files
authored
reset settings after finished installation (#310)
1 parent 6313e58 commit 7d7c00f

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

src-tauri/src/gui/app_state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ pub struct WizardData {
1717
/// Application state that is managed by Tauri and accessible across commands
1818
#[derive(Default, Serialize, Deserialize)]
1919
pub struct AppState {
20-
wizard_data: Mutex<WizardData>,
21-
settings: Mutex<Settings>,
22-
is_installing: Mutex<bool>,
20+
pub wizard_data: Mutex<WizardData>,
21+
pub settings: Mutex<Settings>,
22+
pub is_installing: Mutex<bool>,
2323
}
2424

2525
/// Gets the current settings from the app state

src-tauri/src/gui/commands/settings.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use tauri::{AppHandle, Manager};
2-
use idf_im_lib::{settings,to_absolute_path, utils::is_valid_idf_directory};
2+
use idf_im_lib::{settings::{self, Settings},to_absolute_path, utils::is_valid_idf_directory};
33
use crate::gui::{
44
app_state::{self, get_locked_settings, get_settings_non_blocking, update_settings, AppState},
55
ui::send_message,
@@ -370,3 +370,17 @@ pub async fn is_path_empty_or_nonexistent_command(app_handle: AppHandle, path: S
370370
pub async fn is_path_idf_directory(_app_handle: AppHandle, path: String) -> bool {
371371
is_valid_idf_directory(&path)
372372
}
373+
374+
/// Resets the settings to their default values
375+
#[tauri::command]
376+
pub fn reset_settings_to_default(app_handle: AppHandle) -> Result<(), String> {
377+
let app_state = app_handle.state::<AppState>();
378+
let mut settings = app_state.settings.lock().map_err(|_| {
379+
"Failed to obtain lock on AppState. Please retry the last action later.".to_string()
380+
})?;
381+
382+
*settings = Settings::default();
383+
log::info!("Settings reset to default values");
384+
385+
Ok(())
386+
}

src-tauri/src/gui/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ pub fn run(leg_level_override: Option<log::LevelFilter>) {
274274
get_features_list_all_versions,
275275
set_selected_features_per_version,
276276
get_selected_features_per_version,
277+
reset_settings_to_default,
277278
])
278279
.run(tauri::generate_context!())
279280
.expect("error while running tauri application");

src/components/wizard_steps/Complete.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ export default {
128128
},
129129
mounted() {
130130
this.get_os();
131+
},
132+
beforeUnmount() {
133+
const _ = invoke("reset_settings_to_default", {});
131134
}
132135
}
133136
</script>

0 commit comments

Comments
 (0)