diff --git a/index.ts b/index.ts index d36ff34..aaefb80 100644 --- a/index.ts +++ b/index.ts @@ -1,10 +1,32 @@ +import { definePluginSettings } from "@api/Settings"; import { Logger } from "@utils/Logger"; -import definePlugin from "@utils/types"; +import definePlugin, { OptionType } from "@utils/types"; import { FluxDispatcher } from "@webpack/common"; const logger = new Logger("muter"); -const reconnect_interval = 5000; -const port = 3034; +const settings = definePluginSettings({ + 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 socket: WebSocket; @@ -28,7 +50,7 @@ function connect() { socket.onclose = e => { if (!e.wasClean) { logger.error("Connection to muter was interrupted. Reconnecting..."); - setTimeout(connect, reconnect_interval); + setTimeout(connect, reconnect); } else { logger.info("Connection to muter closed"); } @@ -39,8 +61,11 @@ export default definePlugin({ name: "muter", description: "muter companion plugin. Mirrors system mutes to Discord.", authors: [{ name: "isitreallyalive", id: 1269669249056510026n }], + settings, start() { + port = settings.store.port; + reconnect = settings.store.reconnect; connect(); // todo: try to fix weird virtual bug }, diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..7e1b1db --- /dev/null +++ b/readme.md @@ -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.