diff --git a/src/main/main.ts b/src/main/main.ts index a080eec2..54191b9f 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -40,6 +40,7 @@ export const loadState = async () => { } Ludusavi.copyConfigFileToUserData(); + Ludusavi.copyBinaryToUserData(); await HydraApi.setupApi().then(() => { uploadGamesBatch(); diff --git a/src/main/services/ludusavi.ts b/src/main/services/ludusavi.ts index 67cf7c48..133f764e 100644 --- a/src/main/services/ludusavi.ts +++ b/src/main/services/ludusavi.ts @@ -8,19 +8,19 @@ import cp from "node:child_process"; import { SystemPath } from "./system-path"; export class Ludusavi { - private static ludusaviPath = app.isPackaged + private static ludusaviResourcesPath = app.isPackaged ? path.join(process.resourcesPath, "ludusavi") : path.join(__dirname, "..", "..", "ludusavi"); - private static binaryPath = path.join(this.ludusaviPath, "ludusavi"); private static configPath = path.join( SystemPath.getPath("userData"), "ludusavi" ); + private static binaryPath = path.join(this.configPath, "ludusavi"); public static async getConfig() { const config = YAML.parse( - fs.readFileSync(path.join(this.ludusaviPath, "config.yaml"), "utf-8") + fs.readFileSync(path.join(this.configPath, "config.yaml"), "utf-8") ) as LudusaviConfig; return config; @@ -29,12 +29,20 @@ export class Ludusavi { public static async copyConfigFileToUserData() { if (!fs.existsSync(this.configPath)) { fs.mkdirSync(this.configPath, { recursive: true }); + fs.cpSync( - path.join(this.ludusaviPath, "config.yaml"), + path.join(this.ludusaviResourcesPath, "config.yaml"), path.join(this.configPath, "config.yaml") ); + } + } - fs.cpSync(this.binaryPath, path.join(this.configPath, "ludusavi")); + public static async copyBinaryToUserData() { + if (!fs.existsSync(this.binaryPath)) { + fs.cpSync( + path.join(this.ludusaviResourcesPath, "ludusavi"), + this.binaryPath + ); } } diff --git a/src/main/services/ws/ws-client.ts b/src/main/services/ws/ws-client.ts index 632a3107..e2e9d550 100644 --- a/src/main/services/ws/ws-client.ts +++ b/src/main/services/ws/ws-client.ts @@ -34,6 +34,10 @@ export class WSClient { }); this.ws.on("message", (message) => { + if (message.toString() === "PONG") { + return; + } + const envelope = Envelope.fromBinary( new Uint8Array(Buffer.from(message.toString())) ); @@ -112,7 +116,7 @@ export class WSClient { private static startHeartbeat() { this.heartbeatInterval = setInterval(() => { if (this.ws && this.ws.readyState === WebSocket.OPEN) { - this.ws.ping(); + this.ws.send("PING"); } }, 15_000); }