Skip to content

Commit

Permalink
fix(Performance Menu): ensure default profile is set on app close
Browse files Browse the repository at this point in the history
> - ensure options hidden/shown on performance profile change
  • Loading branch information
ShadowApex committed Dec 21, 2024
1 parent f468c0d commit 9d825ab
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions core/global/launch_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class_name LaunchManager
## launch_manager.stop(running_app)
## [/codeblock]

signal all_apps_stopped()
signal app_launched(app: RunningApp)
signal app_stopped(app: RunningApp)
signal app_switched(from: RunningApp, to: RunningApp)
Expand Down Expand Up @@ -468,6 +469,7 @@ func _on_app_state_changed(from: RunningApp.STATE, to: RunningApp.STATE, app: Ru
_xwayland_primary.remove_baselayer_window()
state_machine.remove_state(in_game_state)
state_machine.remove_state(in_game_menu_state)
all_apps_stopped.emit()


# Removes the given PID from our list of running apps
Expand Down
18 changes: 18 additions & 0 deletions core/systems/performance/performance_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func _init() -> void:
# Listen for signals when the current app switches so we can update the profile
# accordingly.
_launch_manager.app_switched.connect(_on_app_switched)
_launch_manager.all_apps_stopped.connect(_on_all_apps_stopped)

# Connect to battery state changes to switch between "docked" and "undocked"
# performance profiles.
Expand Down Expand Up @@ -283,6 +284,23 @@ func _on_battery_updated(battery: UPowerDevice) -> void:
apply_profile(profile)


## Sets the default performance profile when all running apps have stopped
func _on_all_apps_stopped() -> void:
logger.debug("Detected all apps stopped")

# Get the current profile state to see if we need to load the docked or
# undocked profile.
var profile_state := get_profile_state()

# Load the performance profile based on the running game
var profile_path := get_profile_filename(profile_state)
profile_path = "/".join([USER_PROFILES, profile_path])
var profile := load_or_create_profile(profile_path)
current_profile = profile
profile_loaded.emit(profile)
apply_profile(profile)


## Called whenever an app is switched. E.g. when a game is launched
func _on_app_switched(_from: RunningApp, to: RunningApp) -> void:
logger.debug("Detected app switch")
Expand Down
10 changes: 8 additions & 2 deletions core/ui/common/quick_bar/performance_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var _performance_manager := load("res://core/systems/performance/performance_man
var _power_station := load("res://core/systems/performance/power_station.tres") as PowerStationInstance
var _profiles_available: PackedStringArray

@onready var focus_group := $%FocusGroup as FocusGroup
@onready var cpu_boost_button := $CPUBoostButton as Toggle
@onready var cpu_cores_slider := $CPUCoresSlider as ValueSlider
@onready var gpu_freq_enable := $GPUFreqButton as Toggle
Expand Down Expand Up @@ -238,8 +239,13 @@ func _setup_interface() -> void:
# Configure visibility for all components
wait_label.visible = false

var is_advanced := mode_toggle.button_pressed

var is_advanced := false
if _current_profile:
is_advanced = _current_profile.advanced_mode
if mode_toggle.button_pressed != is_advanced:
mode_toggle.button_pressed = is_advanced
focus_group.current_focus = mode_toggle

# Configure CPU components
if _power_station.cpu:
var cpu := _power_station.cpu
Expand Down
1 change: 1 addition & 0 deletions core/ui/common/quick_bar/performance_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ grow_horizontal = 2
script = ExtResource("1_r31yj")

[node name="FocusGroup" parent="." instance=ExtResource("2_my16i")]
unique_name_in_owner = true
focus_stack = ExtResource("3_hsr7n")

[node name="ApplyTimer" type="Timer" parent="."]
Expand Down

0 comments on commit 9d825ab

Please sign in to comment.