mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 23:51:20 -08:00
fix(dash): [PKG-DASH-CLEANUP-01] preserve first cleanup exception
This commit is contained in:
1 parent
1c522f181b
commit
25faf88e80
23 files changed
+49546
-147
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import type { Cleanup, Valid } from './types'
|
||||
|
||||
export function runCleanups(actions: Cleanup[], current: Valid = () => true): void {
|
||||
let failed = false
|
||||
let failure: unknown
|
||||
for (const action of actions) {
|
||||
if (!current())
|
||||
break
|
||||
try {
|
||||
action()
|
||||
}
|
||||
catch (error) {
|
||||
if (!failed) {
|
||||
failed = true
|
||||
failure = error
|
||||
}
|
||||
}
|
||||
}
|
||||
if (failed)
|
||||
throw failure
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import type Artplayer from 'artplayer'
|
||||
import type { AudioTrack, Option, QualityLevel, Result } from '../types/artplayer-plugin-dash-control'
|
||||
import type { AudioItem, Cleanup, EventName, Host, QualityItem, Valid } from './types'
|
||||
import $audio from './audio.svg?raw'
|
||||
import { runCleanups } from './cleanup'
|
||||
import { audioModel, qualityModel } from './mapping'
|
||||
import { createMenu } from './menu'
|
||||
import $quality from './quality.svg?raw'
|
||||
@@ -39,19 +40,7 @@ export default function artplayerPluginDashControl<Level extends object = Qualit
|
||||
})
|
||||
|
||||
function clear(current: Valid = () => true): void {
|
||||
let failure: unknown
|
||||
for (const cleanup of [quality.clear, audio.clear]) {
|
||||
if (!current())
|
||||
break
|
||||
try {
|
||||
cleanup()
|
||||
}
|
||||
catch (error) {
|
||||
failure ||= error
|
||||
}
|
||||
}
|
||||
if (failure)
|
||||
throw failure
|
||||
runCleanups([quality.clear, audio.clear], current)
|
||||
}
|
||||
|
||||
function update(): void {
|
||||
@@ -101,18 +90,8 @@ export default function artplayerPluginDashControl<Level extends object = Qualit
|
||||
return
|
||||
closed = true
|
||||
revision++
|
||||
let failure: unknown
|
||||
const actions = [observer.release, clear, ...subscriptions.splice(0).map(([name, callback]) => () => art.off(name, callback))]
|
||||
for (const action of actions) {
|
||||
try {
|
||||
action()
|
||||
}
|
||||
catch (error) {
|
||||
failure ||= error
|
||||
}
|
||||
}
|
||||
if (failure)
|
||||
throw failure
|
||||
runCleanups(actions)
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Cleanup, DisplayConfig, Label, MenuHost, MenuModel, SelectorItem, Valid } from './types'
|
||||
import { runCleanups } from './cleanup'
|
||||
|
||||
export function createMenu<Item extends SelectorItem>(art: MenuHost, name: string, icon: string) {
|
||||
let current: object | undefined
|
||||
@@ -18,17 +19,7 @@ export function createMenu<Item extends SelectorItem>(art: MenuHost, name: strin
|
||||
|
||||
function clear(): void {
|
||||
current = undefined
|
||||
let failure: unknown
|
||||
for (const [surface, callback] of [...owned]) {
|
||||
try {
|
||||
remove(surface, callback)
|
||||
}
|
||||
catch (error) {
|
||||
failure ||= error
|
||||
}
|
||||
}
|
||||
if (failure)
|
||||
throw failure
|
||||
runCleanups([...owned].map(([surface, callback]) => () => remove(surface, callback)))
|
||||
}
|
||||
|
||||
function update(config: DisplayConfig, model: MenuModel<Item> | null, active: Valid): void {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Cleanup, Dash, SDKEventName } from './types'
|
||||
import { runCleanups } from './cleanup'
|
||||
import { createSeekRecovery } from './seek-buffer'
|
||||
|
||||
interface Binding<Level extends object, Track extends object> {
|
||||
@@ -27,17 +28,7 @@ export function observeSDK<Level extends object, Track extends object>(options:
|
||||
return
|
||||
binding = undefined
|
||||
record.epoch++
|
||||
let failure: unknown
|
||||
for (const [name, callback] of record.callbacks.splice(0)) {
|
||||
try {
|
||||
record.off.call(record.dash, name, callback)
|
||||
}
|
||||
catch (error) {
|
||||
failure ||= error
|
||||
}
|
||||
}
|
||||
if (failure)
|
||||
throw failure
|
||||
runCleanups(record.callbacks.splice(0).map(([name, callback]) => () => record.off.call(record.dash, name, callback)))
|
||||
}
|
||||
|
||||
function fail(record: Binding<Level, Track>, error: unknown): void {
|
||||
|
||||
Reference in new issue
Block a user