Remove asynctask code (#666)
* Remove asynctask code * add job test example * Fix testing * Fix a couple of imports
This commit is contained in:
1 parent
9ef741292e
commit
82dea9af37
36 files changed
+325
-443
No files matched your search
+14
-15
@@ -2,8 +2,10 @@ import "pkg:/components/Services/Innertube/InnertubeService.bs"
|
||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
||||
|
||||
@asynctask
|
||||
function VideoContentTaskDev(input as object) as object
|
||||
@job("VideoContentDevJob")
|
||||
function ExecuteJob() as void
|
||||
input = JobGetInput()
|
||||
|
||||
titleLabel = input.titleLabel
|
||||
secondaryTitleLabel = input.secondaryTitleLabel
|
||||
backgroundPoster = input.backgroundPoster
|
||||
@@ -17,7 +19,8 @@ function VideoContentTaskDev(input as object) as object
|
||||
videoId = contentNode.videoId
|
||||
|
||||
if StringUtils.IsNullOrEmpty(videoId)
|
||||
throw "Can't load video information: videoId is missing"
|
||||
JobError("Can't load video information: videoId is missing")
|
||||
return
|
||||
end if
|
||||
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
@@ -25,22 +28,22 @@ function VideoContentTaskDev(input as object) as object
|
||||
|
||||
backgroundPoster.uri = `${instance}/vi/${videoId}/maxresdefault.jpg`
|
||||
|
||||
cancellation = CancellationUtils.CreateCancellation(JobGetCallbackNode(), "cancel", true)
|
||||
backend = preferencesNode["backend.selected"]
|
||||
if backend = "playlet"
|
||||
metadata = InnertubeService.GetVideoMetadata(videoId, { cancellation: m.top.cancellation })
|
||||
metadata = InnertubeService.GetVideoMetadata(videoId, { cancellation: cancellation })
|
||||
else
|
||||
metadata = service.GetVideoMetadata(videoId, { cancellation: m.top.cancellation })
|
||||
metadata = service.GetVideoMetadata(videoId, { cancellation: cancellation })
|
||||
end if
|
||||
|
||||
if m.top.cancel
|
||||
return invalid
|
||||
if JobIsCancelled()
|
||||
JobCancel()
|
||||
return
|
||||
end if
|
||||
|
||||
if metadata.error <> invalid
|
||||
return {
|
||||
success: false
|
||||
error: metadata.error
|
||||
}
|
||||
JobError(metadata.error)
|
||||
return
|
||||
end if
|
||||
|
||||
contentNode.title = metadata.title
|
||||
@@ -69,10 +72,6 @@ function VideoContentTaskDev(input as object) as object
|
||||
playletStreamUrls: streamUrls
|
||||
playletStreamUrlIndex: 0
|
||||
})
|
||||
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
end function
|
||||
|
||||
function CreateStreamUrls(metadata as object) as object
|
||||
@@ -1,10 +1,10 @@
|
||||
import "pkg:/components/JobSystem/Jobs.bs"
|
||||
import "pkg:/components/JobSystem/JobSystem.bs"
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
import "pkg:/components/Services/Innertube/Constants.bs"
|
||||
import "pkg:/components/VideoPlayerDev/PictureInPicture.bs"
|
||||
import "pkg:/components/VideoPlayerDev/PlayerUi.bs"
|
||||
import "pkg:/components/VideoQueue/VideoQueueUtils.bs"
|
||||
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
||||
import "pkg:/source/AsyncTask/Tasks.bs"
|
||||
import "pkg:/source/utils/DisposableObserve.bs"
|
||||
import "pkg:/source/utils/ErrorUtils.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
@@ -76,12 +76,12 @@ function PlayWithContent(contentNode as object)
|
||||
m.backgroundPosterSmall.uri = thumbnail
|
||||
end if
|
||||
|
||||
StartVideoContentTask(videoContentNode)
|
||||
StartVideoContentDevJob(videoContentNode)
|
||||
end function
|
||||
|
||||
function StartVideoContentTask(videoContentNode as object)
|
||||
if m.videoContentTask <> invalid
|
||||
m.videoContentTask.cancel = true
|
||||
function StartVideoContentDevJob(videoContentNode as object)
|
||||
if m.videoContentDevJob <> invalid
|
||||
m.videoContentDevJob.cancel = true
|
||||
end if
|
||||
|
||||
m.top.content = videoContentNode
|
||||
@@ -91,31 +91,29 @@ function StartVideoContentTask(videoContentNode as object)
|
||||
m.loadingUi.visible = true
|
||||
m.loadingSpinner.control = "start"
|
||||
|
||||
m.videoContentTask = AsyncTask.Start(Tasks.VideoContentTaskDev, {
|
||||
input = {
|
||||
titleLabel: m.titleLabel
|
||||
secondaryTitleLabel: m.secondaryTitleLabel
|
||||
content: videoContentNode
|
||||
invidious: m.top.invidious
|
||||
preferences: m.top.preferences
|
||||
backgroundPoster: m.backgroundPoster
|
||||
}, OnVideoContentTaskResults)
|
||||
}
|
||||
|
||||
m.videoContentDevJob = JobSystem.CreateCallback(OnVideoContentDevJobDone)
|
||||
JobSystem.QueueJob(m.jobQueue, Jobs.VideoContentDevJob, input, m.videoContentDevJob)
|
||||
end function
|
||||
|
||||
function OnVideoContentTaskResults(output as object) as void
|
||||
m.videoContentTask = invalid
|
||||
if output.cancelled
|
||||
function OnVideoContentDevJobDone(event as object) as void
|
||||
JobSystem.UnobserveCallback(event.getRoSGNode())
|
||||
m.videoContentDevJob = invalid
|
||||
|
||||
info = event.getInfo()
|
||||
if info.cancel
|
||||
return
|
||||
end if
|
||||
|
||||
if not output.success or not output.result.success
|
||||
' output.error for unhandled exception
|
||||
error = output.error
|
||||
if error = invalid
|
||||
' output.result.error for network errors
|
||||
error = output.result.error
|
||||
end if
|
||||
error = ErrorUtils.Format(error)
|
||||
LogError(error)
|
||||
if not info.success
|
||||
m.top.close = true
|
||||
return
|
||||
end if
|
||||
@@ -126,9 +124,9 @@ end function
|
||||
function OnClose()
|
||||
m.top.previousPlayer = invalid
|
||||
|
||||
if m.videoContentTask <> invalid
|
||||
m.videoContentTask.cancel = true
|
||||
m.videoContentTask = invalid
|
||||
if m.videoContentDevJob <> invalid
|
||||
m.videoContentDevJob.cancel = true
|
||||
m.videoContentDevJob = invalid
|
||||
end if
|
||||
|
||||
parent = m.top.getParent()
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
-->
|
||||
<component name="VideoPlayerDev" extends="Video" includes="AutoBind,Disposable">
|
||||
<interface>
|
||||
<field id="jobQueue" type="node" bind="/JobQueue" />
|
||||
<field id="container" type="node" bind=".." />
|
||||
<field id="videoQueue" type="node" bind="../../VideoQueue" />
|
||||
<field id="preferences" type="node" bind="../../Preferences" />
|
||||
|
||||
Reference in new issue
Block a user