From 06622c408842e2f10dd5e109a9e070fafa6d816b Mon Sep 17 00:00:00 2001 From: MathieuG-P Date: Wed, 28 Dec 2022 20:30:10 +0100 Subject: [PATCH] add button to lunch steam when steam is not running --- assets/jsons/translations/en.json | 9 +++++++++ assets/jsons/translations/es.json | 9 +++++++++ assets/jsons/translations/fr.json | 9 +++++++++ src/main/ipcs/os-controls-ipcs.ts | 11 +++++++++++ src/main/services/steam.service.ts | 10 ++++++++++ src/renderer/services/bs-launcher.service.ts | 16 +++++++++++++++- 6 files changed, 63 insertions(+), 1 deletion(-) diff --git a/assets/jsons/translations/en.json b/assets/jsons/translations/en.json index 49f4f819..fa86f981 100644 --- a/assets/jsons/translations/en.json +++ b/assets/jsons/translations/en.json @@ -274,9 +274,18 @@ "BS_ALREADY_RUNNING": "Close BeatSaber before launching it again.", "EXE_NOT_FINDED": "Some files seem to be missing, try to verify the files.", "EXIT": "BeatSaber stopped abruptly, tries to check the files." + }, + "actions":{ + "STEAM_NOT_RUNNING": "Launch Steam" } } }, + "steam":{ + "steam-launching":{ + "title": "Steam is launching!", + "description": "Steam may take some time to launch depending on your configuration." + } + }, "custom-version": { "errors": { "titles": { diff --git a/assets/jsons/translations/es.json b/assets/jsons/translations/es.json index 36461021..579b8f1f 100644 --- a/assets/jsons/translations/es.json +++ b/assets/jsons/translations/es.json @@ -274,9 +274,18 @@ "BS_ALREADY_RUNNING": "Cierra BeatSaber antes de volver a lanzarlo.", "EXE_NOT_FINDED": "Parece que faltan algunos archivos, intente verificar los archivos.", "EXIT": "BeatSaber se detuvo abruptamente, trata de revisar los archivos." + }, + "actions":{ + "STEAM_NOT_RUNNING": "Iniciar Steam" } } }, + "steam":{ + "steam-launching":{ + "title": "¡Steam se está iniciando!", + "description": "Steam puede tardar un poco en iniciarse dependiendo de tu configuración." + } + }, "custom-version": { "errors": { "titles": { diff --git a/assets/jsons/translations/fr.json b/assets/jsons/translations/fr.json index be12fd3f..cf25d0fd 100644 --- a/assets/jsons/translations/fr.json +++ b/assets/jsons/translations/fr.json @@ -274,9 +274,18 @@ "BS_ALREADY_RUNNING": "Ferme BeatSaber avant de le lancer à nouveau.", "EXE_NOT_FINDED": "Quelques fichiers semblent manquants. Essaye de vérifier les fichiers.", "EXIT": "BeatSaber s'est arrêté brusquement, essaye de vérifier les fichiers." + }, + "actions":{ + "STEAM_NOT_RUNNING": "Lancer Steam" } } }, + "steam":{ + "steam-launching":{ + "title": "Steam se lance !", + "description": "Steam peut mettre quelque temps à se lancer selon votre configuration." + } + }, "custom-version": { "errors": { "titles": { diff --git a/src/main/ipcs/os-controls-ipcs.ts b/src/main/ipcs/os-controls-ipcs.ts index ba4d919e..aaec73c8 100644 --- a/src/main/ipcs/os-controls-ipcs.ts +++ b/src/main/ipcs/os-controls-ipcs.ts @@ -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) => { ipcMain.on("notify-system", async (event, request: IpcRequest) => { NotificationService.getInstance().notify(request.args) +}); + +ipcMain.on("open-steam", async (event, request: IpcRequest) => { + 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}); + }); }); \ No newline at end of file diff --git a/src/main/services/steam.service.ts b/src/main/services/steam.service.ts index c880f97b..622d175d 100644 --- a/src/main/services/steam.service.ts +++ b/src/main/services/steam.service.ts @@ -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{ + const process = spawn("start", ["steam://open/games"], {shell: true}); + + return new Promise(resolve => { + process.on("exit", () => resolve(true)); + process.on("error", () => resolve(false)); + }); + } + } diff --git a/src/renderer/services/bs-launcher.service.ts b/src/renderer/services/bs-launcher.service.ts index 0419f1e6..8aa32060 100644 --- a/src/renderer/services/bs-launcher.service.ts +++ b/src/renderer/services/bs-launcher.service.ts @@ -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("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}); }); }