diff --git a/GlosSIWatchdog/dllmain.cpp b/GlosSIWatchdog/dllmain.cpp index f9fac98..3e05df5 100644 --- a/GlosSIWatchdog/dllmain.cpp +++ b/GlosSIWatchdog/dllmain.cpp @@ -32,8 +32,6 @@ limitations under the License. #include "../common/Settings.h" #include "../common/HidHide.h" -#include - bool IsProcessRunning(DWORD pid) { const HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, pid); @@ -119,10 +117,6 @@ DWORD WINAPI watchdog(HMODULE hModule) HidHide hidhide; hidhide.disableHidHide(); - spdlog::info("Uninstalling GlosSITweaks"); - auto steam_tweaks = CEFInject::SteamTweaks(); - steam_tweaks.uninstallTweaks(true); - if (Settings::launch.closeOnExit) { spdlog::info("Closing launched processes"); diff --git a/SteamTweaks/src/GlosSITweaks.ts b/SteamTweaks/src/GlosSITweaks.ts index ea0cf35..dc86ca7 100644 --- a/SteamTweaks/src/GlosSITweaks.ts +++ b/SteamTweaks/src/GlosSITweaks.ts @@ -4,11 +4,40 @@ import type { GlosSISettings } from './@types/GlosSISettings'; class SteamTargetApi { - public getGlosSIActive() { - return fetchWithTimeout('http://localhost:8756/', { timeout: 500 }) + + public static GlosSIActive = true; + + public static readonly ACTIVE_FAIL_THRESHOLD = 2; + private activeFailCounter = 0; + private static ActiveCheckTimer = 0; + + public constructor() { + if (SteamTargetApi.ActiveCheckTimer !== 0) { + clearInterval(SteamTargetApi.ActiveCheckTimer); + } + SteamTargetApi.ActiveCheckTimer = setInterval(() => { + void this.getGlosSIActive().then((active) => { + if (!active) { + this.activeFailCounter++; + if (this.activeFailCounter >= SteamTargetApi.ACTIVE_FAIL_THRESHOLD) { + window?.GlosSITweaks?.GlosSI?.uninstall?.(); + } + } + }); + }, 666); + } + + public async getGlosSIActive() { + return fetchWithTimeout('http://localhost:8756/running', { timeout: 500 }) .then( - () => true - ).catch(() => false); + () => { + SteamTargetApi.GlosSIActive = true; + return true; + } + ).catch(() => { + SteamTargetApi.GlosSIActive = false; + return false; + }); } public getSteamSettings(): Promise { return fetch('http://localhost:8756/steam_settings') @@ -33,6 +62,7 @@ class SteamTargetApi { class GlosSIApiCtor { public readonly SteamTarget: SteamTargetApi = new SteamTargetApi(); + } interface GlosSITweaks { @@ -51,7 +81,6 @@ declare global { const GlosSITweaks: GlosSITweaks; } - const installGlosSIApi = () => { window.GlosSITweaks = { GlosSI: {