refactor: add full documentation and fix theme loading robustness

- Add JSDoc comments across frontend and backend modules
- Improve code readability and maintainability with consistent documentation style
- Document Electron IPC handlers, UI utilities, and theme system
- Add missing function/class documentation in theme loader and app services
- Minor structural improvements and cleanup across Electron main process modules
- Minor fixes on variable names
This commit is contained in:
MasterAcnolo
2026-05-31 20:38:42 +02:00
parent 6afc5e06d6
commit 0218664c5a
34 changed files with 1777 additions and 340 deletions

View File

@@ -2,12 +2,40 @@ const config = require('../config');
const RPC = require("discord-rpc");
const { logger } = require("../server/logger");
/**
* Discord Application Client ID used to authenticate the RPC connection.
* Comes from the application configuration.
*/
const clientId = `${config.DiscordRPCID}`;
/**
* Discord RPC client instance using IPC transport.
* Maintains a persistent connection with Discord desktop client.
*/
const rpc = new RPC.Client({ transport: "ipc" });
/**
* Optional interval reference used for future RPC refresh logic.
* Currently reserved for potential periodic activity updates.
*/
let intervalId;
/**
* Initializes Discord Rich Presence (RPC) connection.
*
* Responsibilities:
* - Connect to Discord via IPC transport
* - Set application presence (title, state, timestamps, assets)
* - Handle connection errors gracefully via logger
*
* Triggered once during application startup.
*/
function startRPC() {
/**
* Rich Presence payload describing current application state
* shown in Discord user profile.
*/
rpc.on("ready", () => {
const presence = {
largeImageKey: "icon",
@@ -27,10 +55,22 @@ function startRPC() {
});
}
/**
* Gracefully stops Discord Rich Presence connection.
*
* Responsibilities:
* - Clear any running intervals
* - Remove current activity from Discord
* - Destroy RPC transport connection
* - Handle cleanup errors safely
*/
async function stopRPC(){
try {
if (intervalId) clearInterval(intervalId);
/**
* Ensures RPC connection exists before attempting cleanup.
*/
if (rpc && rpc.transport) {
await rpc.clearActivity()
await rpc.destroy();