Get running processes independent of platform

This commit is contained in:
Pierce Thompson
2023-06-27 20:09:21 -04:00
parent aa6e2488df
commit 12f8724de4
6 changed files with 51 additions and 30 deletions
+3 -3
View File
@@ -55,8 +55,8 @@ export class BSLauncherService{
return rename(steamVrFolder + ".bak", steamVrFolder).catch(log.error);
}
public isBsRunning(): boolean{
return this.bsProcess?.connected || this.utilsService.taskRunning(BS_EXECUTABLE) === true;
public async isBsRunning(): Promise<boolean> {
return this.bsProcess?.connected || await this.utilsService.taskRunning(BS_EXECUTABLE) === true;
}
// TODO : Rework with shortcuts implementation
@@ -121,4 +121,4 @@ export class BSLauncherService{
return "LAUNCHED";
}
}
}
+3 -3
View File
@@ -20,8 +20,8 @@ export class OculusService {
this.utils = UtilsService.getInstance();
}
public oculusRunning(): boolean | null{
return this.utils.taskRunning("OculusClient.exe");
public async oculusRunning(): Promise<boolean> {
return await this.utils.taskRunning("OculusClient.exe");
}
public async getOculusLibsPath(): Promise<string[]>{
@@ -64,4 +64,4 @@ export class OculusService {
return null;
}
}
}
+4 -12
View File
@@ -6,6 +6,7 @@ import { readFile } from "fs/promises";
import { spawn } from "child_process";
import { pathExist } from "../helpers/fs.helpers";
import log from "electron-log";
import psList from 'ps-list';
export class SteamService{
@@ -25,18 +26,9 @@ export class SteamService{
return SteamService.instance;
}
public async getActiveUser(): Promise<number>{
const res = await regedit.promisified.list(["HKCU\\Software\\Valve\\Steam\\ActiveProcess"]);
const keys = res?.["HKCU\\Software\\Valve\\Steam\\ActiveProcess"];
if(!keys?.exists){ throw "Key \"HKCU\\Software\\Valve\\Steam\\ActiveProcess\" not exist"; }
return (keys.values?.ActiveUser.value || undefined) as number;
}
public steamRunning(): Promise<boolean>{
return this.getActiveUser()
.then(userId => !!userId)
public async steamRunning(): Promise<boolean>{
return await psList()
.then(processes => !!processes.find(process => process.cmd.includes('steam')))
.catch(e => {log.error(e); throw e})
}
+4 -3
View File
@@ -4,6 +4,7 @@ import { app, BrowserWindow } from "electron";
import { IpcResponse } from "shared/models/ipc";
import log from "electron-log";
import { AppWindow } from "shared/models/window-manager/app-window.model";
import psList from "ps-list";
// TODO : REFACTOR
@@ -33,10 +34,10 @@ export class UtilsService{
public setMainWindows(windows: Map<AppWindow, BrowserWindow>){ this.windows = windows; }
public getMainWindows(win: AppWindow){ return this.windows.get(win); }
public taskRunning(task: string): boolean | null{
public async taskRunning(task: string): Promise<boolean> {
try{
const tasks = spawnSync('tasklist').stdout;
return tasks.toString().includes(task);
const processes = await psList();
return !!processes.find(process => process.cmd.includes(task));
}
catch(error){
log.error(error);