Show the now playing screen after being locked for a while

custom
jacqueline 1 year ago
parent ef72b25660
commit eba5adeb8c
  1. 17
      lua/main.lua
  2. 1
      src/ui/include/ui_fsm.hpp
  3. 4
      src/ui/ui_fsm.cpp

@ -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")

@ -129,6 +129,7 @@ class UiState : public tinyfsm::Fsm<UiState> {
static lua::Property sControlsScheme;
static lua::Property sScrollSensitivity;
static lua::Property sLockSwitch;
static lua::Property sDatabaseUpdating;
};

@ -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(

Loading…
Cancel
Save