From 12d9b07c8d0928650f6d3e3e602f8fe9ede35c20 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Wed, 5 Apr 2023 13:43:40 +0300 Subject: [PATCH] [caption-selector] use new dynamic configProvider --- plugins/captions-selector/front.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/plugins/captions-selector/front.js b/plugins/captions-selector/front.js index df5a5842..99cd52f0 100644 --- a/plugins/captions-selector/front.js +++ b/plugins/captions-selector/front.js @@ -1,7 +1,8 @@ const { ElementFromFile, templatePath } = require("../utils"); const { ipcRenderer } = require("electron"); -const config = require("./config"); +const configProvider = require("./config"); +let config; function $(selector) { return document.querySelector(selector); } @@ -9,7 +10,12 @@ const captionsSettingsButton = ElementFromFile( templatePath(__dirname, "captions-settings-template.html") ); -module.exports = () => { +module.exports = async () => { + config = await configProvider.getAll(); + + configProvider.subscribeAll((newConfig) => { + config = newConfig; + }); document.addEventListener('apiLoaded', (event) => setup(event.detail), { once: true, passive: true }); } @@ -19,7 +25,7 @@ function setup(api) { let captionTrackList = api.getOption("captions", "tracklist"); $("video").addEventListener("srcChanged", async () => { - if (await config.get('disableCaptions')) { + if (config.disableCaptions) { setTimeout(() => api.unloadModule("captions"), 100); captionsSettingsButton.style.display = "none"; return; @@ -30,9 +36,9 @@ function setup(api) { setTimeout(async () => { captionTrackList = api.getOption("captions", "tracklist"); - if (await config.get("autoload") && await config.get("lastCaptionsCode")) { + if (config.autoload && config.lastCaptionsCode) { api.setOption("captions", "track", { - languageCode: await config.get("lastCaptionsCode"), + languageCode: config.lastCaptionsCode, }); } @@ -58,7 +64,7 @@ function setup(api) { if (currentIndex === null) return; const newCaptions = captionTrackList[currentIndex]; - config.set('lastCaptionsCode', newCaptions?.languageCode); + configProvider.set('lastCaptionsCode', newCaptions?.languageCode); if (newCaptions) { api.setOption("captions", "track", { languageCode: newCaptions.languageCode }); } else {