From 45e52e1daa5fae91d4b99c051b7071c2303fb848 Mon Sep 17 00:00:00 2001 From: Jeffrey Farb <3586012+lexarvn@users.noreply.github.com> Date: Tue, 13 May 2025 00:11:02 -0700 Subject: [PATCH] Add in powershell script that will auto close epic when the launched game closes - Start a model for epic games manifests --- files/shellscripts/EpicGamesLauncher.ps1 | 26 ++++++++++++++++++++++++ src/lib/parsers/epic.parser.ts | 10 ++++++--- src/models/epic.model.ts | 8 ++++++++ src/models/index.ts | 1 + 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 files/shellscripts/EpicGamesLauncher.ps1 create mode 100644 src/models/epic.model.ts diff --git a/files/shellscripts/EpicGamesLauncher.ps1 b/files/shellscripts/EpicGamesLauncher.ps1 new file mode 100644 index 0000000000..477f83e404 --- /dev/null +++ b/files/shellscripts/EpicGamesLauncher.ps1 @@ -0,0 +1,26 @@ +Param( + [Parameter(Mandatory=$true)] + $gameURI, + [Parameter(Mandatory=$true)] + $gameProcessName +) + + +# Start the game via Epic Games Launcher +Start-Process $gameURI + +# Wait for the game to start +while (-not (Get-Process -Name $gameProcessName -ErrorAction SilentlyContinue)) { + Start-Sleep -Seconds 5 +} + +# Wait for the game to exit +while (Get-Process -Name $gameProcessName -ErrorAction SilentlyContinue) { + Start-Sleep -Seconds 5 +} + +# Give Epic Games Launcher a few seconds before closing +Start-Sleep -Seconds 10 + +# Close Epic Games Launcher +Stop-Process -Name "EpicGamesLauncher" -Force -ErrorAction SilentlyContinue \ No newline at end of file diff --git a/src/lib/parsers/epic.parser.ts b/src/lib/parsers/epic.parser.ts index d4488e74ba..0dfb808f6f 100644 --- a/src/lib/parsers/epic.parser.ts +++ b/src/lib/parsers/epic.parser.ts @@ -1,10 +1,11 @@ -import { ParserInfo, GenericParser, ParsedData } from "../../models"; +import { ParserInfo, GenericParser, ParsedData, EpicGameManifest } from "../../models"; import { APP } from "../../variables"; import * as _ from "lodash"; import * as fs from "fs-extra"; import * as os from "os"; import * as path from "path"; import { glob } from "glob"; +import * as paths from "../../paths"; export class EpicParser implements GenericParser { private get lang() { @@ -65,9 +66,10 @@ export class EpicParser implements GenericParser { const files: string[] = await glob( [epicManifestsDir.replace(/\\/g, "/"), "*.item"].join("/"), ); + const scriptsPath = path.join(paths.userDataDir, "scripts"); for (let file of files) { if (fs.existsSync(file) && fs.lstatSync(file).isFile()) { - let item = JSON.parse(fs.readFileSync(file).toString()); + let item: EpicGameManifest = JSON.parse(fs.readFileSync(file).toString()); let launchPath = path.join( item.InstallLocation, item.LaunchExecutable, @@ -77,11 +79,13 @@ export class EpicParser implements GenericParser { fs.existsSync(launchPath) && !appTitles.includes(item.DisplayName) ) { + const processName = item.LaunchExecutable.replace(/\.exe$/i, ""); appTitles.push(item.DisplayName); parsedData.success.push({ extractedTitle: item.DisplayName, extractedAppId: item.AppName, - launchOptions: `-windowStyle hidden -NoProfile -ExecutionPolicy Bypass -Command "&Start-Process \\"com.epicgames.launcher://apps/${item.AppName}?action=launch&silent=true\\""`, + startInDirectory: scriptsPath, + launchOptions: `-windowStyle hidden -NoProfile -ExecutionPolicy Bypass -File .\\EpicGamesLauncher.ps1 -gameURI "com.epicgames.launcher://apps/${item.AppName}?action=launch&silent=true" -gameProcessName "${processName}"`, filePath: launchPath, fileLaunchOptions: item.LaunchCommand, }); diff --git a/src/models/epic.model.ts b/src/models/epic.model.ts new file mode 100644 index 0000000000..8f2018eaf2 --- /dev/null +++ b/src/models/epic.model.ts @@ -0,0 +1,8 @@ +// game json manifest +export interface EpicGameManifest { + InstallLocation: string; + LaunchExecutable: string; + DisplayName: string; + AppName: string; + LaunchCommand: string; +} diff --git a/src/models/index.ts b/src/models/index.ts index 6c676047e8..c1343c8536 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -20,3 +20,4 @@ export * from "./user-exceptions.model"; export * from "./config-presets.model"; export * from "./error.model"; export * from "./uwp.model"; +export * from "./epic.model";