“destruk” wrote:
So you can’t just use “END” in the script section of a callback? Does that leave processes running?
Here’s a demo channel (HD). Set your screensaver timeout to one minute and see what happens.
Main() creates MainScene. Main() prints to the console every 3 seconds to show that it’s running. After 100 seconds (long enough for screensaver activation), Main() closes the scene and exits.
Meanwhile, MainScene has a timer that runs every 15 seconds. The timer callback calls END, which does indeed exit the callback. However, it can be seen in the console output that the timer keeps firing every 15 seconds until screensaver activation.
MainScene has a Task that runs continuously printing to the console every 15 seconds.
The key point is that even though Main() exits, the Task and the screensaver keep running. The UI is unresponsive requiring a re-boot.
source/Main.brs
sub Main()
screen = CreateObject("roSGScreen")
scene = screen.createScene("MainScene")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
screen.Show()
ts = CreateObject("roTimespan")
while true
msg = Wait(3000, port)
print "Main() is running"
if ts.TotalSeconds() > 100
print "Closing the screen"
screen.Close()
exit while
end if
if Type(msg) = "roSGScreenEvent"
print "roSGScreenEvent"
if msg.IsScreenClosed()
exit while
end if
end if
end while
print "** Main() terminating ***"
end sub
components/MainScene.xml
<?xml version="1.0" encoding="UTF-8"?>
<component name="MainScene" extends="Scene">
<script type="text/brightscript">
<![CDATA[
sub init()
m.top.findNode("label").font.size = 120
m.timer = m.top.findNode("timer")
m.timer.ObserveField("fire", "onFire")
m.timer.control = "start"
end sub
sub onFire()
print "***** Main Scene timer fired *****"
END
print "***** Should not get here *****"
end sub
]]>
</script>
<children>
<Label
id="label"
width="1280"
height="720"
text="Hello, World!"
font="font:LargeBoldSystemFont"
horizAlign="center"
vertAlign="center" />
<TaskRunning />
<Timer
id="timer"
repeat="true"
duration="15" />
</children>
</component>
components/TaskRunning.xml
<?xml version="1.0" encoding="UTF-8"?>
<component name="TaskRunning" extends="Task">
<script type="text/brightscript">
<![CDATA[
sub init()
m.top.functionName = "taskRun"
m.top.control = "RUN"
end sub
function taskRun() as void
port = CreateObject("roMessagePort")
while true
Wait(5000, port)
print "Task is running"
end while
end function
]]>
</script>
</component>
components/Screensaver.xml
<?xml version="1.0" encoding="UTF-8"?>
<component name="Screensaver" extends="Scene">
<script type="text/brightscript">
<![CDATA[
sub init()
m.top.findNode("seq").control = "start"
end sub
]]>
</script>
<children>
<Group>
<Poster
id="poster"
uri="https://c1.staticflickr.com/9/8505/8418942879_d6f9e365b8_z.jpg"
translation="[370, 120]"
width="500"
height="500" />
<SequentialAnimation
id="seq"
repeat="true">
<Animation
duration="8"
easeFunction="outCubic">
<FloatFieldInterpolator
key="[0,1]"
keyValue="[1,0]"
fieldToInterp="poster.opacity" />
</Animation>
<Animation
duration="8"
easeFunction="inCubic">
<FloatFieldInterpolator
key="[0,1]"
keyValue="[0,1]"
fieldToInterp="poster.opacity" />
</Animation>
</SequentialAnimation>
</Group>
</children>
</component>
source/RunScreenSaver.brs
sub RunScreenSaver()
screen = CreateObject("roSGScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
scene = screen.CreateScene("Screensaver")
screen.Show()
while true
msg = Wait(0, port)
if Type(msg) = "roSGScreenEvent"
if msg.IsScreenClosed()
exit while
end if
end if
end while
end sub