Skip to content

Commit

Permalink
feat: Add button to delete profile
Browse files Browse the repository at this point in the history
This adds a button and corresponding logic to delete an existing profile

Spliced out from #444

Co-authored-by: Jan <[email protected]>
  • Loading branch information
GeckoEidechse and Jan200101 committed Oct 9, 2023
1 parent 1ebefbb commit 0d7c7ec
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!())
{
Expand Down
17 changes: 17 additions & 0 deletions src-tauri/src/northstar/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}
6 changes: 5 additions & 1 deletion src-vue/src/i18n/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"yes": "Yes",
"no": "No",
"error": "Error",
"confirm": "Confirm",
"cancel": "Cancel",
"informationShort": "Info",
"downloading": "Downloading",
Expand Down Expand Up @@ -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"
}
},

Expand Down
35 changes: 35 additions & 0 deletions src-vue/src/views/SettingsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@
>
<el-table :data="availableProfiles" >
<el-table-column prop="name" label="Name" />
<el-table-column align="right">
<template #default="scope">
<el-popconfirm
v-if="scope.row.name != 'R2Northstar'"
:title="$t('settings.profile.dialog.delete_confirm')"
:confirm-button-text="$t('generic.yes')"
:cancel-button-text="$t('generic.no')"
@confirm="deleteProfile(scope.row.name)"
>
<template #reference>
<el-button type="danger">
{{ $t('settings.profile.dialog.delete') }}
</el-button>
</template>
</el-popconfirm>
</template>
</el-table-column>
</el-table>
</el-dialog>

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0d7c7ec

Please sign in to comment.