GlosSITarget: Close existing target on launch

pull/212/head
Peter Repukat 2 years ago
parent be8e206683
commit 85ab663804

@ -21,7 +21,7 @@ limitations under the License.
#include "AppLauncher.h" #include "AppLauncher.h"
#include "Settings.h" #include "Settings.h"
HttpServer::HttpServer(AppLauncher& app_launcher) : app_launcher_(app_launcher) HttpServer::HttpServer(AppLauncher& app_launcher, std::function<void()> close) : app_launcher_(app_launcher), close_(close)
{ {
} }
@ -62,6 +62,10 @@ void HttpServer::run()
res.set_content(j.dump(), "text/json"); 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) { server_.Get("/settings", [this](const httplib::Request& req, httplib::Response& res) {
res.set_content(Settings::toJson().dump(), "text/json"); res.set_content(Settings::toJson().dump(), "text/json");
}); });

@ -23,7 +23,7 @@ class AppLauncher;
class HttpServer { class HttpServer {
public: public:
explicit HttpServer(AppLauncher& app_launcher); explicit HttpServer(AppLauncher& app_launcher, std::function<void()> close);
void run(); void run();
void stop(); void stop();
@ -34,4 +34,5 @@ class HttpServer {
uint16_t port_ = 8756; uint16_t port_ = 8756;
AppLauncher& app_launcher_; AppLauncher& app_launcher_;
std::function<void()> close_;
}; };

@ -46,7 +46,7 @@ SteamTarget::SteamTarget()
delayed_shutdown_ = true; delayed_shutdown_ = true;
delay_shutdown_clock_.restart(); delay_shutdown_clock_.restart();
}), }),
server_(launcher_) server_(launcher_, [this] { run_ = false; })
{ {
target_window_handle_ = window_.getSystemHandle(); target_window_handle_ = window_.getSystemHandle();
#ifdef _WIN32 #ifdef _WIN32

@ -168,8 +168,9 @@ int main(int argc, char* argv[])
auto existingwindow = FindWindowA(nullptr, "GlosSITarget"); auto existingwindow = FindWindowA(nullptr, "GlosSITarget");
if (existingwindow) { if (existingwindow) {
spdlog::error("GlosSITarget is already running!"); spdlog::error("GlosSITarget is already running! Closing old process...");
return 1; httplib::Client client("http://localhost:8756");
client.Post("/quit");
} }
int numArgs; int numArgs;

Loading…
Cancel
Save