feat: add option to reset all configuration

This commit is contained in:
Ilya Zlobintsev 2024-09-07 22:28:15 +03:00
parent 4007e0a360
commit 74dda30925
8 changed files with 79 additions and 7 deletions

View File

@ -116,6 +116,7 @@ impl DaemonClient {
request_plain!(enable_overdrive, EnableOverdrive, String);
request_plain!(disable_overdrive, DisableOverdrive, String);
request_plain!(generate_debug_snapshot, GenerateSnapshot, String);
request_plain!(reset_config, RestConfig, ());
request_with_id!(get_device_info, DeviceInfo, DeviceInfo);
request_with_id!(get_device_stats, DeviceStats, DeviceStats);
request_with_id!(get_device_clocks_info, DeviceClocksInfo, ClocksInfo);

View File

@ -62,7 +62,7 @@ impl Default for Daemon {
pub struct Gpu {
pub fan_control_enabled: bool,
pub fan_control_settings: Option<FanControlSettings>,
#[serde(default)]
#[serde(default, skip_serializing_if = "PmfwOptions::is_empty")]
pub pmfw_options: PmfwOptions,
pub power_cap: Option<f64>,
pub performance_level: Option<PerformanceLevel>,
@ -70,9 +70,9 @@ pub struct Gpu {
pub clocks_configuration: ClocksConfiguration,
pub power_profile_mode_index: Option<u16>,
/// Outer vector is for power profile components, inner vector is for the heuristics within a component
#[serde(default)]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub custom_power_profile_mode_hueristics: Vec<Vec<Option<i32>>>,
#[serde(default)]
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub power_states: HashMap<PowerLevelKind, Vec<u8>>,
}

View File

@ -246,7 +246,7 @@ impl<'a> Handler {
config_guard.gpus.insert(id, new_config);
if let Err(err) = config_guard.save() {
error!("{err}");
error!("{err:#}");
}
*handler.config_last_saved.lock().unwrap() = Instant::now();
@ -604,7 +604,21 @@ impl<'a> Handler {
}
}
pub async fn cleanup(self) {
pub async fn reset_config(&self) {
self.cleanup().await;
let mut config = self.config.borrow_mut();
config.gpus.clear();
*self.config_last_saved.lock().unwrap() = Instant::now();
if let Err(err) = config.save() {
error!("could not save config: {err:#}");
}
*self.config_last_saved.lock().unwrap() = Instant::now();
}
pub async fn cleanup(&self) {
let disable_clocks_cleanup = self
.config
.try_borrow()

View File

@ -119,6 +119,10 @@ async fn handle_request<'a>(request: Request<'a>, handler: &'a Handler) -> anyho
Request::ConfirmPendingConfig(command) => {
ok_response(handler.confirm_pending_config(command)?)
}
Request::RestConfig => {
handler.reset_config().await;
ok_response(())
}
}
}

View File

@ -39,6 +39,8 @@ impl Header {
)
}
menu.append(Some("Reset all configuration"), Some("app.reset-config"));
let menu_button = MenuButton::builder()
.icon_name("open-menu-symbolic")
.menu_model(&menu)

View File

@ -281,11 +281,25 @@ impl App {
))
.build();
let reset_config_action = ActionEntry::builder("reset-config")
.activate(clone!(
#[strong]
app,
#[strong]
current_gpu_id,
move |_, _, _| {
let gpu_id = current_gpu_id.borrow().clone();
app.reset_config(gpu_id);
}
))
.build();
app.application.add_action_entries([
snapshot_action,
disable_overdive_action,
show_graphs_window_action,
dump_vbios_action,
reset_config_action,
]);
app.start_stats_update_loop(current_gpu_id);
@ -616,7 +630,7 @@ impl App {
.daemon_client
.batch_set_clocks_value(&gpu_id, clocks_commands)
.context("Could not commit clocks settings")?;
self.ask_confirmation(gpu_id.clone(), delay);
self.ask_settings_confirmation(gpu_id.clone(), delay);
}
self.set_initial(&gpu_id);
@ -809,7 +823,37 @@ impl App {
}
}
fn ask_confirmation(&self, gpu_id: String, mut delay: u64) {
fn reset_config(&self, gpu_id: String) {
let dialog = MessageDialog::builder()
.title("Reset configuration")
.text("Are you sure you want to reset all GPU configuration?")
.message_type(MessageType::Question)
.buttons(ButtonsType::YesNo)
.transient_for(&self.window)
.build();
dialog.run_async(clone!(
#[strong(rename_to = app)]
self,
move |diag, response| {
diag.hide();
if response == ResponseType::Yes {
if let Err(err) = app
.daemon_client
.reset_config()
.and_then(|response| response.inner())
{
show_error(&app.window, err);
}
app.set_initial(&gpu_id);
}
}
));
}
fn ask_settings_confirmation(&self, gpu_id: String, mut delay: u64) {
let text = confirmation_text(delay);
let dialog = MessageDialog::builder()
.title("Confirm settings")

View File

@ -277,6 +277,12 @@ pub struct PmfwOptions {
pub target_temperature: Option<u32>,
}
impl PmfwOptions {
pub fn is_empty(&self) -> bool {
*self == Self::default()
}
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
pub struct FanOptions<'a> {

View File

@ -61,6 +61,7 @@ pub enum Request<'a> {
DisableOverdrive,
GenerateSnapshot,
ConfirmPendingConfig(ConfirmCommand),
RestConfig,
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]