WIP: Added basic game and application detection. Created gameDetection.ts for the main process detection, which was then integrated into main.ts. Not production ready since it is only looking for linux based applications however i plan to continue working on this in the future
Signed-off-by: ICEBADGERR <imgranttissue@gmail.com>
This commit is contained in:
parent
a162219668
commit
4197a46a6f
21
src/main.ts
21
src/main.ts
|
|
@ -9,6 +9,9 @@ import { initDiscordRpc } from "./native/discordRpc";
|
|||
import { initTray } from "./native/tray";
|
||||
import { BUILD_URL, createMainWindow, mainWindow } from "./native/window";
|
||||
|
||||
// Added by ICEBADGERR 02/10/2026
|
||||
import { detectRunningGame } from "./native/gameDetection";
|
||||
|
||||
// Squirrel-specific logic
|
||||
// create/remove shortcuts on Windows when installing / uninstalling
|
||||
// we just need to close out of the app immediately
|
||||
|
|
@ -28,6 +31,9 @@ if (acquiredLock) {
|
|||
// start auto update logic
|
||||
updateElectronApp();
|
||||
|
||||
//Variable to check the current game process that is running
|
||||
let currentGame: string | null = null;
|
||||
|
||||
// create and configure the app when electron is ready
|
||||
app.on("ready", () => {
|
||||
// enable auto start on Windows and MacOS
|
||||
|
|
@ -42,6 +48,21 @@ if (acquiredLock) {
|
|||
initTray();
|
||||
initDiscordRpc();
|
||||
|
||||
//Detect game that is being played code
|
||||
setInterval(async () => {
|
||||
const game = await detectRunningGame();
|
||||
|
||||
//Only log if it is changed
|
||||
if (game !== currentGame) {
|
||||
currentGame = game;
|
||||
if (game) {
|
||||
console.log('Now Playing:', game);
|
||||
} else{
|
||||
console.log('Stopped Playing');
|
||||
}
|
||||
}
|
||||
}, 5000); //Checks every 5 seconds
|
||||
|
||||
// Windows specific fix for notifications
|
||||
if (process.platform === "win32") {
|
||||
app.setAppUserModelId("chat.stoat.notifications");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
import { exec } from 'child_process';
|
||||
import { promisify } from 'util';
|
||||
|
||||
const execAsync = promisify(exec)
|
||||
|
||||
//Simple detect list
|
||||
const KNOWN_GAMES: Record<string, string> = {
|
||||
'steam.exe': 'Steam',
|
||||
'discord.exe': 'Discord',
|
||||
'code': 'VS Code (replace with actual game later)'
|
||||
// Add more later
|
||||
};
|
||||
|
||||
export async function detectRunningGame(): Promise<string | null> {
|
||||
try{
|
||||
//For linux
|
||||
const { stdout } = await execAsync('ps aux');
|
||||
const lowerOutput = stdout.toLowerCase();
|
||||
|
||||
for (const [processName, gameName] of Object.entries(KNOWN_GAMES)) {
|
||||
if (lowerOutput.includes(processName.toLowerCase())) {
|
||||
return gameName;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (error) {
|
||||
console.error('Error deteching game:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue