readability: MAX_POLL_FRAMES, _poll_for_power_menu, BUTTON_LABEL
This commit is contained in:
parent
e611e16651
commit
005412fa71
1 changed files with 6 additions and 5 deletions
11
plugin.gd
11
plugin.gd
|
|
@ -10,7 +10,8 @@ extends Plugin
|
||||||
const SESSION_SELECT_PATH := "/usr/lib/os-session-select"
|
const SESSION_SELECT_PATH := "/usr/lib/os-session-select"
|
||||||
const POWER_MENU_GROUP := "power_menu"
|
const POWER_MENU_GROUP := "power_menu"
|
||||||
const BUTTON_NAME := "SwitchToSteamButton"
|
const BUTTON_NAME := "SwitchToSteamButton"
|
||||||
const MAX_ATTEMPTS := 600
|
const BUTTON_LABEL := "Switch to Steam"
|
||||||
|
const MAX_POLL_FRAMES := 600
|
||||||
|
|
||||||
# ChimeraOS records the session that was active before OpenGamepadUI took over
|
# ChimeraOS records the session that was active before OpenGamepadUI took over
|
||||||
# in this file when the OpenGamepadUI session is entered. We return to that
|
# in this file when the OpenGamepadUI session is entered. We return to that
|
||||||
|
|
@ -35,11 +36,11 @@ func _ready() -> void:
|
||||||
if not _has_session_switcher():
|
if not _has_session_switcher():
|
||||||
logger.info("No session switcher script detected: " + SESSION_SELECT_PATH)
|
logger.info("No session switcher script detected: " + SESSION_SELECT_PATH)
|
||||||
return
|
return
|
||||||
_add_button_when_ready()
|
_poll_for_power_menu()
|
||||||
|
|
||||||
|
|
||||||
func _add_button_when_ready() -> void:
|
func _poll_for_power_menu() -> void:
|
||||||
for i in MAX_ATTEMPTS:
|
for i in MAX_POLL_FRAMES:
|
||||||
if _try_add_button():
|
if _try_add_button():
|
||||||
return
|
return
|
||||||
await get_tree().process_frame
|
await get_tree().process_frame
|
||||||
|
|
@ -68,7 +69,7 @@ func _try_add_button() -> bool:
|
||||||
var button := button_scene.instantiate()
|
var button := button_scene.instantiate()
|
||||||
button.name = BUTTON_NAME
|
button.name = BUTTON_NAME
|
||||||
button.set("click_focuses", false)
|
button.set("click_focuses", false)
|
||||||
button.set("text", "Switch to Steam")
|
button.set("text", BUTTON_LABEL)
|
||||||
button.pressed.connect(_switch_session)
|
button.pressed.connect(_switch_session)
|
||||||
|
|
||||||
container.add_child(button)
|
container.add_child(button)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue