Skip to content

Commit

Permalink
Fix loss of focus bug when closing options popup on Live TV show details
Browse files Browse the repository at this point in the history
  • Loading branch information
1hitsong committed Nov 29, 2024
1 parent 51513d9 commit 6d5bdbe
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 83 deletions.
3 changes: 0 additions & 3 deletions components/ItemGrid/ItemGridOptions.bs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ sub init()
m.buttons = m.top.findNode("buttons")
m.buttons.buttons = [tr("View"), tr("Sort"), tr("Filter")]
m.buttons.selectedIndex = MenuType.SORT
m.buttons.setFocus(true)
group = m.global.sceneManager.callFunc("getActiveScene")
group.lastFocus = m.buttons

m.favoriteMenu = m.top.findNode("favoriteMenu")
m.selectedFavoriteItem = m.top.findNode("selectedFavoriteItem")
Expand Down
18 changes: 11 additions & 7 deletions components/liveTv/LiveTVLibraryView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,11 @@ sub ItemDataLoaded(msg)
group = m.global.sceneManager.callFunc("getActiveScene")
group.lastFocus = m.alphaMenu
else
m.alphaMenu.setFocus(false)
m.itemGrid.setFocus(true)
group = m.global.sceneManager.callFunc("getActiveScene")
group.lastFocus = m.itemGrid
if not isStringEqual(m.global.session.user.settings["display.livetv.landing"], "guide") or isStringEqual(m.options.view, "livetv")
m.itemGrid.setFocus(true)
group = m.global.sceneManager.callFunc("getActiveScene")
group.lastFocus = m.itemGrid
end if
end if

'Update the stored counts
Expand Down Expand Up @@ -442,11 +443,14 @@ sub optionsClosed()
group = m.global.sceneManager.callFunc("getActiveScene")
group.lastFocus = m.itemGrid.opacity = 1 ? m.itemGrid : m.tvGuide

if m.tvGuide <> invalid
if isValid(m.tvGuide)
m.tvGuide.lastFocus.setFocus(true)
group.lastFocus = m.tvGuide
end if
group.lastFocus = m.tvGuide.lastFocus

if isChainValid(m.tvGuide, "lastFocus.hasFocus")
m.tvGuide.lastFocus.hasFocus = m.tvGuide.lastFocus.hasFocus
end if
end if
end sub

sub showTVGuide()
Expand Down
10 changes: 5 additions & 5 deletions components/liveTv/ProgramDetails.bs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ sub focusChanged()
m.viewChannelOutline.visible = true
m.recordOutline.visible = false
m.recordSeriesOutline.visible = false
m.viewChannelButtonBackground.blendColor = "#006fab"
m.viewChannelButtonBackground.blendColor = ColorPalette.HIGHLIGHT
m.recordButtonBackground.blendColor = "#000000"
m.recordSeriesButtonBackground.blendColor = "#000000"
else
Expand Down Expand Up @@ -343,7 +343,7 @@ function onKeyEvent(key as string, press as boolean) as boolean
m.viewChannelOutline.visible = false
m.recordOutline.visible = true
m.viewChannelButtonBackground.blendColor = "#000000"
m.recordButtonBackground.blendColor = "#006fab"
m.recordButtonBackground.blendColor = ColorPalette.HIGHLIGHT
m.recordSeriesButtonBackground.blendColor = "#000000"
return true
else if key = "right" and m.recordButton.hasFocus()
Expand All @@ -354,7 +354,7 @@ function onKeyEvent(key as string, press as boolean) as boolean
m.recordSeriesOutline.visible = true
m.viewChannelButtonBackground.blendColor = "#000000"
m.recordButtonBackground.blendColor = "#000000"
m.recordSeriesButtonBackground.blendColor = "#006fab"
m.recordSeriesButtonBackground.blendColor = ColorPalette.HIGHLIGHT
return true
else if key = "left" and m.recordSeriesButton.hasFocus()
m.recordButton.setFocus(true)
Expand All @@ -363,7 +363,7 @@ function onKeyEvent(key as string, press as boolean) as boolean
m.recordOutline.visible = true
m.recordSeriesOutline.visible = false
m.viewChannelButtonBackground.blendColor = "#000000"
m.recordButtonBackground.blendColor = "#006fab"
m.recordButtonBackground.blendColor = ColorPalette.HIGHLIGHT
m.recordSeriesButtonBackground.blendColor = "#000000"
return true
else if key = "left" and m.recordButton.hasFocus()
Expand All @@ -372,7 +372,7 @@ function onKeyEvent(key as string, press as boolean) as boolean
group.lastFocus = m.viewChannelButton
m.viewChannelOutline.visible = true
m.recordOutline.visible = false
m.viewChannelButtonBackground.blendColor = "#006fab"
m.viewChannelButtonBackground.blendColor = ColorPalette.HIGHLIGHT
m.recordButtonBackground.blendColor = "#000000"
m.recordSeriesButtonBackground.blendColor = "#000000"
return true
Expand Down
2 changes: 1 addition & 1 deletion components/liveTv/ProgramDetails.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@
<field id="favorite" type="node" onchange="channelUpdated" />
<field id="programDetails" type="node" onchange="programUpdated" />
<field id="height" type="integer" />
<field id="hasFocus" type="boolean" onChange="focusChanged" />
<field id="hasFocus" type="boolean" onChange="focusChanged" alwaysNotify="true" />
</interface>
</component>
31 changes: 22 additions & 9 deletions components/liveTv/schedule.bs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import "pkg:/source/enums/ColorPalette.bs"
import "pkg:/source/enums/TaskControl.bs"
import "pkg:/source/utils/misc.bs"

sub init()
m.state = TaskControl.RUN
m.loadedChannelCount = 0
m.channelFirstLoadLimit = 20
m.channelLaterLoadLimit = 100
Expand Down Expand Up @@ -35,6 +37,15 @@ sub init()

m.LoadChannelsTask = createObject("roSGNode", "LoadChannelsTask")
m.LoadChannelsTask.observeField("channels", "onChannelsLoaded")

m.LoadScheduleTask = createObject("roSGNode", "LoadScheduleTask")
m.LoadScheduleTask.observeField("schedule", "onScheduleLoaded")
m.LoadScheduleTask.startTime = m.gridStartDate.ToISOString()
m.LoadScheduleTask.endTime = m.gridEndDate.ToISOString()

m.LoadProgramDetailsTask = createObject("roSGNode", "LoadProgramDetailsTask")
m.LoadProgramDetailsTask.observeField("programDetails", "onProgramDetailsLoaded")

loadChannels(m.channelFirstLoadLimit)

m.top.lastFocus = m.scheduleGrid
Expand All @@ -43,6 +54,8 @@ sub init()
end sub

sub loadChannels(limit as integer)
if not isStringEqual(m.state, TaskControl.RUN) then return

m.LoadChannelsTask.limit = limit
m.LoadChannelsTask.startIndex = m.loadedChannelCount
m.LoadChannelsTask.control = "RUN"
Expand Down Expand Up @@ -96,17 +109,9 @@ sub onChannelsLoaded()
channelIdList = channelIdList + item.Id + ","
end for

m.LoadScheduleTask = createObject("roSGNode", "LoadScheduleTask")
m.LoadScheduleTask.observeField("schedule", "onScheduleLoaded")

m.LoadScheduleTask.startTime = m.gridStartDate.ToISOString()
m.LoadScheduleTask.endTime = m.gridEndDate.ToISOString()
m.LoadScheduleTask.channelIds = channelIdList
m.LoadScheduleTask.control = "RUN"

m.LoadProgramDetailsTask = createObject("roSGNode", "LoadProgramDetailsTask")
m.LoadProgramDetailsTask.observeField("programDetails", "onProgramDetailsLoaded")

if m.EPGLaunchCompleteSignaled = false
m.top.signalBeacon("EPGLaunchComplete") ' Required Roku Performance monitoring
m.EPGLaunchCompleteSignaled = true
Expand Down Expand Up @@ -331,7 +336,15 @@ function onKeyEvent(key as string, press as boolean) as boolean
group.lastFocus = gridGrp
return true
else if key = "back"
m.LoadChannelsTask.control = "stop"
m.state = TaskControl.STOP

m.LoadChannelsTask.control = TaskControl.STOP
m.LoadScheduleTask.control = TaskControl.STOP

m.LoadChannelsTask.channels = []
m.LoadScheduleTask.schedule = []
m.channelIndex = {}

m.global.sceneManager.callFunc("popScene")
return true
end if
Expand Down
117 changes: 59 additions & 58 deletions source/Main.bs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,19 @@ import "pkg:/source/enums/String.bs"
sub Main (args as dynamic) as void
' The main function that runs when the application is launched.
m.screen = CreateObject("roSGScreen")
m.port = CreateObject("roMessagePort")
m.screen.setMessagePort(m.port)

' Set global constants
setConstants()

' Write screen tracker for screensaver
WriteAsciiFile("tmp:/scene.temp", "")
MoveFile("tmp:/scene.temp", "tmp:/scene")

m.port = CreateObject("roMessagePort")
m.screen.setMessagePort(m.port)

' Set any initial Global Variables
m.global = m.screen.getGlobalNode()
SaveAppToGlobal()
SaveDeviceToGlobal()

session.Init()

' update global LastRunVersion now that migrations are finished
if m.global.app.version <> m.global.app.lastRunVersion
set_setting("LastRunVersion", m.global.app.version)
end if

m.scene = m.screen.CreateScene("BaseScene")
m.screen.show() ' vscode_rale_tracker_entry
'vscode_rdb_on_device_component_entry
Expand Down Expand Up @@ -70,52 +60,14 @@ sub Main (args as dynamic) as void

m.scene.observeField("exit", m.port)

' Downloads and stores a fallback font to tmp:/
configEncoding = api.system.GetConfigurationByName("encoding")

if isChainValid(configEncoding, "EnableFallbackFont")
if configEncoding.EnableFallbackFont
re = CreateObject("roRegex", "Name.:.(.*?).,.Size", "s")
filename = APIRequest("FallbackFont/Fonts").GetToString()
if isValid(filename)
filename = re.match(filename)
if isValidAndNotEmpty(filename)
filename = filename[1]
APIRequest("FallbackFont/Fonts/" + filename).gettofile("tmp:/font")
end if
end if
end if
end if
' Download and store the fallback font to tmp:/
' This font may be used for CJK subtitles
downloadFallbackFont()

' Delete any old library filters
for each settingKeys in m.global.session.user.settings.keys()
if isStringEqual(left(settingKeys, 8), "display.")
if isStringEqual(right(settingKeys, 7), ".filter") or isStringEqual(right(settingKeys, 14), ".filterOptions")
m.global.session.user.settings.delete(settingKeys)
unset_user_setting(settingKeys)
end if
end if
end for
clearOldLibraryFilters()

' Bypass What's New popup if server is Jellyfin demo
if isStringEqual(m.global.session.server.url, "https://demo.jellyfin.org/stable")
set_user_setting("LastRunVersion", m.global.app.version)
end if

' Bypass What's New popup if deep linking arguments were passed
if isValidAndNotEmpty(args.mediaType) and isValidAndNotEmpty(args.contentId)
set_user_setting("LastRunVersion", m.global.app.version)
end if

' Has the current user run this version before?
usersLastRunVersion = m.global.session.user.settings.lastRunVersion
if ChannelVersionUpdated(usersLastRunVersion)
set_user_setting("LastRunVersion", m.global.app.version)
' show what's new popup
if m.global.session.user.settings["load.allowwhatsnew"]
m.global.sceneManager.callFunc("whatsNewDialog")
end if
end if
displayWhatsNewPopup(args)

' Handle input messages
input = CreateObject("roInput")
Expand All @@ -124,11 +76,9 @@ sub Main (args as dynamic) as void
device = CreateObject("roDeviceInfo")
device.setMessagePort(m.port)
device.EnableScreensaverExitedEvent(true)
device.EnableAppFocusEvent(true)
device.EnableAudioGuideChangedEvent(true)
device.EnableLowGeneralMemoryEvent(true)
device.EnableLinkStatusEvent(true)
device.EnableCodecCapChangedEvent(true)
device.EnableAudioGuideChangedEvent(true)

' Check if we were sent content to play with the startup command (Deep Link)
onDeepLinkingEvent(args)
Expand Down Expand Up @@ -255,3 +205,54 @@ sub Main (args as dynamic) as void
end if
end while
end sub

sub downloadFallbackFont()
configEncoding = api.system.GetConfigurationByName("encoding")

if isChainValid(configEncoding, "EnableFallbackFont")
if configEncoding.EnableFallbackFont
re = CreateObject("roRegex", "Name.:.(.*?).,.Size", "s")
filename = APIRequest("FallbackFont/Fonts").GetToString()
if isValid(filename)
filename = re.match(filename)
if isValidAndNotEmpty(filename)
filename = filename[1]
APIRequest("FallbackFont/Fonts/" + filename).gettofile("tmp:/font")
end if
end if
end if
end if
end sub

sub clearOldLibraryFilters()
for each settingKeys in m.global.session.user.settings.keys()
if isStringEqual(left(settingKeys, 8), "display.")
if isStringEqual(right(settingKeys, 7), ".filter") or isStringEqual(right(settingKeys, 14), ".filterOptions")
m.global.session.user.settings.delete(settingKeys)
unset_user_setting(settingKeys)
end if
end if
end for
end sub

sub displayWhatsNewPopup(args)
' Bypass What's New popup if server is Jellyfin demo
if isStringEqual(m.global.session.server.url, "https://demo.jellyfin.org/stable")
set_user_setting("LastRunVersion", m.global.app.version)
end if

' Bypass What's New popup if deep linking arguments were passed
if isValidAndNotEmpty(args.mediaType) and isValidAndNotEmpty(args.contentId)
set_user_setting("LastRunVersion", m.global.app.version)
end if

' Has the current user run this version before?
usersLastRunVersion = m.global.session.user.settings.lastRunVersion
if ChannelVersionUpdated(usersLastRunVersion)
set_user_setting("LastRunVersion", m.global.app.version)
' show what's new popup
if m.global.session.user.settings["load.allowwhatsnew"]
m.global.sceneManager.callFunc("whatsNewDialog")
end if
end if
end sub
4 changes: 4 additions & 0 deletions source/static/whatsNew/1.1.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"description": "Fix TV episode watched button text not changing when clicked",
"author": "1hitsong"
},
{
"description": "Fix loss of focus bug when closing options popup from Live TV show details",
"author": "1hitsong"
},
{
"description": "Update item API calls",
"author": "jimdogx"
Expand Down

0 comments on commit 6d5bdbe

Please sign in to comment.