Add option for enable/disable apply AC/Bat policy on change

This commit is contained in:
Luke D. Jones
2024-05-12 11:55:34 +12:00
parent 92ca7bc70d
commit 6c7e1a6467
9 changed files with 150 additions and 81 deletions

View File

@@ -60,7 +60,19 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc<Mutex<Config>>)
set_ui_props_async!(handle, platform, SystemPageData, throttle_performance_epp);
set_ui_props_async!(handle, platform, SystemPageData, throttle_quiet_epp);
set_ui_props_async!(handle, platform, SystemPageData, throttle_policy_on_battery);
set_ui_props_async!(
handle,
platform,
SystemPageData,
change_throttle_policy_on_battery
);
set_ui_props_async!(handle, platform, SystemPageData, throttle_policy_on_ac);
set_ui_props_async!(
handle,
platform,
SystemPageData,
change_throttle_policy_on_ac
);
set_ui_props_async!(handle, platform, SystemPageData, panel_od);
set_ui_props_async!(handle, platform, SystemPageData, boot_sound);
@@ -94,6 +106,7 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc<Mutex<Config>>)
throttle_thermal_policy: sys_props.contains(&Properties::ThrottlePolicy),
};
// TODO: move the fail/sucess messages to slint
handle
.upgrade_in_event_loop(move |handle| {
handle.global::<SystemPageData>().set_available(props);
@@ -163,13 +176,24 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc<Mutex<Config>>)
"Throttle policy on AC set to {}",
"Setting Throttle policy on AC failed"
);
set_ui_callbacks!(handle,
SystemPageData(as bool),
platform.change_throttle_policy_on_ac(.into()),
"Throttle policy on AC enabled: {}",
"Setting Throttle policy on AC failed"
);
set_ui_callbacks!(handle,
SystemPageData(as i32),
platform.throttle_policy_on_battery(.into()),
"Throttle policy on abttery set to {}",
"Setting Throttle policy on battery failed"
);
set_ui_callbacks!(handle,
SystemPageData(as bool),
platform.change_throttle_policy_on_battery(.into()),
"Throttle policy on battery enabled: {}",
"Setting Throttle policy on AC failed"
);
set_ui_callbacks!(handle,
SystemPageData(as f32),
platform.ppt_pl1_spl(as u8),

View File

@@ -43,8 +43,12 @@ export global SystemPageData {
callback set_throttle_policy_linked_epp(bool);
in-out property <int> throttle_policy_on_ac: 0;
callback set_throttle_policy_on_ac(int);
in-out property <bool> change_throttle_policy_on_ac: true;
callback set_change_throttle_policy_on_ac(bool);
in-out property <int> throttle_policy_on_battery: 0;
callback set_throttle_policy_on_battery(int);
in-out property <bool> change_throttle_policy_on_battery: true;
callback set_change_throttle_policy_on_battery(bool);
in-out property <bool> panel_od;
callback set_panel_od(bool);
in-out property <bool> boot_sound;
@@ -340,23 +344,45 @@ export component PageSystem inherits Rectangle {
text: @tr("Throttle Policy for power state");
}
SystemDropdown {
text: @tr("Throttle Policy on Battery");
current_index <=> SystemPageData.throttle_policy_on_battery;
current_value: SystemPageData.throttle_policy_choices[SystemPageData.throttle_policy_on_battery];
model <=> SystemPageData.throttle_policy_choices;
selected => {
SystemPageData.set_throttle_policy_on_battery(SystemPageData.throttle_policy_on_battery)
HorizontalLayout {
spacing: 10px;
SystemDropdown {
text: @tr("Throttle Policy on Battery");
current_index <=> SystemPageData.throttle_policy_on_battery;
current_value: SystemPageData.throttle_policy_choices[SystemPageData.throttle_policy_on_battery];
model <=> SystemPageData.throttle_policy_choices;
selected => {
SystemPageData.set_throttle_policy_on_battery(SystemPageData.throttle_policy_on_battery)
}
}
SystemToggle {
text: @tr("Enabled");
checked <=> SystemPageData.change_throttle_policy_on_battery;
toggled => {
SystemPageData.set_change_throttle_policy_on_battery(SystemPageData.change_throttle_policy_on_battery);
}
}
}
SystemDropdown {
text: @tr("Throttle Policy on AC");
current_index <=> SystemPageData.throttle_policy_on_ac;
current_value: SystemPageData.throttle_policy_choices[SystemPageData.throttle_policy_on_ac];
model <=> SystemPageData.throttle_policy_choices;
selected => {
SystemPageData.set_throttle_policy_on_ac(SystemPageData.throttle_policy_on_ac)
HorizontalLayout {
spacing: 10px;
SystemDropdown {
text: @tr("Throttle Policy on AC");
current_index <=> SystemPageData.throttle_policy_on_ac;
current_value: SystemPageData.throttle_policy_choices[SystemPageData.throttle_policy_on_ac];
model <=> SystemPageData.throttle_policy_choices;
selected => {
SystemPageData.set_throttle_policy_on_ac(SystemPageData.throttle_policy_on_ac)
}
}
SystemToggle {
text: @tr("Enabled");
checked <=> SystemPageData.change_throttle_policy_on_ac;
toggled => {
SystemPageData.set_change_throttle_policy_on_ac(SystemPageData.change_throttle_policy_on_ac);
}
}
}
}

View File

@@ -5,7 +5,8 @@ export component RogItem inherits Rectangle {
border-color: Palette.border;
border-width: 3px;
border-radius: 10px;
min-height: 46px;
min-height: 48px;
max-height: 56px;
}
export component SystemSlider inherits RogItem {
@@ -54,6 +55,7 @@ export component SystemToggle inherits RogItem {
in-out property <bool> checked;
callback toggled(bool);
HorizontalLayout {
spacing: 6px;
HorizontalLayout {
alignment: LayoutAlignment.start;
padding-left: 10px;
@@ -195,7 +197,7 @@ export component PopupNotification {
}
}
public function show() {
public function show(){
_p.show();
}
}