mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
Merge pull request #257 from Insprill/fix/running-processes
Get running processes independent of platform
This commit is contained in:
Generated
+27
-6
@@ -27,6 +27,7 @@
|
||||
"md5-file": "^5.0.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
"node-stream-zip": "^1.15.0",
|
||||
"ps-list": "^7.2.0",
|
||||
"react": "^18.2.0",
|
||||
"react-colorful": "^5.6.1",
|
||||
"react-dom": "^18.2.0",
|
||||
@@ -4784,9 +4785,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/caniuse-lite": {
|
||||
"version": "1.0.30001431",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001431.tgz",
|
||||
"integrity": "sha512-zBUoFU0ZcxpvSt9IU66dXVT/3ctO1cy4y9cscs1szkPlcWb6pasYM144GqrUygUbT+k7cmUCW61cvskjcv0enQ==",
|
||||
"version": "1.0.30001508",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001508.tgz",
|
||||
"integrity": "sha512-sdQZOJdmt3GJs1UMNpCCCyeuS2IEGLXnHyAo9yIO5JJDjbjoVRij4M1qep6P6gFpptD1PqIYgzM+gwJbOi92mw==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
@@ -4796,6 +4797,10 @@
|
||||
{
|
||||
"type": "tidelift",
|
||||
"url": "https://tidelift.com/funding/github/npm/caniuse-lite"
|
||||
},
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/ai"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -14856,6 +14861,17 @@
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/ps-list": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/ps-list/-/ps-list-7.2.0.tgz",
|
||||
"integrity": "sha512-v4Bl6I3f2kJfr5o80ShABNHAokIgY+wFDTQfE+X3zWYgSGQOCBeYptLZUpoOALBqO5EawmDN/tjTldJesd0ujQ==",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/ps-scrollbar-tailwind": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ps-scrollbar-tailwind/-/ps-scrollbar-tailwind-0.0.1.tgz",
|
||||
@@ -22490,9 +22506,9 @@
|
||||
}
|
||||
},
|
||||
"caniuse-lite": {
|
||||
"version": "1.0.30001431",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001431.tgz",
|
||||
"integrity": "sha512-zBUoFU0ZcxpvSt9IU66dXVT/3ctO1cy4y9cscs1szkPlcWb6pasYM144GqrUygUbT+k7cmUCW61cvskjcv0enQ==",
|
||||
"version": "1.0.30001508",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001508.tgz",
|
||||
"integrity": "sha512-sdQZOJdmt3GJs1UMNpCCCyeuS2IEGLXnHyAo9yIO5JJDjbjoVRij4M1qep6P6gFpptD1PqIYgzM+gwJbOi92mw==",
|
||||
"dev": true
|
||||
},
|
||||
"chalk": {
|
||||
@@ -29985,6 +30001,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"ps-list": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/ps-list/-/ps-list-7.2.0.tgz",
|
||||
"integrity": "sha512-v4Bl6I3f2kJfr5o80ShABNHAokIgY+wFDTQfE+X3zWYgSGQOCBeYptLZUpoOALBqO5EawmDN/tjTldJesd0ujQ=="
|
||||
},
|
||||
"ps-scrollbar-tailwind": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ps-scrollbar-tailwind/-/ps-scrollbar-tailwind-0.0.1.tgz",
|
||||
|
||||
@@ -248,6 +248,7 @@
|
||||
"md5-file": "^5.0.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
"node-stream-zip": "^1.15.0",
|
||||
"ps-list": "^7.2.0",
|
||||
"react": "^18.2.0",
|
||||
"react-colorful": "^5.6.1",
|
||||
"react-dom": "^18.2.0",
|
||||
|
||||
@@ -55,14 +55,14 @@ 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
|
||||
public async launch(launchOptions: LauchOption): Promise<LaunchResult>{
|
||||
if(this.isBsRunning() === true){ return "BS_ALREADY_RUNNING" }
|
||||
if(launchOptions.version.oculus && this.oculusService.oculusRunning() === false){ return "OCULUS_NOT_RUNNING" }
|
||||
if(await this.isBsRunning() === true){ return "BS_ALREADY_RUNNING" }
|
||||
if(launchOptions.version.oculus && await this.oculusService.oculusRunning() === false){ return "OCULUS_NOT_RUNNING" }
|
||||
|
||||
const steamRunning = await this.steamService.steamRunning().catch(() => true); // True if error (error not not means that steam is not running)
|
||||
if(!launchOptions.version.oculus && !steamRunning){
|
||||
@@ -121,4 +121,4 @@ export class BSLauncherService{
|
||||
return "LAUNCHED";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
import { app } from "electron";
|
||||
|
||||
export class SteamService{
|
||||
@@ -26,20 +27,21 @@ 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"];
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
.catch(e => {log.error(e); throw e})
|
||||
public async steamRunning(): Promise<boolean>{
|
||||
if (process.platform === 'win32') {
|
||||
return !!(await this.getActiveUser());
|
||||
}
|
||||
return await psList()
|
||||
.then(processes => !!processes.find(process => process.cmd.includes('steam')))
|
||||
.catch(e => {log.error(e); throw e})
|
||||
}
|
||||
|
||||
public async getSteamPath(): Promise<string>{
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user