make playing status work under linux

This commit is contained in:
HorizonCode 2022-10-24 06:36:03 +02:00
parent 2857345997
commit 033ce8f3a4
2 changed files with 63 additions and 2 deletions

49
app.js
View File

@ -7,11 +7,13 @@ const config = require('./config');
const fs = require('fs'); const fs = require('fs');
const rpc = require('./discordPresence'); const rpc = require('./discordPresence');
const windowName = require('get-window-by-name'); const windowName = require('get-window-by-name');
const terminalUtil = require('./terminalUtil');
let tempOsuPath; let tempOsuPath;
let osuWindowInfo; let osuWindowInfo;
let isIngame; let isIngame;
const platform = process.platform; const platform = process.platform;
let linuxWMCtrlFound = false;
const run = () => { const run = () => {
const gotTheLock = app.requestSingleInstanceLock() const gotTheLock = app.requestSingleInstanceLock()
@ -50,6 +52,41 @@ const run = () => {
rpc.updateState("Idle in Launcher..."); rpc.updateState("Idle in Launcher...");
rpc.updateStatus(undefined, undefined); rpc.updateStatus(undefined, undefined);
} }
} else if (platform == "linux") {
if (!linuxWMCtrlFound) {
if (isIngame) {
rpc.updateState("Playing...");
rpc.updateStatus("Clicking circles!", "runningunderwine");
} else {
rpc.updateState("Idle in Launcher...");
rpc.updateStatus(undefined, undefined);
}
return;
}
const processesOutput = await terminalUtil.execCommand(`wmctrl -l|awk '{$3=""; $2=""; $1=""; print $0}'`);
const allLines = processesOutput.split("\n");
const filteredProcesses = allLines.filter((line) => line.trim().startsWith("osu!"));
if (filteredProcesses.length > 0) {
const windowTitle = filteredProcesses[0].trim();
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 { } else {
if (isIngame) { if (isIngame) {
rpc.updateState("Playing..."); rpc.updateState("Playing...");
@ -75,10 +112,18 @@ const run = () => {
await tryLogin(mainWindow); await tryLogin(mainWindow);
await doUpdateCheck(mainWindow); await doUpdateCheck(mainWindow);
if (platform === "linux") { if (platform === "linux") {
mainWindow.webContents.send('status_update', { /* mainWindow.webContents.send('status_update', {
type: "info", type: "info",
message: "We detected that you are running the Launcher under Linux. It's currently just compatible with Arch and the osu AUR package!" message: "We detected that you are running the Launcher under Linux. It's currently just compatible with Arch and the osu AUR package!"
}); }); */
const terminalTest = await terminalUtil.execCommand(`wmctrl -l|awk '{$3=""; $2=""; $1=""; print $0}'`);
const isFailed = terminalTest.trim() == "";
if (isFailed) {
mainWindow.webContents.send('status_update', {
type: "info",
message: "Seems like you are missing the wmctrl package, please install it for the RPC to work!"
});
} else linuxWMCtrlFound = true;
} }
}) })
app.on('activate', function () { app.on('activate', function () {

16
terminalUtil.js Normal file
View File

@ -0,0 +1,16 @@
const exec = require('child_process').exec;
const execPromise = function (cmd) {
return new Promise(function (resolve, reject) {
exec(cmd, function (err, stdout) {
if (err) return reject(err);
resolve(stdout);
});
});
}
const execCommand = async (command) => {
return await execPromise(command);
}
module.exports = { execCommand };