add button to lunch steam when steam is not running

This commit is contained in:
MathieuG-P
2022-12-28 20:30:10 +01:00
parent a8ca0b26b3
commit 06622c4088
6 changed files with 63 additions and 1 deletions
+11
View File
@@ -3,6 +3,7 @@ import { UtilsService } from '../services/utils.service';
import { IpcRequest } from 'shared/models/ipc';
import { SystemNotificationOptions } from 'shared/models/notification/system-notification.model';
import { NotificationService } from '../services/notification.service';
import { SteamService } from '../services/steam.service';
// TODO IMPROVE WINDOW CONTROL BY USING WINDOW SERVICE
@@ -60,4 +61,14 @@ ipcMain.on("open-logs", async (event, request: IpcRequest<void>) => {
ipcMain.on("notify-system", async (event, request: IpcRequest<SystemNotificationOptions>) => {
NotificationService.getInstance().notify(request.args)
});
ipcMain.on("open-steam", async (event, request: IpcRequest<void>) => {
const steam = SteamService.getInstance();
const utils = UtilsService.getInstance();
steam.openSteam().then(res => {
utils.ipcSend(request.responceChannel, {success: true, data: res});
}).catch((e) => {
utils.ipcSend(request.responceChannel, {success: false, error: e});
});
});
+10
View File
@@ -3,6 +3,7 @@ import regedit from 'regedit'
import path from "path";
import { parse } from "@node-steam/vdf";
import { readFile } from "fs/promises";
import { spawn } from "child_process";
export class SteamService{
@@ -62,4 +63,13 @@ export class SteamService{
return null;
}
public openSteam(): Promise<boolean>{
const process = spawn("start", ["steam://open/games"], {shell: true});
return new Promise(resolve => {
process.on("exit", () => resolve(true));
process.on("error", () => resolve(false));
});
}
}
+15 -1
View File
@@ -58,7 +58,21 @@ export class BSLauncherService{
return res;
});
}
if(res.data){ return this.notificationService.notifyError({title: `notifications.bs-launch.errors.titles.${res.data}`}); }
if(res.data){
// TODO : too much nesting here, need refactor
if(res.data === "STEAM_NOT_RUNNING"){
return new Promise(async resolve => {
const notif = await this.notificationService.notifyError({title: `notifications.bs-launch.errors.titles.${res.data}`, actions: [{id: "0", title: `notifications.bs-launch.errors.actions.${res.data}`}]});
if(notif === "0"){
await this.ipcService.send<boolean>("open-steam");
const lastNotif = await this.notificationService.notifySuccess({title: "notifications.steam.steam-launching.title", desc: "notifications.steam.steam-launching.description"});
resolve(lastNotif);
}
resolve(notif)
})
}
return this.notificationService.notifyError({title: `notifications.bs-launch.errors.titles.${res.data}`});
}
return this.notificationService.notifyError({title: res.data || res.error.title});
});
}