Skip to content

Commit

Permalink
Create custom screensaver
Browse files Browse the repository at this point in the history
  • Loading branch information
1hitsong committed Jul 30, 2024
1 parent 189aec5 commit 7cddce1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 8 deletions.
55 changes: 47 additions & 8 deletions components/scenes/BaseScene.bs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ sub init()
m.top.backgroundColor = "#262626"
m.top.backgroundURI = ""

m.deviceInfo = CreateObject("roDeviceInfo")

m.audioPlayer = m.top.findNode("audioPlayer")
m.nowPlaying = m.top.findNode("nowPlaying")

Expand All @@ -17,10 +19,51 @@ sub init()
m.radioGrid = m.top.findNode("radioGrid")
m.radioGrid.setFocus(true)
m.radioGrid.observeField("selectedRadio", "onSelectedRadioChange")

m.screensaverTimeout = 0
m.screensaverActive = false

m.getScreensaverTimeoutTask = createObject("roSGNode", "GetScreensaverTimeoutTask")
m.getScreensaverTimeoutTask.observeField("responseBody", "onScreensaverTimeoutLoaded")
m.getScreensaverTimeoutTask.control = "RUN"
end sub

sub onScreensaverTimeoutLoaded()
m.getScreensaverTimeoutTask.unobserveField("responseBody")
if not isValid(m.getScreensaverTimeoutTask.responseBody) then return
m.screensaverTimeout = m.getScreensaverTimeoutTask.responseBody
end sub

sub activateScreensaver()
if not m.audioPlayer.disableScreenSaver then return

screenSaver = createObject("roSGNode", "ScreenSaver")
screenSaver.id = "screenSaver"
screenSaver.trackCover = m.audioPlayer.content.FHDPosterUrl
m.top.appendChild(screenSaver)

m.screensaverActive = true
end sub

sub deactivateScreensaver()
screenSaver = m.top.findNode("screenSaver")
if not isValid(screenSaver) then return

m.top.removeChild(screenSaver)

m.screensaverActive = false
end sub

sub onPositionChange()
m.nowPlaying.position = m.audioPlayer.position / m.audioPlayer.duration

if not m.screensaverActive
if m.screensaverTimeout <> 0
if m.deviceInfo.TimeSinceLastKeypress() > m.getScreensaverTimeoutTask.responseBody
activateScreensaver()
end if
end if
end if
end sub

sub onSelectedRadioChange()
Expand Down Expand Up @@ -176,20 +219,16 @@ function loadNextSong() as object
end function

function onKeyEvent(key as string, press as boolean) as boolean
if m.screensaverActive
deactivateScreensaver()
end if

if not press then return false

if LCase(key) = "play"
m.audioPlayer.control = LCase(m.audioPlayer.state) = "paused" ? "resume" : "pause"
return true
end if

if LCase(key) = "up"
screenSaver = createObject("roSGNode", "ScreenSaver")
screenSaver.id = "screenSaver"
screenSaver.trackCover = m.audioPlayer.content.FHDPosterUrl
m.top.appendChild(screenSaver)
return true
end if

return false
end function
8 changes: 8 additions & 0 deletions components/tasks/GetScreensaverTimeoutTask.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sub init()
m.top.functionName = "getScreensaverTimeout"
end sub

sub getScreensaverTimeout()
appinfo = CreateObject("roAppManager")
m.top.responseBody = appinfo.GetScreensaverTimeout() * 60
end sub
7 changes: 7 additions & 0 deletions components/tasks/GetScreensaverTimeoutTask.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<component name="GetScreensaverTimeoutTask" extends="Task">
<interface>
<field id="responseBody" type="integer" value="0" />
</interface>
</component>

0 comments on commit 7cddce1

Please sign in to comment.