Add force remove remote

This commit is contained in:
Ward from fusion-voyager-3 2024-09-28 23:03:39 +03:00
parent ac17a93abf
commit ac7c1ab569
2 changed files with 65 additions and 14 deletions

View File

@ -141,5 +141,8 @@
"flatpak_remote_add_error_dialog_heading": "Flatpak Remote Changes Failed Error:",
"flatpak_remote_add_error_dialog_ok_label": "OK",
"flatpak_remote_add_name_prefrencesgroup_title": "Remote Name",
"flatpak_remote_add_url_prefrencesgroup_title": "Remote Ref URL (flatpakrepo)"
"flatpak_remote_add_url_prefrencesgroup_title": "Remote Ref URL (flatpakrepo)",
"flatpak_remote_add_error_dialog_used_error_body": "Should We Force Remove The Remote Alongside Everything Using It?",
"flatpak_remote_add_error_used_no_label": "No",
"flatpak_remote_add_error_used_yes_label": "Yes"
}

View File

@ -328,18 +328,18 @@ pub fn flatpak_manage_page(
|_|
{
{
let (mut installation, mut remote_name): (libflatpak::Installation, libflatpak::glib::GString);
let (mut installation, mut remote_name, mut cmd_installation): (libflatpak::Installation, libflatpak::glib::GString, String);
{
let flatpak_remotes_selection_model = flatpak_remotes_selection_model_rc.borrow();
let selection = flatpak_remotes_selection_model.selected_item().unwrap();
let item = selection.downcast_ref::<BoxedAnyObject>().unwrap();
let flatpak_remote: Ref<FlatpakRemote> = item.borrow();
(installation, remote_name) = match flatpak_remote.deref() {
(installation, remote_name, cmd_installation) = match flatpak_remote.deref() {
FlatpakRemote::System(remote) => {
(libflatpak::Installation::new_system(cancellable_no).unwrap(), remote.name().unwrap_or_default())
(libflatpak::Installation::new_system(cancellable_no).unwrap(), remote.name().unwrap_or_default(), "--system".to_string())
}
FlatpakRemote::User(remote) => {
(libflatpak::Installation::new_user(cancellable_no).unwrap(), remote.name().unwrap_or_default())
(libflatpak::Installation::new_user(cancellable_no).unwrap(), remote.name().unwrap_or_default(), "--user".to_string())
}
};
}
@ -347,6 +347,34 @@ pub fn flatpak_manage_page(
Ok(_) => {
retry_signal_action.activate(None);
}
Err(e) => {
match e.matches(libflatpak::Error::RemoteUsed) {
true => {
let flatpak_remote_add_error_dialog = adw::MessageDialog::builder()
.heading(t!("flatpak_remote_add_error_dialog_heading"))
.body(e.to_string() + "\n" + &t!("flatpak_remote_add_error_dialog_used_error_body").to_string())
.build();
flatpak_remote_add_error_dialog.add_response(
"flatpak_remote_add_error_dialog_used_no",
&t!("flatpak_remote_add_error_used_no_label").to_string(),
);
flatpak_remote_add_error_dialog.add_response(
"flatpak_remote_add_error_dialog_used_yes",
&t!("flatpak_remote_add_error_used_yes_label").to_string(),
);
flatpak_remote_add_error_dialog.set_response_appearance(
"flatpak_remote_add_error_dialog_used_yes",
adw::ResponseAppearance::Destructive,
);
let retry_signal_action_clone0 = retry_signal_action.clone();
flatpak_remote_add_error_dialog.clone()
.choose(None::<&gio::Cancellable>, move |choice| {
match choice.as_str() {
"flatpak_remote_add_error_dialog_used_yes" => {
match duct::cmd!("flatpak", "remote-delete", "--force", "--noninteractive", &cmd_installation, &remote_name).run() {
Ok(_) => {
retry_signal_action_clone0.activate(None);
}
Err(e) => {
let flatpak_remote_add_error_dialog = adw::MessageDialog::builder()
.heading(t!("flatpak_remote_add_error_dialog_heading"))
@ -360,6 +388,26 @@ pub fn flatpak_manage_page(
}
}
}
_ => {}
}
}
);
}
false => {
let flatpak_remote_add_error_dialog = adw::MessageDialog::builder()
.heading(t!("flatpak_remote_add_error_dialog_heading"))
.body(e.to_string())
.build();
flatpak_remote_add_error_dialog.add_response(
"flatpak_remote_add_error_dialog_ok",
&t!("flatpak_remote_add_error_dialog_ok_label").to_string(),
);
flatpak_remote_add_error_dialog.present();
}
}
}
}
}
}
)
);