Skip to content

Commit

Permalink
save global refs to prevent deep copies
Browse files Browse the repository at this point in the history
  • Loading branch information
cewert committed Oct 17, 2024
1 parent 3a7882e commit 95b84d0
Show file tree
Hide file tree
Showing 20 changed files with 239 additions and 207 deletions.
10 changes: 5 additions & 5 deletions components/ItemGrid/GridItem.bs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ end sub

sub itemContentChanged()
m.backdrop.blendColor = "#00a4db" ' set default in case global var is invalid
localGlobal = m.global
myGlobal = m.global

if isValid(localGlobal) and isValid(localGlobal.constants) and isValid(localGlobal.constants.poster_bg_pallet)
posterBackgrounds = localGlobal.constants.poster_bg_pallet
if isValid(myGlobal) and isValid(myGlobal.constants) and isValid(myGlobal.constants.poster_bg_pallet)
posterBackgrounds = myGlobal.constants.poster_bg_pallet
m.backdrop.blendColor = posterBackgrounds[rnd(posterBackgrounds.count()) - 1]
end if

Expand All @@ -62,8 +62,8 @@ sub itemContentChanged()
m.itemIcon.uri = itemData.iconUrl
m.itemText.text = itemData.Title
else if itemData.type = "Series"
if isValid(localGlobal) and isValid(localGlobal.session) and isValid(localGlobal.session.user) and isValid(localGlobal.session.user.settings)
if localGlobal.session.user.settings["ui.tvshows.disableUnwatchedEpisodeCount"] = false
if isValid(myGlobal) and isValid(myGlobal.session) and isValid(myGlobal.session.user) and isValid(myGlobal.session.user.settings)
if myGlobal.session.user.settings["ui.tvshows.disableUnwatchedEpisodeCount"] = false
if isValid(itemData.json) and isValid(itemData.json.UserData) and isValid(itemData.json.UserData.UnplayedItemCount)
if itemData.json.UserData.UnplayedItemCount > 0
m.unplayedCount.visible = true
Expand Down
37 changes: 20 additions & 17 deletions components/ItemGrid/ItemGrid.bs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import "pkg:/source/roku_modules/log/LogMixin.brs"
sub init()
m.log = log.Logger("ItemGrid")
m.log.debug("start init()")
userSettings = m.global.session.user.settings

m.options = m.top.findNode("options")

m.showItemCount = m.global.session.user.settings["itemgrid.showItemCount"]
m.showItemCount = userSettings["itemgrid.showItemCount"]

m.tvGuide = invalid
m.channelFocused = invalid
Expand Down Expand Up @@ -68,9 +70,9 @@ sub init()
m.alphaMenu = m.alpha.findNode("alphaMenu")

'Get reset folder setting
m.resetGrid = m.global.session.user.settings["itemgrid.reset"]
m.resetGrid = userSettings["itemgrid.reset"]

m.top.gridTitles = m.global.session.user.settings["itemgrid.gridTitles"]
m.top.gridTitles = userSettings["itemgrid.gridTitles"]
m.log.debug("end init()")
end sub

Expand All @@ -84,6 +86,7 @@ sub loadInitialItems()
m.log.debug("start loadInitialItems()")
m.loadItemsTask.control = "stop"
startLoadingSpinner()
userSettings = m.global.session.user.settings

if m.top.parentItem.json.Type = "CollectionFolder" 'or m.top.parentItem.json.Type = "Folder"
m.top.HomeLibraryItem = m.top.parentItem.Id
Expand All @@ -96,25 +99,25 @@ sub loadInitialItems()
' Read view/sort/filter settings
if m.top.parentItem.collectionType = "livetv"
' Translate between app and server nomenclature
viewSetting = m.global.session.user.settings["display.livetv.landing"]
viewSetting = userSettings["display.livetv.landing"]
if viewSetting = "guide"
m.view = "tvGuide"
else
m.view = "livetv"
end if
m.sortField = m.global.session.user.settings["display.livetv.sortField"]
sortAscendingStr = m.global.session.user.settings["display.livetv.sortAscending"]
m.filter = m.global.session.user.settings["display.livetv.filter"]
m.sortField = userSettings["display.livetv.sortField"]
sortAscendingStr = userSettings["display.livetv.sortAscending"]
m.filter = userSettings["display.livetv.filter"]
else if m.top.parentItem.collectionType = "music"
m.view = m.global.session.user.settings["display.music.view"]
m.sortField = m.global.session.user.settings["display." + m.top.parentItem.Id + ".sortField"]
sortAscendingStr = m.global.session.user.settings["display." + m.top.parentItem.Id + ".sortAscending"]
m.filter = m.global.session.user.settings["display." + m.top.parentItem.Id + ".filter"]
m.view = userSettings["display.music.view"]
m.sortField = userSettings["display." + m.top.parentItem.Id + ".sortField"]
sortAscendingStr = userSettings["display." + m.top.parentItem.Id + ".sortAscending"]
m.filter = userSettings["display." + m.top.parentItem.Id + ".filter"]
else
m.sortField = m.global.session.user.settings["display." + m.top.parentItem.Id + ".sortField"]
sortAscendingStr = m.global.session.user.settings["display." + m.top.parentItem.Id + ".sortAscending"]
m.filter = m.global.session.user.settings["display." + m.top.parentItem.Id + ".filter"]
m.view = m.global.session.user.settings["display." + m.top.parentItem.Id + ".landing"]
m.sortField = userSettings["display." + m.top.parentItem.Id + ".sortField"]
sortAscendingStr = userSettings["display." + m.top.parentItem.Id + ".sortAscending"]
m.filter = userSettings["display." + m.top.parentItem.Id + ".filter"]
m.view = userSettings["display." + m.top.parentItem.Id + ".landing"]
end if

if m.sortField = invalid
Expand Down Expand Up @@ -180,7 +183,7 @@ sub loadInitialItems()
m.loadItemsTask.itemType = "MusicArtist"
m.loadItemsTask.itemId = m.top.parentItem.Id

m.view = m.global.session.user.settings["display.music.view"]
m.view = userSettings["display.music.view"]

if m.view = "music-album"
m.loadItemsTask.itemType = "MusicAlbum"
Expand All @@ -191,7 +194,7 @@ sub loadInitialItems()
' For LiveTV, we want to "Fit" the item images, not zoom
m.top.imageDisplayMode = "scaleToFit"

if m.global.session.user.settings["display.livetv.landing"] = "guide" and m.options.view <> "livetv"
if userSettings["display.livetv.landing"] = "guide" and m.options.view <> "livetv"
showTvGuide()
end if
else if m.top.parentItem.collectionType = "CollectionFolder" or m.top.parentItem.type = "CollectionFolder" or m.top.parentItem.collectionType = "boxsets" or m.top.parentItem.Type = "Boxset" or m.top.parentItem.Type = "Boxsets" or m.top.parentItem.Type = "Folder" or m.top.parentItem.Type = "Channel"
Expand Down
43 changes: 26 additions & 17 deletions components/ItemGrid/LoadVideoContentTask.bs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,31 @@ sub init()
end sub

sub loadItems()
queueManager = m.global.queueManager

' Reset intro tracker in case task gets reused
m.top.isIntro = false

' Only show preroll once per queue
if m.global.queueManager.callFunc("isPrerollActive")
if queueManager.callFunc("isPrerollActive")
' Prerolls not allowed if we're resuming video
if m.global.queueManager.callFunc("getCurrentItem").startingPoint = 0
if queueManager.callFunc("getCurrentItem").startingPoint = 0
preRoll = GetIntroVideos(m.top.itemId)
if isValid(preRoll) and preRoll.TotalRecordCount > 0 and isValid(preRoll.items[0])
' If an error is thrown in the Intros plugin, instead of passing the error they pass the entire rick roll music video.
' Bypass the music video and treat it as an error message
if lcase(preRoll.items[0].name) <> "rick roll'd"
m.global.queueManager.callFunc("push", m.global.queueManager.callFunc("getCurrentItem"))
queueManager.callFunc("push", queueManager.callFunc("getCurrentItem"))
m.top.itemId = preRoll.items[0].id
m.global.queueManager.callFunc("setPrerollStatus", false)
queueManager.callFunc("setPrerollStatus", false)
m.top.isIntro = true
end if
end if
end if
end if

if m.top.selectedAudioStreamIndex = 0
currentItem = m.global.queueManager.callFunc("getCurrentItem")
currentItem = queueManager.callFunc("getCurrentItem")
if isValid(currentItem) and isValid(currentItem.json)
m.top.selectedAudioStreamIndex = FindPreferredAudioStream(currentItem.json.MediaStreams)
end if
Expand Down Expand Up @@ -79,6 +81,10 @@ sub LoadItems_AddVideoContent(video as object, mediaSourceId as dynamic, audio_s
return
end if

queueManager = m.global.queueManager
userSession = m.global.session.user
userSettings = userSession.settings

videotype = LCase(meta.type)

' Check for any Live TV streams or Recordings coming from other places other than the TV Guide
Expand Down Expand Up @@ -119,15 +125,14 @@ sub LoadItems_AddVideoContent(video as object, mediaSourceId as dynamic, audio_s
end if

if LCase(m.top.itemType) = "episode"
userSession = m.global.session.user
if userSession.settings["playback.playnextepisode"] = "enabled" or userSession.settings["playback.playnextepisode"] = "webclient" and userSession.Configuration.EnableNextEpisodeAutoPlay
if userSettings["playback.playnextepisode"] = "enabled" or userSettings["playback.playnextepisode"] = "webclient" and userSession.Configuration.EnableNextEpisodeAutoPlay
addNextEpisodesToQueue(video.showID)
end if
end if

playbackPosition = 0!

currentItem = m.global.queueManager.callFunc("getCurrentItem")
currentItem = queueManager.callFunc("getCurrentItem")

if isValid(currentItem) and isValid(currentItem.startingPoint)
playbackPosition = currentItem.startingPoint
Expand Down Expand Up @@ -209,8 +214,8 @@ sub LoadItems_AddVideoContent(video as object, mediaSourceId as dynamic, audio_s
' transcode is that the Encoding Level is not supported, then try to direct play but silently
' fall back to the transcode if that fails.
if m.playbackInfo.MediaSources[0].MediaStreams.Count() > 0 and meta.live = false
tryDirectPlay = m.global.session.user.settings["playback.tryDirect.h264ProfileLevel"] and m.playbackInfo.MediaSources[0].MediaStreams[0].codec = "h264"
tryDirectPlay = tryDirectPlay or (m.global.session.user.settings["playback.tryDirect.hevcProfileLevel"] and m.playbackInfo.MediaSources[0].MediaStreams[0].codec = "hevc")
tryDirectPlay = userSettings["playback.tryDirect.h264ProfileLevel"] and m.playbackInfo.MediaSources[0].MediaStreams[0].codec = "h264"
tryDirectPlay = tryDirectPlay or (userSettings["playback.tryDirect.hevcProfileLevel"] and m.playbackInfo.MediaSources[0].MediaStreams[0].codec = "hevc")
if tryDirectPlay and isValid(m.playbackInfo.MediaSources[0].TranscodingUrl) and forceTranscoding = false
transcodingReasons = getTranscodeReasons(m.playbackInfo.MediaSources[0].TranscodingUrl)
if transcodingReasons.Count() = 1 and transcodingReasons[0] = "VideoLevelNotSupported"
Expand Down Expand Up @@ -250,7 +255,8 @@ end sub
' @param {dynamic} videoID - id of video user is playing
' @return {integer} indicating the default track's server-side index. Defaults to {SubtitleSelection.none} is one is not found
function defaultSubtitleTrackFromVid(videoID) as integer
if m.global.session.user.configuration.SubtitleMode = "None"
userSession = m.global.session.user
if userSession.configuration.SubtitleMode = "None"
return SubtitleSelection.none ' No subtitles desired: return none
end if

Expand All @@ -276,7 +282,7 @@ function defaultSubtitleTrackFromVid(videoID) as integer
return defaultTextSubs
end if

if not m.global.session.user.settings["playback.subs.onlytext"]
if not userSession.settings["playback.subs.onlytext"]
return defaultSubtitleTrack(subtitles["all"], selectedAudioLanguage) ' if no appropriate text subs exist, allow non-text
end if

Expand Down Expand Up @@ -476,20 +482,22 @@ end function

' Add next episodes to the playback queue
sub addNextEpisodesToQueue(showID)
queueManager = m.global.queueManager

' Don't queue next episodes if we already have a playback queue
maxQueueCount = 1

if m.top.isIntro
maxQueueCount = 2
end if

if m.global.queueManager.callFunc("getCount") > maxQueueCount then return
if queueManager.callFunc("getCount") > maxQueueCount then return

videoID = m.top.itemId

' If first item is an intro video, use the next item in the queue
if m.top.isIntro
currentVideo = m.global.queueManager.callFunc("getItemByIndex", 1)
currentVideo = queueManager.callFunc("getItemByIndex", 1)

if isValid(currentVideo) and isValid(currentVideo.id)
videoID = currentVideo.id
Expand All @@ -511,7 +519,7 @@ sub addNextEpisodesToQueue(showID)

if isValid(data) and data.Items.Count() > 1
for i = 1 to data.Items.Count() - 1
m.global.queueManager.callFunc("push", data.Items[i])
queueManager.callFunc("push", data.Items[i])
end for
end if
end sub
Expand Down Expand Up @@ -570,8 +578,9 @@ function sortSubtitles(id as string, MediaStreams)
end function

function FindPreferredAudioStream(streams as dynamic) as integer
preferredLanguage = m.global.session.user.Configuration.AudioLanguagePreference
playDefault = m.global.session.user.Configuration.PlayDefaultAudioTrack
userConfig = m.global.session.user.configuration
preferredLanguage = userConfig.AudioLanguagePreference
playDefault = userConfig.PlayDefaultAudioTrack

if playDefault <> invalid and playDefault = true
return 1
Expand Down
20 changes: 11 additions & 9 deletions components/ItemGrid/MovieLibraryView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ end sub

sub init()
setupNodes()
userSettings = m.global.session.user.settings

m.overhang.isVisible = false

Expand All @@ -39,7 +40,7 @@ sub init()
alphaMicText = m.alpha.findNode("alphaMicText")
alphaMicText.visible = false

m.showItemCount = m.global.session.user.settings["itemgrid.showItemCount"]
m.showItemCount = userSettings["itemgrid.showItemCount"]

m.swapAnimation.observeField("state", "swapDone")

Expand Down Expand Up @@ -86,7 +87,7 @@ sub init()
m.loadItemsTask.totalRecordCount = 0

'Get reset folder setting
m.resetGrid = m.global.session.user.settings["itemgrid.reset"]
m.resetGrid = userSettings["itemgrid.reset"]
end sub

sub OnScreenHidden()
Expand All @@ -112,6 +113,7 @@ end sub
sub loadInitialItems()
m.loadItemsTask.control = "stop"
startLoadingSpinner(false)
userSettings = m.global.session.user.settings

if m.top.parentItem.json.Type = "CollectionFolder"
m.top.HomeLibraryItem = m.top.parentItem.Id
Expand All @@ -123,15 +125,15 @@ sub loadInitialItems()
SetBackground("")
end if

m.sortField = m.global.session.user.settings["display." + m.top.parentItem.Id + ".sortField"]
m.filter = m.global.session.user.settings["display." + m.top.parentItem.Id + ".filter"]
m.filterOptions = m.global.session.user.settings["display." + m.top.parentItem.Id + ".filterOptions"]
m.view = m.global.session.user.settings["display." + m.top.parentItem.Id + ".landing"]
m.sortAscending = m.global.session.user.settings["display." + m.top.parentItem.Id + ".sortAscending"]
m.sortField = userSettings["display." + m.top.parentItem.Id + ".sortField"]
m.filter = userSettings["display." + m.top.parentItem.Id + ".filter"]
m.filterOptions = userSettings["display." + m.top.parentItem.Id + ".filterOptions"]
m.view = userSettings["display." + m.top.parentItem.Id + ".landing"]
m.sortAscending = userSettings["display." + m.top.parentItem.Id + ".sortAscending"]

' If user has not set a preferred view for this folder, check if they've set a default view
if not isValid(m.view)
m.view = m.global.session.user.settings["itemgrid.movieDefaultView"]
m.view = userSettings["itemgrid.movieDefaultView"]
end if

if not isValid(m.sortField) then m.sortField = "SortName"
Expand Down Expand Up @@ -200,7 +202,7 @@ sub loadInitialItems()
m.itemGrid.numRows = "3"
m.selectedMovieOverview.visible = false
m.infoGroup.visible = false
m.top.showItemTitles = m.global.session.user.settings["itemgrid.gridTitles"]
m.top.showItemTitles = userSettings["itemgrid.gridTitles"]
if LCase(m.top.showItemTitles) = "hidealways"
m.itemGrid.itemSize = "[230, 315]"
m.itemGrid.rowHeights = "[315]"
Expand Down
16 changes: 9 additions & 7 deletions components/ItemGrid/MusicLibraryView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ end sub

sub init()
setupNodes()
userSettings = m.global.session.user.settings

m.overhang.isVisible = false

Expand All @@ -34,7 +35,7 @@ sub init()
alphaMicText = m.alpha.findNode("alphaMicText")
alphaMicText.visible = false

m.showItemCount = m.global.session.user.settings["itemgrid.showItemCount"]
m.showItemCount = userSettings["itemgrid.showItemCount"]

m.swapAnimation.observeField("state", "swapDone")

Expand Down Expand Up @@ -80,7 +81,7 @@ sub init()
m.loadItemsTask.totalRecordCount = 0

'Get reset folder setting
m.resetGrid = m.global.session.user.settings["itemgrid.reset"]
m.resetGrid = userSettings["itemgrid.reset"]
end sub

sub OnScreenHidden()
Expand All @@ -106,6 +107,7 @@ end sub
sub loadInitialItems()
m.loadItemsTask.control = "stop"
startLoadingSpinner(false)
userSettings = m.global.session.user.settings

if LCase(m.top.parentItem.json.Type) = "collectionfolder"
m.top.HomeLibraryItem = m.top.parentItem.Id
Expand All @@ -117,17 +119,17 @@ sub loadInitialItems()
SetBackground("")
end if

m.sortField = m.global.session.user.settings["display." + m.top.parentItem.Id + ".sortField"]
m.sortAscending = m.global.session.user.settings["display." + m.top.parentItem.Id + ".sortAscending"]
m.filter = m.global.session.user.settings["display." + m.top.parentItem.Id + ".filter"]
m.view = m.global.session.user.settings["display." + m.top.parentItem.Id + ".landing"]
m.sortField = userSettings["display." + m.top.parentItem.Id + ".sortField"]
m.sortAscending = userSettings["display." + m.top.parentItem.Id + ".sortAscending"]
m.filter = userSettings["display." + m.top.parentItem.Id + ".filter"]
m.view = userSettings["display." + m.top.parentItem.Id + ".landing"]

if not isValid(m.sortField) then m.sortField = "SortName"
if not isValid(m.filter) then m.filter = "All"
if not isValid(m.view) then m.view = "ArtistsPresentation"
if not isValid(m.sortAscending) then m.sortAscending = true

m.top.showItemTitles = m.global.session.user.settings["itemgrid.gridTitles"]
m.top.showItemTitles = userSettings["itemgrid.gridTitles"]

if LCase(m.top.parentItem.json.type) = "musicgenre"
m.itemGrid.translation = "[96, 60]"
Expand Down
5 changes: 3 additions & 2 deletions components/JFVideo.bs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ sub init()
m.top.transcodeReasons = []
m.bufferCheckTimer.duration = 30

if m.global.session.user.settings["ui.design.hideclock"] = true
userSettings = m.global.session.user.settings
if userSettings["ui.design.hideclock"]
clockNode = findNodeBySubtype(m.top, "clock")
if clockNode[0] <> invalid then clockNode[0].parent.removeChild(clockNode[0].node)
end if
Expand All @@ -22,7 +23,7 @@ sub init()
m.nextEpisodeButton = m.top.findNode("nextEpisode")
m.nextEpisodeButton.text = tr("Next Episode")
m.nextEpisodeButton.setFocus(false)
m.nextupbuttonseconds = m.global.session.user.settings["playback.nextupbuttonseconds"].ToInt()
m.nextupbuttonseconds = userSettings["playback.nextupbuttonseconds"].ToInt()

m.showNextEpisodeButtonAnimation = m.top.findNode("showNextEpisodeButton")
m.hideNextEpisodeButtonAnimation = m.top.findNode("hideNextEpisodeButton")
Expand Down
Loading

0 comments on commit 95b84d0

Please sign in to comment.