Skip to content

Commit 04cbfde

Browse files
committed
improve settings
1 parent cf705c1 commit 04cbfde

File tree

1 file changed

+22
-71
lines changed

1 file changed

+22
-71
lines changed

open-in-mpv.plugin.js

Lines changed: 22 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -50,72 +50,29 @@ function contextMenuPatch(tree, context) {
5050
}
5151
}
5252

53-
document.createSvgElement = (name) => { return document.createElementNS("http://www.w3.org/2000/svg", name) };
53+
const { React, React: { useState }, Webpack: { Filters, getModule } } = BdApi;
5454

55-
function buildCheckboxSetting(text, key, callback = () => {}) {
56-
const setting = document.createElement("div");
57-
setting.className = "flex_f5fbb7 vertical__1e37a justifyStart__42744 alignStretch_e239ef noWrap__5c413";
58-
setting.style.flex = "1 1 auto";
59-
60-
const rowWrapper = document.createElement("div");
61-
rowWrapper.className = "flex_f5fbb7 horizontal__992f6 justifyStart__42744 alignStart__4fe1e noWrap__5c413";
62-
rowWrapper.style.flex = "1 1 auto";
63-
64-
const titleWrapper = document.createElement("div");
65-
titleWrapper.className = "flexChild__6e093";
66-
titleWrapper.style.flex = "1 1 auto";
67-
68-
const title = document.createElement("div");
69-
title.className = "title__28a65";
70-
title.textContent = text;
71-
72-
const switchWrapper = document.createElement("div");
73-
switchWrapper.className = "bd-switch";
74-
if (settings[key]) switchWrapper.classList.add("bd-switch-checked");
75-
76-
const input = document.createElement("input");
77-
input.type = "checkbox";
78-
input.checked = settings[key];
79-
80-
input.addEventListener("change", () => {
81-
const newValue = input.checked;
82-
if (newValue) switchWrapper.classList.add("bd-switch-checked"); else switchWrapper.classList.remove("bd-switch-checked");
83-
settings[key] = newValue;
84-
BdApi.Data.save("open-in-mpv", "settings", settings);
85-
callback(newValue);
55+
const TheBigBoyBundle = getModule(Filters.byProps("openModal", "FormSwitch", "Anchor"));
56+
57+
function Switch({ value, note, hideBorder, label, key }) {
58+
const [enabled, setEnabled] = useState(value);
59+
return (React.createElement(TheBigBoyBundle.FormSwitch, {
60+
value: enabled, note: note, hideBorder: hideBorder, onChange: e => {
61+
setEnabled(e);
62+
63+
console.log(e);
64+
65+
settings[key] = e;
66+
BdApi.Data.save("open-in-mpv", "settings", settings);
67+
68+
},
69+
}, label));
70+
}
71+
72+
const SettingComponent = () => {
73+
return React.createElement(Switch, {
74+
value: true, /*note: "this is a note",*/ hideBorder: true, onChange: console.log, label: "Show Dialog", key: "showAgain",
8675
});
87-
88-
const switchBody = document.createElement("div");
89-
switchBody.className = "bd-switch-body";
90-
91-
const switchSlider = document.createSvgElement("svg");
92-
switchSlider.setAttribute("class", "bd-switch-slider");
93-
switchSlider.setAttribute("viewBox", "0 0 28 20");
94-
switchSlider.setAttribute("preserveAspectRatio", "xMinYMid meet");
95-
96-
const handle = document.createSvgElement("rect");
97-
handle.setAttribute("class", "bd-switch-handle");
98-
handle.setAttribute("fill", "white");
99-
handle.setAttribute("x", "4");
100-
handle.setAttribute("y", "0");
101-
handle.setAttribute("height", "20");
102-
handle.setAttribute("width", "20");
103-
handle.setAttribute("rx", "10");
104-
105-
const symbol = document.createSvgElement("svg");
106-
symbol.setAttribute("class", "bd-switch-symbol");
107-
symbol.setAttribute("viewBox", "0 0 20 20");
108-
symbol.setAttribute("fill", "none");
109-
110-
symbol.append(document.createSvgElement("path"), document.createSvgElement("path"));
111-
switchSlider.append(handle, symbol);
112-
switchBody.append(switchSlider);
113-
switchWrapper.append(input, switchBody);
114-
titleWrapper.append(title);
115-
rowWrapper.append(titleWrapper, switchWrapper);
116-
setting.append(rowWrapper);
117-
118-
return setting;
11976
}
12077

12178
module.exports = () => ({
@@ -125,13 +82,7 @@ module.exports = () => ({
12582
BdApi.ContextMenu.patch("message", contextMenuPatch);
12683
}, stop() {
12784
BdApi.ContextMenu.unpatch("message", contextMenuPatch);
128-
}, getSettingsPanel: () => {
129-
const mySettingsPanel = Object.assign(document.createElement("div"));
130-
131-
mySettingsPanel.append(buildCheckboxSetting("Show Dialog", "showAgain"));
132-
133-
return mySettingsPanel;
134-
},
85+
}, getSettingsPanel: () => React.createElement(SettingComponent),
13586
});
13687

13788
function isEmpty(obj) {

0 commit comments

Comments
 (0)