Skip to content

Commit e6cbeea

Browse files
committed
fix settings not loaded
1 parent 8a22117 commit e6cbeea

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

open-in-mpv.plugin.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88

9-
const mySettings = { showAgain: true };
9+
const settings = { showAgain: true };
1010

1111
const contextMenuPatch = (tree, context) => {
1212
const href = context.target.href || context.target.parentNode.href
@@ -26,7 +26,7 @@ const contextMenuPatch = (tree, context) => {
2626
const electron = require('electron');
2727

2828
electron.shell.openExternal('mpv://' + href).then(() => {
29-
if (mySettings.showAgain !== false) {
29+
if (settings.showAgain !== false) {
3030
BdApi.UI.showConfirmationModal("Open in mpv", "Successfully opened " + href + " in mpv. Did nothing happen? Download and run setup.sh", {
3131
confirmText: "Download setup.sh",
3232
onConfirm: () => {
@@ -35,8 +35,8 @@ const contextMenuPatch = (tree, context) => {
3535

3636
cancelText: "Ok, don't show again",
3737
onCancel: () => {
38-
mySettings.showAgain = false;
39-
BdApi.Data.save("open-in-mpv", "settings", mySettings);
38+
settings.showAgain = false;
39+
BdApi.Data.save("open-in-mpv", "settings", settings);
4040
},
4141
})
4242
} else {
@@ -67,19 +67,20 @@ function buildSetting(text, key, type, value, callback = () => {
6767
}
6868
input.addEventListener("change", () => {
6969
const newValue = type === "checkbox" ? input.checked : input.value;
70-
mySettings[key] = newValue;
71-
BdApi.Data.save("open-in-mpv", "settings", mySettings);
70+
settings[key] = newValue;
71+
BdApi.Data.save("open-in-mpv", "settings", settings);
7272
callback(newValue);
7373
});
7474
setting.append(label, input);
7575
return setting;
7676
}
7777

7878
// noinspection JSUnusedGlobalSymbols
79-
module.exports = (meta) => ({
79+
module.exports = () => ({
8080
start() {
8181
console.log("Open in mpv plugin enabled");
8282

83+
Object.assign(settings, BdApi.Data.load("open-in-mpv", "settings"));
8384
BdApi.ContextMenu.patch("message", contextMenuPatch);
8485
},
8586
stop() {
@@ -89,7 +90,7 @@ module.exports = (meta) => ({
8990
const mySettingsPanel = document.createElement("div", { className: "bd-addon-settings-wrap" });
9091
mySettingsPanel.id = "my-settings";
9192

92-
const showAgain = buildSetting("Show Dialog", "showAgain", "checkbox", mySettings.showAgain);
93+
const showAgain = buildSetting("Show Dialog", "showAgain", "checkbox", settings.showAgain);
9394

9495
mySettingsPanel.append(showAgain);
9596
return mySettingsPanel;

0 commit comments

Comments
 (0)