Skip to content

Commit 20db77f

Browse files
authored
Merge pull request #1102 from Araxeus/caption-selector-use-new-dynamic-configProvider
2 parents d0ab23f + 12d9b07 commit 20db77f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

plugins/captions-selector/front.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
const { ElementFromFile, templatePath } = require("../utils");
22
const { ipcRenderer } = require("electron");
33

4-
const config = require("./config");
4+
const configProvider = require("./config");
5+
let config;
56

67
function $(selector) { return document.querySelector(selector); }
78

89
const captionsSettingsButton = ElementFromFile(
910
templatePath(__dirname, "captions-settings-template.html")
1011
);
1112

12-
module.exports = () => {
13+
module.exports = async () => {
14+
config = await configProvider.getAll();
15+
16+
configProvider.subscribeAll((newConfig) => {
17+
config = newConfig;
18+
});
1319
document.addEventListener('apiLoaded', (event) => setup(event.detail), { once: true, passive: true });
1420
}
1521

@@ -19,7 +25,7 @@ function setup(api) {
1925
let captionTrackList = api.getOption("captions", "tracklist");
2026

2127
$("video").addEventListener("srcChanged", async () => {
22-
if (await config.get('disableCaptions')) {
28+
if (config.disableCaptions) {
2329
setTimeout(() => api.unloadModule("captions"), 100);
2430
captionsSettingsButton.style.display = "none";
2531
return;
@@ -30,9 +36,9 @@ function setup(api) {
3036
setTimeout(async () => {
3137
captionTrackList = api.getOption("captions", "tracklist");
3238

33-
if (await config.get("autoload") && await config.get("lastCaptionsCode")) {
39+
if (config.autoload && config.lastCaptionsCode) {
3440
api.setOption("captions", "track", {
35-
languageCode: await config.get("lastCaptionsCode"),
41+
languageCode: config.lastCaptionsCode,
3642
});
3743
}
3844

@@ -58,7 +64,7 @@ function setup(api) {
5864
if (currentIndex === null) return;
5965

6066
const newCaptions = captionTrackList[currentIndex];
61-
config.set('lastCaptionsCode', newCaptions?.languageCode);
67+
configProvider.set('lastCaptionsCode', newCaptions?.languageCode);
6268
if (newCaptions) {
6369
api.setOption("captions", "track", { languageCode: newCaptions.languageCode });
6470
} else {

0 commit comments

Comments
 (0)