Skip to content

Commit

Permalink
v1.0.1 update
Browse files Browse the repository at this point in the history
fix: broken presence after initial lifecycle
fix: stop updates on game shutdown
chore: polish some code/docs
  • Loading branch information
benjammin4dayz committed Feb 6, 2024
1 parent 740cddd commit 5886827
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Release

on:
workflow_dispatch:
push:
tags: ["*"]

Expand Down
2 changes: 1 addition & 1 deletion make.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import esbuild from "esbuild";
import dotenv from "dotenv";
import esbuild from "esbuild";
import pkg from "@yao-pkg/pkg";

dotenv.config();
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aceo-rpc",
"version": "1.0.0",
"version": "1.0.1",
"description": "Discord Rich Presence for Airport CEO!",
"main": "src/index.js",
"private": true,
Expand Down
14 changes: 11 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ console.log(
].join("\n")
);

const client = new RPCLite();
const game = new ProcMon(["Airport CEO"]);
game.startup(); // stdby for game start
let [client, presenceInterval] = [null, null];

game.on("start", () => {
!client && (client = new RPCLite());

const presenceObj = {
client,
getter: getAirportData,
Expand All @@ -32,7 +34,10 @@ game.on("start", () => {
.then(() => {
handleProcessEvents(client);
handleSetDiscordPresence(presenceObj);
setInterval(() => handleSetDiscordPresence(presenceObj), 1 * 60000);
presenceInterval = setInterval(
() => handleSetDiscordPresence(presenceObj),
1 * 60000
);
})
.catch((e) => {
console.error("An error has occurred:", e);
Expand All @@ -41,7 +46,10 @@ game.on("start", () => {
});

game.on("stop", async () => {
await client.destroy();
clearInterval(presenceInterval);
await client?.clearActivity();
await client?.destroy();
client = null;
});

function handleProcessEvents(client) {
Expand Down
6 changes: 3 additions & 3 deletions src/saveUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import os from "os";
import path from "path";

/**
*
* @param {"win32" | "linux" | any} platform Identifier for the active O.S.
* Find the path where the user's game data is stored.
* @param {"win32" | "linux" | "darwin"} platform Identifier for the active O.S.
* @returns {string} Path to the user's save folder if it exists, otherwise an empty string.
*/
function findGameData(platform = os.platform()) {
Expand Down Expand Up @@ -59,7 +59,7 @@ function getLatestModifiedSaveFilePath(saveDir, file) {
}

/**
* Responsible for reading and parsing the save file into a valid JSON object.
* Read and parse the save file into a valid JSON object.
* @param {fs.PathLike} savePath Full path to a save file which contains valid JSON.
* @returns Parsed JSON object representing the save file's contents.
*/
Expand Down

0 comments on commit 5886827

Please sign in to comment.