Add an Apply button to the Web UI when running as a Win32 Service (#700)
This commit is contained in:
@@ -494,6 +494,7 @@ void getConfig(resp_https_t response, req_https_t request) {
|
||||
|
||||
outputTree.put("status", "true");
|
||||
outputTree.put("platform", SUNSHINE_PLATFORM);
|
||||
outputTree.put("restart_supported", platf::restart_supported());
|
||||
|
||||
auto vars = config::parse_config(read_file(config::sunshine.config_file.c_str()));
|
||||
|
||||
@@ -537,6 +538,37 @@ void saveConfig(resp_https_t response, req_https_t request) {
|
||||
}
|
||||
}
|
||||
|
||||
void restart(resp_https_t response, req_https_t request) {
|
||||
if(!authenticate(response, request)) return;
|
||||
|
||||
print_req(request);
|
||||
|
||||
std::stringstream ss;
|
||||
std::stringstream configStream;
|
||||
ss << request->content.rdbuf();
|
||||
pt::ptree outputTree;
|
||||
auto g = util::fail_guard([&]() {
|
||||
std::ostringstream data;
|
||||
|
||||
pt::write_json(data, outputTree);
|
||||
response->write(data.str());
|
||||
});
|
||||
|
||||
if(!platf::restart_supported()) {
|
||||
outputTree.put("status", false);
|
||||
outputTree.put("error", "Restart is not currently supported on this platform");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!platf::restart()) {
|
||||
outputTree.put("status", false);
|
||||
outputTree.put("error", "Restart failed");
|
||||
return;
|
||||
}
|
||||
|
||||
outputTree.put("status", true);
|
||||
}
|
||||
|
||||
void savePassword(resp_https_t response, req_https_t request) {
|
||||
if(!config::sunshine.username.empty() && !authenticate(response, request)) return;
|
||||
|
||||
@@ -678,6 +710,7 @@ void start() {
|
||||
server.resource["^/api/apps$"]["POST"] = saveApp;
|
||||
server.resource["^/api/config$"]["GET"] = getConfig;
|
||||
server.resource["^/api/config$"]["POST"] = saveConfig;
|
||||
server.resource["^/api/restart$"]["POST"] = restart;
|
||||
server.resource["^/api/password$"]["POST"] = savePassword;
|
||||
server.resource["^/api/apps/([0-9]+)$"]["DELETE"] = deleteApp;
|
||||
server.resource["^/api/clients/unpair$"]["POST"] = unpairAll;
|
||||
|
||||
@@ -318,6 +318,9 @@ void adjust_thread_priority(thread_priority_e priority);
|
||||
void streaming_will_start();
|
||||
void streaming_will_stop();
|
||||
|
||||
bool restart_supported();
|
||||
bool restart();
|
||||
|
||||
input_t input();
|
||||
void move_mouse(input_t &input, int deltaX, int deltaY);
|
||||
void abs_mouse(input_t &input, const touch_port_t &touch_port, float x, float y);
|
||||
|
||||
@@ -165,6 +165,16 @@ void streaming_will_stop() {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
bool restart_supported() {
|
||||
// Restart not supported yet
|
||||
return false;
|
||||
}
|
||||
|
||||
bool restart() {
|
||||
// Restart not supported yet
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace source {
|
||||
enum source_e : std::size_t {
|
||||
#ifdef SUNSHINE_BUILD_CUDA
|
||||
|
||||
@@ -143,6 +143,16 @@ void streaming_will_stop() {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
bool restart_supported() {
|
||||
// Restart not supported yet
|
||||
return false;
|
||||
}
|
||||
|
||||
bool restart() {
|
||||
// Restart not supported yet
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace platf
|
||||
|
||||
namespace dyn {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <csignal>
|
||||
#include <filesystem>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
@@ -522,4 +523,16 @@ void streaming_will_stop() {
|
||||
DwmEnableMMCSS(false);
|
||||
}
|
||||
|
||||
bool restart_supported() {
|
||||
// Restart is supported if we're running from the service
|
||||
return (GetConsoleWindow() == NULL);
|
||||
}
|
||||
|
||||
bool restart() {
|
||||
// Raise SIGINT to trigger the graceful exit logic. The service will
|
||||
// restart us in a few seconds.
|
||||
std::raise(SIGINT);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace platf
|
||||
Reference in New Issue
Block a user