fix: fixing ping pong

This commit is contained in:
Chubby Granny Chaser
2025-05-21 19:44:24 +01:00
parent 05e8d53783
commit 61dae4cf84
3 changed files with 19 additions and 6 deletions

View File

@@ -40,6 +40,7 @@ export const loadState = async () => {
}
Ludusavi.copyConfigFileToUserData();
Ludusavi.copyBinaryToUserData();
await HydraApi.setupApi().then(() => {
uploadGamesBatch();

View File

@@ -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
);
}
}

View File

@@ -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);
}