This repository was archived by the owner on Apr 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
53 lines (41 loc) · 1.33 KB
/
index.ts
File metadata and controls
53 lines (41 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { watch } from "fs";
import { RPCManager } from "./src/RPCManager";
import { CLIENT_ID, NOW_PLAYING_PATH } from "./src/constants";
import readNowPlaying from "./src/utils/readNowPlaying";
import statesEqual from "./src/utils/statesEqual";
async function main() {
const rpc = new RPCManager(CLIENT_ID);
console.log("VLC Discord RPC with Catbox support + Timestamps");
console.log("Watching:", NOW_PLAYING_PATH);
console.log();
let currentState = await readNowPlaying(NOW_PLAYING_PATH);
await rpc.update(currentState);
let debounceTimer: Timer | null = null;
const cleanup = async () => {
console.log("\nShutting down...");
await rpc.close();
console.log("Stopped.");
process.exit(0);
};
process.on("SIGINT", cleanup);
process.on("SIGTERM", cleanup);
watch(NOW_PLAYING_PATH, async (eventType) => {
if (eventType === "change") {
if (debounceTimer) {
clearTimeout(debounceTimer);
}
debounceTimer = setTimeout(async () => {
try {
const newState = await readNowPlaying(NOW_PLAYING_PATH);
if (!statesEqual(currentState, newState)) {
await rpc.update(newState);
currentState = newState;
}
} catch (error) {
}
}, 50);
}
});
console.log("Watching for changes...");
}
main().catch(console.error);