Merge branch 'master' into feature/launch-bs-from-shortcut

This commit is contained in:
MathieuG-P
2023-06-30 15:44:57 +02:00
19 changed files with 701 additions and 616 deletions
+4 -2
View File
@@ -1,4 +1,4 @@
import { ipcMain } from 'electron';
import { ipcMain, shell } from 'electron';
import { UtilsService } from '../services/utils.service';
import { BSVersionLibService } from '../services/bs-version-lib.service'
import { BSVersion } from 'shared/bs-version.interface';
@@ -38,7 +38,9 @@ ipcMain.on('bs-version.installed-versions', async (event, req: IpcRequest<void>)
ipcMain.on("bs-version.open-folder", async (event, req: IpcRequest<BSVersion>) => {
const localVersionService = BSLocalVersionService.getInstance();
const versionFolder = await localVersionService.getVersionPath(req.args);
(await pathExist(versionFolder)) && exec(`start "" "${versionFolder}"`);
if (!(await pathExist(versionFolder)))
return;
shell.openPath(versionFolder);
});
ipcMain.on("bs-version.edit", async (event, req: IpcRequest<{version: BSVersion, name: string, color: string}>) => {
+1 -1
View File
@@ -46,7 +46,7 @@ const installExtensions = async () => {
const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
const extensions = ['REACT_DEVELOPER_TOOLS'];
return installer.default(extensions.map((name) => installer[name]), forceDownload).catch(console.log);
return installer.default(extensions.map((name) => installer[name]), forceDownload).catch(console.error);
};
const createWindow = async (window: AppWindow = "launcher.html") => {
+6 -3
View File
@@ -66,9 +66,12 @@ export class BSInstallerService{
return new Promise(resolve => {
if(this.downloadProcess?.killed && !this.downloadProcess?.pid){ return resolve(false); }
this.downloadProcess.once('exit', () => resolve(true));
ctrlc(this.downloadProcess.pid);
this.downloadProcess?.once('exit', () => resolve(true));
if (process.platform === 'win32') {
ctrlc(this.downloadProcess.pid);
} else {
this.downloadProcess.kill();
}
setTimeout(() => resolve(false), 3000);
});
}
+6 -6
View File
@@ -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: LaunchOption): 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){
@@ -167,7 +167,7 @@ export class BSLauncherService{
return obs.error({type: BSLaunchErrorType.BS_ALREADY_RUNNING} as BSLaunchErrorEvent);
}
if(launchOptions.version.oculus && this.oculusService.oculusRunning() === false){
if(launchOptions.version.oculus && (await this.oculusService.oculusRunning()) === false){
return obs.error({type: BSLaunchErrorType.OCULUS_NOT_RUNNING} as BSLaunchErrorEvent);
}
@@ -214,4 +214,4 @@ export class BSLauncherService{
}
}
}
+2 -2
View File
@@ -20,7 +20,7 @@ export class OculusService {
this.utils = UtilsService.getInstance();
}
public oculusRunning(): boolean | null{
public async oculusRunning(): Promise<boolean> {
return this.utils.taskRunning("OculusClient.exe");
}
@@ -64,4 +64,4 @@ export class OculusService {
return null;
}
}
}
+29 -20
View File
@@ -6,6 +6,8 @@ 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{
@@ -25,40 +27,47 @@ 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>{
if(!!this.steamPath){ return this.steamPath; }
if(this.steamPath){ return this.steamPath; }
switch (process.platform) {
case "linux":
this.steamPath = path.join(app.getPath('home'), '.steam', "steam");
return this.steamPath;
case "win32":
const [win32Res, win64Res] = await Promise.all([
regedit.promisified.list(['HKLM\\SOFTWARE\\Valve\\Steam']),
regedit.promisified.list(['HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam'])
regedit.promisified.list(['HKLM\\SOFTWARE\\Valve\\Steam']),
regedit.promisified.list(['HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam'])
]);
const [win32, win64] = [win32Res["HKLM\\SOFTWARE\\Valve\\Steam"], win64Res["HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam"]];
let res = '';
if(win64.exists && win64?.values?.InstallPath?.value){ res = win64.values.InstallPath.value as string; }
else if(win32.exists && win32?.values?.InstallPath?.value){ res = win32.values.InstallPath.value as string; }
this.steamPath = res;
return this.steamPath;
return res;
default:
return null;
}
}
public async getGameFolder(gameId: string, gameFolder?: string): Promise<string>{
try{
@@ -88,7 +97,7 @@ export class SteamService{
const process = spawn("start", ["steam://open/games"], {shell: true});
process.on("error", log.error);
return new Promise(async (resolve, reject) => {
// Every 3 seconds check if steam is running
const interval = setInterval(async () => {
+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);