diff --git a/lua/main.lua b/lua/main.lua index 5cbbf0a6..4291c3da 100644 --- a/lua/main.lua +++ b/lua/main.lua @@ -1,8 +1,13 @@ local font = require("font") local vol = require("volume") +local controls = require("controls") +local time = require("time") + +local lock_time = time.ticks() -- Set up property bindings that are used across every screen. GLOBAL_BINDINGS = { + -- Show an alert with the current volume whenver the volume changes. vol.current_pct:bind(function(pct) require("alerts").show(function() local container = lvgl.Object(nil, { @@ -32,6 +37,18 @@ GLOBAL_BINDINGS = { container:center() end) end), + -- When the device has been locked for a while, default to showing the now + -- playing screen after unlocking. + controls.lock_switch:bind(function(locked) + if locked then + lock_time = time.ticks() + elseif time.ticks() - lock_time > 8000 then + local queue = require("queue") + if queue.size:get() > 0 then + require("playing"):pushIfNotShown() + end + end + end), } local backstack = require("backstack") diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index 6cf2ba4c..07937559 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -129,6 +129,7 @@ class UiState : public tinyfsm::Fsm { static lua::Property sControlsScheme; static lua::Property sScrollSensitivity; + static lua::Property sLockSwitch; static lua::Property sDatabaseUpdating; }; diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index 5c22e90e..1a9f01b4 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -280,6 +280,8 @@ lua::Property UiState::sScrollSensitivity{ return true; }}; +lua::Property UiState::sLockSwitch{false}; + lua::Property UiState::sDatabaseUpdating{false}; auto UiState::InitBootSplash(drivers::IGpios& gpios) -> bool { @@ -326,6 +328,7 @@ int UiState::PopScreen() { void UiState::react(const system_fsm::KeyLockChanged& ev) { sDisplay->SetDisplayOn(!ev.locking); sInput->lock(ev.locking); + sLockSwitch.Update(ev.locking); } void UiState::react(const internal::ControlSchemeChanged&) { @@ -516,6 +519,7 @@ void Lua::entry() { { {"scheme", &sControlsScheme}, {"scroll_sensitivity", &sScrollSensitivity}, + {"lock_switch", &sLockSwitch}, }); registry.AddPropertyModule(