feat: add config

This commit is contained in:
newt 2024-11-17 12:59:14 +00:00
parent c21b623ffd
commit dcd7407bc5
2 changed files with 32 additions and 4 deletions

View file

@ -1,10 +1,32 @@
import { definePluginSettings } from "@api/Settings";
import { Logger } from "@utils/Logger"; import { Logger } from "@utils/Logger";
import definePlugin from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { FluxDispatcher } from "@webpack/common"; import { FluxDispatcher } from "@webpack/common";
const logger = new Logger("muter"); const logger = new Logger("muter");
const reconnect_interval = 5000; const settings = definePluginSettings({
const port = 3034; port: {
description: "Port to connect to muter on.",
type: OptionType.NUMBER,
default: 3034,
onChange: value => {
port = value;
socket.close();
connect();
}
},
reconnect: {
description: "Reconnect interval in seconds.",
type: OptionType.NUMBER,
default: 5,
onChange: value => {
reconnect = value * 1000;
}
}
});
let port: number;
let reconnect: number;
let muted = false; let muted = false;
let socket: WebSocket; let socket: WebSocket;
@ -28,7 +50,7 @@ function connect() {
socket.onclose = e => { socket.onclose = e => {
if (!e.wasClean) { if (!e.wasClean) {
logger.error("Connection to muter was interrupted. Reconnecting..."); logger.error("Connection to muter was interrupted. Reconnecting...");
setTimeout(connect, reconnect_interval); setTimeout(connect, reconnect);
} else { } else {
logger.info("Connection to muter closed"); logger.info("Connection to muter closed");
} }
@ -39,8 +61,11 @@ export default definePlugin({
name: "muter", name: "muter",
description: "muter companion plugin. Mirrors system mutes to Discord.", description: "muter companion plugin. Mirrors system mutes to Discord.",
authors: [{ name: "isitreallyalive", id: 1269669249056510026n }], authors: [{ name: "isitreallyalive", id: 1269669249056510026n }],
settings,
start() { start() {
port = settings.store.port;
reconnect = settings.store.reconnect;
connect(); connect();
// todo: try to fix weird virtual bug // todo: try to fix weird virtual bug
}, },

3
readme.md Normal file
View file

@ -0,0 +1,3 @@
# muter-vencord
A plugin for [Vencord](https://vencord.dev/) which integrates with [muter](https://git.newty.dev/newt/muter) to synchronise system mutes to Discord.