From 255ce14f3c36f5e1f2bf5e8242070d0129f15ac1 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Tue, 10 Oct 2023 18:21:12 +0200 Subject: feat: Add button to delete profile (#603) This adds a button and corresponding logic to delete an existing profile Spliced out from #444 Co-authored-by: Jan --- src-tauri/src/main.rs | 1 + src-tauri/src/northstar/profile.rs | 17 +++++++++++++++++ src-vue/src/i18n/lang/en.json | 6 +++++- src-vue/src/views/SettingsView.vue | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 66bb98d2..47cfee6a 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -160,6 +160,7 @@ fn main() { get_available_northstar_versions, northstar::profile::fetch_profiles, northstar::profile::validate_profile, + northstar::profile::delete_profile, ]) .run(tauri::generate_context!()) { diff --git a/src-tauri/src/northstar/profile.rs b/src-tauri/src/northstar/profile.rs index 78e734d0..b0c6c418 100644 --- a/src-tauri/src/northstar/profile.rs +++ b/src-tauri/src/northstar/profile.rs @@ -74,3 +74,20 @@ pub fn validate_profile(game_install: GameInstall, profile: String) -> bool { profile_dir.is_dir() } + +#[tauri::command] +pub fn delete_profile(game_install: GameInstall, profile: String) -> Result<(), String> { + // Check if the Profile actually exists + if !validate_profile(game_install.clone(), profile.clone()) { + return Err(format!("{} is not a valid Profile", profile)); + } + + log::info!("Deleting Profile {}", profile); + + let profile_path = format!("{}/{}", game_install.game_path, profile); + + match std::fs::remove_dir_all(profile_path) { + Ok(()) => Ok(()), + Err(err) => Err(format!("Failed to delete Profile: {}", err)), + } +} diff --git a/src-vue/src/i18n/lang/en.json b/src-vue/src/i18n/lang/en.json index 2b056655..2bf18c2e 100644 --- a/src-vue/src/i18n/lang/en.json +++ b/src-vue/src/i18n/lang/en.json @@ -11,6 +11,7 @@ "yes": "Yes", "no": "No", "error": "Error", + "confirm": "Confirm", "cancel": "Cancel", "informationShort": "Info", "downloading": "Downloading", @@ -115,7 +116,10 @@ "edit": "Edit Profiles", "dialog": { - "title": "Profiles" + "title": "Profiles", + "delete_confirm": "Are you sure to delete this profile?", + "delete": "Delete", + "clone": "Clone" } }, diff --git a/src-vue/src/views/SettingsView.vue b/src-vue/src/views/SettingsView.vue index 2219498c..70bffbc5 100644 --- a/src-vue/src/views/SettingsView.vue +++ b/src-vue/src/views/SettingsView.vue @@ -6,6 +6,23 @@ > + + + @@ -257,6 +274,24 @@ export default defineComponent({ showErrorNotification(error); }); }, + async deleteProfile(profile: string) { + let store = this.$store; + await invoke("delete_profile", { + gameInstall: store.state.game_install, + profile: profile, + }).then(async (message) => { + if (profile == store.state.game_install.profile) + { + // trying to delete the active profile, lets switch to the default profile + await this.switchProfile("R2Northstar"); + } + store.commit('fetchProfiles'); + showNotification('Success'); + }).catch((error) => { + console.error(error); + showErrorNotification(error); + }); + }, }, mounted() { document.querySelector('input')!.disabled = true; -- cgit v1.2.3