mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-28 10:31:20 -08:00
refactor(jassub): [PKG-JASSUB-03] isolate registration and fix adapter cleanup
This commit is contained in:
1 parent
944e2cc9d0
commit
38e7b37878
21 files changed
+6553
-70
No files matched your search
@@ -1,21 +1,5 @@
|
||||
import JASSUB from './jassub.es.js'
|
||||
import { registerJassub } from './registration.js'
|
||||
|
||||
export default function artplayerPluginJassub(option) {
|
||||
return (art) => {
|
||||
const instance = new JASSUB({
|
||||
video: art.video,
|
||||
...option,
|
||||
})
|
||||
|
||||
instance._canvasParent.style.zIndex = 20
|
||||
|
||||
art.on('destroy', () => {
|
||||
instance.destroy()
|
||||
})
|
||||
|
||||
return {
|
||||
name: 'artplayerPluginJassub',
|
||||
instance,
|
||||
}
|
||||
}
|
||||
return art => registerJassub(art, option)
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import JASSUB from './jassub.es.js'
|
||||
|
||||
export function registerJassub(art, option) {
|
||||
const instance = new JASSUB({ video: art.video, ...option })
|
||||
let disposed = false
|
||||
const dispose = () => {
|
||||
if (disposed || instance._destroyed)
|
||||
return
|
||||
disposed = true
|
||||
try {
|
||||
instance.destroy()
|
||||
}
|
||||
catch (error) {
|
||||
disposed = false
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (instance._canvasParent)
|
||||
instance._canvasParent.style.zIndex = 20
|
||||
art.on('destroy', dispose)
|
||||
}
|
||||
catch (error) {
|
||||
// Registration may throw after attaching its listener. Keep the original
|
||||
// error while independently attempting listener and instance rollback.
|
||||
try {
|
||||
art.off('destroy', dispose)
|
||||
}
|
||||
catch {}
|
||||
try {
|
||||
dispose()
|
||||
}
|
||||
catch {}
|
||||
throw error
|
||||
}
|
||||
|
||||
return { name: 'artplayerPluginJassub', instance }
|
||||
}
|
||||
Reference in new issue
Block a user