diff --git a/plugins/AudioPlayerLite/AudioPlayerLite.js b/plugins/AudioPlayerLite/AudioPlayerLite.js index 9e7b63ce..22e05d96 100644 --- a/plugins/AudioPlayerLite/AudioPlayerLite.js +++ b/plugins/AudioPlayerLite/AudioPlayerLite.js @@ -12,24 +12,35 @@ } } + // patch.instead() appends to a list of patches, so registering on every + // navigation stacks up copies of this patch and breaks the patch chain. + let patched = false; + PluginApi.Event.addEventListener("stash:location", async (e) => { + if (patched) return; + const path = e.detail.data.location.pathname; const idRegExp = /.*\/scenes\/(\d+)/; - if (idRegExp.test(path)) { - await PluginApi.utils.loadComponents([ - PluginApi.loadableComponents.ScenePlayer - ]); - PluginApi.patch.instead("ScenePlayer", function (props, _, originalComponent) { - const file = props.scene.files[0]; - let scene = props.scene; - if (file.video_codec === "") { - scene = { ...scene, - sceneStreams: props.scene.sceneStreams.filter((ss) => ss.label.toUpperCase() === 'HSL') - }; - poster() - } - return originalComponent({ ...props, scene }); - }); - } + if (!idRegExp.test(path)) return; + + await PluginApi.utils.loadComponents([ + PluginApi.loadableComponents.ScenePlayer + ]); + + // re-check: another navigation event may have been handled while awaiting + if (patched) return; + patched = true; + + PluginApi.patch.instead("ScenePlayer", function (props, _, originalComponent) { + const file = props.scene && props.scene.files && props.scene.files[0]; + let scene = props.scene; + if (file && file.video_codec === "") { + scene = { ...scene, + sceneStreams: props.scene.sceneStreams.filter((ss) => ss.label.toUpperCase() === 'HSL') + }; + setStyle() + } + return React.createElement(originalComponent, { ...props, scene }); + }); }); })(); diff --git a/plugins/AudioPlayerLite/AudioPlayerLite.yml b/plugins/AudioPlayerLite/AudioPlayerLite.yml index 8b2174f8..937b0394 100644 --- a/plugins/AudioPlayerLite/AudioPlayerLite.yml +++ b/plugins/AudioPlayerLite/AudioPlayerLite.yml @@ -1,6 +1,6 @@ name: AudioPlayerLite description: This plugin identifies files with no video codec and plays them as audio. -version: 0.1 +version: 0.2 url: https://discourse.stashapp.cc/t/audioplayerlite/1329 ui: javascript: