Skip to content

Commit

Permalink
Address reviewer feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cewert committed Nov 1, 2023
1 parent a08a9cb commit ab3fd49
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion components/data/SceneManager.brs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ end function
sub clearScenes()
if m.content <> invalid then m.content.removeChildrenIndex(m.content.getChildCount(), 0)
for each group in m.groups
if group.subtype() = "JFScreen"
if LCase(group.subtype()) = "jfscreen"
group.callFunc("OnScreenHidden")
end if
end for
Expand Down
6 changes: 5 additions & 1 deletion components/home/Home.brs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ sub loadLibraries()
m.top.findNode("homeRows").callFunc("loadLibraries")
end sub

' JFScreen hook that gets ran as needed.
' Used to update the foces, the state of the data, and tells the server about the device profile
sub OnScreenShown()
if m.top.lastFocus <> invalid
if isValid(m.top.lastFocus)
m.top.lastFocus.setFocus(true)
else
m.top.setFocus(true)
Expand All @@ -42,6 +44,8 @@ sub OnScreenShown()
end if
end sub

' Triggered by m.postTask after completing a post.
' Empty the task data when finished.
sub postFinished()
m.postTask.unobserveField("responseCode")
m.postTask.callFunc("empty")
Expand Down
7 changes: 5 additions & 2 deletions components/settings/settings.brs
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,18 @@ sub radioSettingChanged()
set_user_setting(selectedSetting.settingName, m.radioSetting.content.getChild(m.radioSetting.checkedItem).id)
end sub

' JFScreen hook that gets ran as needed.
' Assumes settings were changed and they affect the device profile.
' Posts a new device profile to the server using the task thread
sub OnScreenHidden()
' some settings affect the device profile.
' assume there were changes and always post device profile when leaving the settings screen
m.postTask.arrayData = getDeviceCapabilities()
m.postTask.apiUrl = "/Sessions/Capabilities/Full"
m.postTask.control = "RUN"
m.postTask.observeField("responseCode", "postFinished")
end sub

' Triggered by m.postTask after completing a post.
' Empty the task data when finished.
sub postFinished()
m.postTask.unobserveField("responseCode")
m.postTask.callFunc("empty")
Expand Down
45 changes: 25 additions & 20 deletions components/tasks/PostTask.bs
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
import "pkg:/source/api/baserequest.brs"
import "pkg:/source/utils/misc.brs"

sub init()
m.top.functionName = "postItems"
end sub

' Main function for PostTask.
' Posts either an array of data
' or a string of data to an API endpoint.
' Saves the response information
sub postItems()
if m.top.apiUrl <> ""
if m.top.arrayData.count() > 0 and m.top.stringData = ""
print "PostTask Started - Posting array to " + m.top.apiUrl
req = APIRequest(m.top.apiUrl)
req.SetRequest("POST")
httpResponse = asyncPost(req, FormatJson(m.top.arrayData))
m.top.responseCode = httpResponse
print "PostTask Finished. " + m.top.apiUrl + " Response = " + httpResponse.toStr()
else if m.top.arrayData.count() = 0 and m.top.stringData <> ""
print "PostTask Started - Posting string(" + m.top.stringData + ") to " + m.top.apiUrl
req = APIRequest(m.top.apiUrl)
req.SetRequest("POST")
httpResponse = asyncPost(req, m.top.stringData)
m.top.responseCode = httpResponse
print "PostTask Finished. " + m.top.apiUrl + " Response = " + httpResponse.toStr()
else
print "ERROR processing data for PostTask"
end if
else
if m.top.apiUrl = ""
print "ERROR in PostTask. Invalid API URL provided"
return
end if
if m.top.arrayData.count() > 0 and m.top.stringData = ""
print "PostTask Started - Posting array to " + m.top.apiUrl
req = APIRequest(m.top.apiUrl)
req.SetRequest("POST")
httpResponse = asyncPost(req, FormatJson(m.top.arrayData))
m.top.responseCode = httpResponse
print "PostTask Finished. " + m.top.apiUrl + " Response = " + httpResponse.toStr()
else if m.top.arrayData.count() = 0 and m.top.stringData <> ""
print "PostTask Started - Posting string(" + m.top.stringData + ") to " + m.top.apiUrl
req = APIRequest(m.top.apiUrl)
req.SetRequest("POST")
httpResponse = asyncPost(req, m.top.stringData)
m.top.responseCode = httpResponse
print "PostTask Finished. " + m.top.apiUrl + " Response = " + httpResponse.toStr()
else
print "ERROR processing data for PostTask"
end if
end sub

Expand All @@ -41,7 +46,7 @@ function asyncPost(req, data = "" as string) as integer
resp = wait(m.top.timeoutSeconds * 1000, req.GetMessagePort())

respString = resp.GetString()
if respString <> invalid and respString <> ""
if isValidAndNotEmpty(respString)
m.top.responseBody = ParseJson(respString)
print "m.top.responseBody=", m.top.responseBody
end if
Expand Down

0 comments on commit ab3fd49

Please sign in to comment.