/* * Vencord, a Discord client mod * Copyright (c) 2026 Vendicated and contributors * SPDX-License-Identifier: GPL-3.0-or-later */ import { app, IpcMainInvokeEvent, shell } from "electron"; import { appendFile, writeFile } from "fs/promises"; import { join } from "path"; const LOG_FILE = "watchcord-logs.txt"; const STATUS_CHANGE_FILE = "watchcord-full-status-changes.json"; function getLogPath(): string { return join(app.getPath("userData"), LOG_FILE); } function getStatusChangePath(): string { return join(app.getPath("userData"), STATUS_CHANGE_FILE); } export async function appendLog( _: IpcMainInvokeEvent, logLine: string ): Promise { const logPath = getLogPath(); await appendFile(logPath, logLine + "\n", "utf-8"); } export async function clearLogs(_: IpcMainInvokeEvent): Promise { const logPath = getLogPath(); await writeFile(logPath, "", "utf-8"); } export async function openLogFile(_: IpcMainInvokeEvent): Promise { const logPath = getLogPath(); // Create file if it doesn't exist try { await appendFile(logPath, "", { flag: "a" }); } catch { // ignore } shell.openPath(logPath); } export async function sendWebhook( _: IpcMainInvokeEvent, webhookUrl: string, content: string ): Promise<{ ok: boolean; error?: string }> { try { const res = await fetch(webhookUrl, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ content }), }); return { ok: res.ok }; } catch (e) { return { ok: false, error: String(e) }; } } export async function logFullStatusChange( _: IpcMainInvokeEvent, statusChangeObject: any ): Promise { const statusChangePath = getStatusChangePath(); const timestamp = new Date().toISOString(); const logEntry = { timestamp, data: statusChangeObject }; await appendFile(statusChangePath, JSON.stringify(logEntry, null, 2) + "\n---\n", "utf-8"); } export async function openStatusChangeFile(_: IpcMainInvokeEvent): Promise { const statusChangePath = getStatusChangePath(); // Create file if it doesn't exist try { await appendFile(statusChangePath, "", { flag: "a" }); } catch { // ignore } shell.openPath(statusChangePath); } export async function clearStatusChanges(_: IpcMainInvokeEvent): Promise { const statusChangePath = getStatusChangePath(); await writeFile(statusChangePath, "", "utf-8"); }