From 85ab6638042523ea7ffc17ce5acf0c13815ec65d Mon Sep 17 00:00:00 2001 From: Peter Repukat Date: Wed, 16 Nov 2022 21:28:58 +0100 Subject: [PATCH] GlosSITarget: Close existing target on launch --- GlosSITarget/HttpServer.cpp | 6 +++++- GlosSITarget/HttpServer.h | 3 ++- GlosSITarget/SteamTarget.cpp | 2 +- GlosSITarget/main.cpp | 5 +++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/GlosSITarget/HttpServer.cpp b/GlosSITarget/HttpServer.cpp index c3acd0d..a475cde 100644 --- a/GlosSITarget/HttpServer.cpp +++ b/GlosSITarget/HttpServer.cpp @@ -21,7 +21,7 @@ limitations under the License. #include "AppLauncher.h" #include "Settings.h" -HttpServer::HttpServer(AppLauncher& app_launcher) : app_launcher_(app_launcher) +HttpServer::HttpServer(AppLauncher& app_launcher, std::function close) : app_launcher_(app_launcher), close_(close) { } @@ -62,6 +62,10 @@ void HttpServer::run() res.set_content(j.dump(), "text/json"); }); + server_.Post("/quit", [this](const httplib::Request& req, httplib::Response& res) { + close_(); + }); + server_.Get("/settings", [this](const httplib::Request& req, httplib::Response& res) { res.set_content(Settings::toJson().dump(), "text/json"); }); diff --git a/GlosSITarget/HttpServer.h b/GlosSITarget/HttpServer.h index b23bff5..5541dfd 100644 --- a/GlosSITarget/HttpServer.h +++ b/GlosSITarget/HttpServer.h @@ -23,7 +23,7 @@ class AppLauncher; class HttpServer { public: - explicit HttpServer(AppLauncher& app_launcher); + explicit HttpServer(AppLauncher& app_launcher, std::function close); void run(); void stop(); @@ -34,4 +34,5 @@ class HttpServer { uint16_t port_ = 8756; AppLauncher& app_launcher_; + std::function close_; }; \ No newline at end of file diff --git a/GlosSITarget/SteamTarget.cpp b/GlosSITarget/SteamTarget.cpp index fc3c357..5916152 100644 --- a/GlosSITarget/SteamTarget.cpp +++ b/GlosSITarget/SteamTarget.cpp @@ -46,7 +46,7 @@ SteamTarget::SteamTarget() delayed_shutdown_ = true; delay_shutdown_clock_.restart(); }), - server_(launcher_) + server_(launcher_, [this] { run_ = false; }) { target_window_handle_ = window_.getSystemHandle(); #ifdef _WIN32 diff --git a/GlosSITarget/main.cpp b/GlosSITarget/main.cpp index 65bbc06..7c0a7d5 100644 --- a/GlosSITarget/main.cpp +++ b/GlosSITarget/main.cpp @@ -168,8 +168,9 @@ int main(int argc, char* argv[]) auto existingwindow = FindWindowA(nullptr, "GlosSITarget"); if (existingwindow) { - spdlog::error("GlosSITarget is already running!"); - return 1; + spdlog::error("GlosSITarget is already running! Closing old process..."); + httplib::Client client("http://localhost:8756"); + client.Post("/quit"); } int numArgs;