feat: use ScrolledWindow for initramfs output when enabling/disabling oc (#364)

This commit is contained in:
Ilya Zlobintsev 2024-08-30 13:08:41 +03:00 committed by GitHub
parent 44704a101e
commit 54ef929b1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -675,40 +675,38 @@ impl App {
.transient_for(&self.window) .transient_for(&self.window)
.build(); .build();
dialog.run_async(clone!(#[strong(rename_to = app)] self, move |diag, response| { dialog.run_async(clone!(
if response == ResponseType::Ok { #[strong(rename_to = app)]
let handle = gio::spawn_blocking(|| { self,
let (daemon_client, _) = create_connection().expect("Could not create new daemon connection"); move |diag, response| {
daemon_client.enable_overdrive().and_then(|buffer| buffer.inner()) if response == ResponseType::Ok {
}); let handle = gio::spawn_blocking(|| {
let (daemon_client, _) =
create_connection().expect("Could not create new daemon connection");
daemon_client
.enable_overdrive()
.and_then(|buffer| buffer.inner())
});
let dialog = app.spinner_dialog("Turning overclocking on (this may take a while)"); let dialog =
dialog.show(); app.spinner_dialog("Regenerating initramfs (this may take a while)");
dialog.show();
glib::spawn_future_local(async move { glib::spawn_future_local(async move {
let result = handle.await.unwrap(); let result = handle.await.unwrap();
dialog.hide(); dialog.hide();
match result { match result {
Ok(msg) => { Ok(msg) => oc_toggled_dialog(true, &msg),
let success_dialog = MessageDialog::builder() Err(err) => {
.title("Success") show_error(&app.window, err);
.text(format!("Overclocking successfully enabled. A system reboot is required to apply the changes.\nSystem message: {msg}")) }
.message_type(MessageType::Info)
.buttons(ButtonsType::Ok)
.build();
success_dialog.run_async(move |diag, _| {
diag.hide();
});
} }
Err(err) => { });
show_error(&app.window, err); }
} diag.hide();
}
});
} }
diag.hide(); ));
}));
} }
fn disable_overclocking(&self) { fn disable_overclocking(&self) {
@ -721,40 +719,36 @@ impl App {
.transient_for(&self.window) .transient_for(&self.window)
.build(); .build();
dialog.run_async(clone!(#[strong(rename_to = app)] self, move |diag, _| { dialog.run_async(clone!(
diag.hide(); #[strong(rename_to = app)]
self,
move |diag, _| {
diag.hide();
let handle = gio::spawn_blocking(|| { let handle = gio::spawn_blocking(|| {
let (daemon_client, _) = create_connection().expect("Could not create new daemon connection"); let (daemon_client, _) =
daemon_client.disable_overdrive().and_then(|buffer| buffer.inner()) create_connection().expect("Could not create new daemon connection");
}); daemon_client
.disable_overdrive()
.and_then(|buffer| buffer.inner())
});
let dialog = app.spinner_dialog("Turning overclocking off (this may take a while)"); let dialog = app.spinner_dialog("Regenerating initramfs (this may take a while)");
dialog.show(); dialog.show();
glib::spawn_future_local(async move { glib::spawn_future_local(async move {
let result = handle.await.unwrap(); let result = handle.await.unwrap();
dialog.hide(); dialog.hide();
match result { match result {
Ok(msg) => { Ok(msg) => oc_toggled_dialog(false, &msg),
let success_dialog = MessageDialog::builder() Err(err) => {
.title("Success") show_error(&app.window, err);
.text(format!("Overclocking successfully disabled. A system reboot is required to apply the changes.\nSystem message: {msg}")) }
.message_type(MessageType::Info)
.buttons(ButtonsType::Ok)
.build();
success_dialog.run_async(move |diag, _| {
diag.hide();
});
} }
Err(err) => { });
show_error(&app.window, err); }
} ));
}
});
}));
} }
fn dump_vbios(&self, gpu_id: &str) { fn dump_vbios(&self, gpu_id: &str) {
@ -912,6 +906,47 @@ fn show_error(parent: &ApplicationWindow, err: anyhow::Error) {
}) })
} }
fn oc_toggled_dialog(enabled: bool, msg: &str) {
let enabled_text = if enabled { "enabled" } else { "disabled" };
let child = Box::builder()
.orientation(Orientation::Vertical)
.spacing(5)
.margin_top(10)
.margin_bottom(10)
.margin_start(10)
.margin_end(10)
.build();
child.append(&Label::new(Some(&format!("Overclocking successfully {enabled_text}. A system reboot is required to apply the changes.\nSystem message:"))));
let msg_label = Label::builder()
.label(msg)
.valign(Align::Start)
.halign(Align::Start)
.build();
let msg_scrollable = ScrolledWindow::builder().child(&msg_label).build();
child.append(&msg_scrollable);
let ok_button = Button::builder().label("OK").build();
child.append(&ok_button);
let success_dialog = MessageDialog::builder()
.title("Success")
.child(&child)
.message_type(MessageType::Info)
.build();
ok_button.connect_clicked(clone!(
#[strong]
success_dialog,
move |_| success_dialog.hide(),
));
success_dialog.run_async(move |diag, _| {
diag.hide();
});
}
fn confirmation_text(seconds_left: u64) -> String { fn confirmation_text(seconds_left: u64) -> String {
format!("Do you want to keep the new settings? (Reverting in {seconds_left} seconds)") format!("Do you want to keep the new settings? (Reverting in {seconds_left} seconds)")
} }