add basic discord rpc, showing osu status
This commit is contained in:
parent
1de9fce504
commit
c8a07fbb0d
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
node_modules/
|
||||
release/
|
||||
yarn.lock
|
||||
pnpm-lock.yaml
|
||||
|
|
39
app.js
39
app.js
|
@ -5,8 +5,11 @@ const osuUtil = require('./osuUtil');
|
|||
const ezppUtil = require('./ezppUtil');
|
||||
const config = require('./config');
|
||||
const fs = require('fs');
|
||||
const rpc = require('./discordPresence');
|
||||
const windowName = require('get-window-by-name');
|
||||
|
||||
let tempOsuPath;
|
||||
let osuWindowInfo;
|
||||
|
||||
const run = () => {
|
||||
const gotTheLock = app.requestSingleInstanceLock()
|
||||
|
@ -15,8 +18,43 @@ const run = () => {
|
|||
return;
|
||||
}
|
||||
|
||||
setInterval(() => {
|
||||
osuWindowInfo = windowName.getWindowText("osu!.exe");
|
||||
const firstInstance = osuWindowInfo[0];
|
||||
if (firstInstance) {
|
||||
if (firstInstance.processTitle && firstInstance.processTitle.length > 0) {
|
||||
const windowTitle = firstInstance.processTitle;
|
||||
let rpcOsuVersion = "";
|
||||
let currentMap = undefined;
|
||||
if (!windowTitle.includes("-")) {
|
||||
rpcOsuVersion = windowTitle;
|
||||
rpc.updateState("Idle...");
|
||||
} else {
|
||||
var string = windowTitle;
|
||||
var components = string.split(' - ');
|
||||
const splitArray = [components.shift(), components.join(' - ')];
|
||||
rpcOsuVersion = splitArray[0];
|
||||
currentMap = splitArray[1];
|
||||
rpc.updateState("Playing...");
|
||||
}
|
||||
|
||||
rpc.updateStatus(currentMap, rpcOsuVersion);
|
||||
} else {
|
||||
rpc.updateState("Idle in Launcher...");
|
||||
rpc.updateStatus(undefined, undefined);
|
||||
}
|
||||
} else {
|
||||
rpc.updateState("Idle in Launcher...");
|
||||
rpc.updateStatus(undefined, undefined);
|
||||
}
|
||||
console.log(osuWindowInfo);
|
||||
}, 2000);
|
||||
|
||||
setupTitlebar();
|
||||
|
||||
rpc.connect();
|
||||
|
||||
|
||||
let mainWindow;
|
||||
app.whenReady().then(() => {
|
||||
|
||||
|
@ -46,6 +84,7 @@ const run = () => {
|
|||
await osuUtil.setConfigValue(osuConfig.path, "Username", "");
|
||||
await osuUtil.setConfigValue(osuConfig.path, "Password", "");
|
||||
}
|
||||
rpc.updateState("Launching osu!...");
|
||||
const result = await osuUtil.startOsuWithDevServer(tempOsuPath, "ez-pp.farm", async () => {
|
||||
await doUpdateCheck(mainWindow);
|
||||
});
|
||||
|
|
69
discordPresence.js
Normal file
69
discordPresence.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
const appInfo = require('./appInfo.js');
|
||||
const DiscordAutoRPC = require("discord-auto-rpc");
|
||||
const { app } = require('electron');
|
||||
const DiscordRPC = require("discord-rpc").default;
|
||||
const clientId = "1032772293220384808";
|
||||
let client = undefined;
|
||||
let lastState = "Idle in Launcher...";
|
||||
let presenceEnabled = true;
|
||||
let startDate = new Date();
|
||||
let lastActivity = {
|
||||
details: " ",
|
||||
state: lastState,
|
||||
startTimestamp: startDate,
|
||||
largeImageKey: "ezppfarm",
|
||||
largeImageText: appInfo.appName + " " + appInfo.appVersion,
|
||||
buttons: [
|
||||
{
|
||||
label: "Download the Launcher",
|
||||
url: "https://ez-pp.farm/download"
|
||||
},
|
||||
{
|
||||
label: "Join EZPPFarm",
|
||||
url: "https://discord.com/invite/g8Bh7RaKPg"
|
||||
}
|
||||
],
|
||||
instance: false,
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
connect: () => {
|
||||
if (client === undefined) {
|
||||
client = new DiscordAutoRPC.AutoClient({ transport: "ipc" });
|
||||
client.endlessLogin({ clientId: clientId });
|
||||
client.once("ready", () => {
|
||||
setInterval(() => {
|
||||
if (lastActivity !== undefined)
|
||||
lastActivity.state = lastState;
|
||||
client.setActivity(presenceEnabled ? lastActivity : undefined);
|
||||
}, 2500);
|
||||
});
|
||||
}
|
||||
},
|
||||
enablePresence: () => presenceEnabled = true,
|
||||
disablePresence: () => presenceEnabled = false,
|
||||
updateStartDate: () => startDate = new Date(),
|
||||
updateState: (state) => lastState = state,
|
||||
updateStatus: (details, osuVersion) => {
|
||||
lastActivity = {
|
||||
details: details ? details : " ",
|
||||
state: lastState,
|
||||
startTimestamp: startDate,
|
||||
smallImageKey: osuVersion ? "osu" : " ",
|
||||
smallImageText: osuVersion ? osuVersion : " ",
|
||||
largeImageKey: "ezppfarm",
|
||||
largeImageText: appInfo.appName + " " + appInfo.appVersion,
|
||||
buttons: [
|
||||
{
|
||||
label: "Download the Launcher",
|
||||
url: "https://ez-pp.farm/download"
|
||||
},
|
||||
{
|
||||
label: "Join EZPPFarm",
|
||||
url: "https://discord.com/invite/g8Bh7RaKPg"
|
||||
}
|
||||
],
|
||||
instance: false,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -50,6 +50,9 @@
|
|||
"dependencies": {
|
||||
"axios": "^0.27.2",
|
||||
"custom-electron-titlebar": "^4.1.1",
|
||||
"discord-auto-rpc": "^1.0.17",
|
||||
"discord-rpc": "^4.0.1",
|
||||
"get-window-by-name": "^2.0.0",
|
||||
"jquery": "^3.6.0",
|
||||
"node-downloader-helper": "^2.1.4",
|
||||
"sweetalert2": "^11.5.2",
|
||||
|
|
Loading…
Reference in New Issue
Block a user