From 21ec167dacc9d4537f7ebfed257e93e6889c4f76 Mon Sep 17 00:00:00 2001 From: Yundi339 Date: Tue, 3 Feb 2026 09:20:17 +0800 Subject: [PATCH 1/2] fix: refresh() made empty env --- src/process.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/process.cpp b/src/process.cpp index 95c7bdaeaa5..d29f91146d0 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -154,6 +154,8 @@ namespace proc { _app_prep_it = _app_prep_begin; // Add Stream-specific environment variables + // These variables are dynamically set for each streaming session and will be passed + // to the launched application. They should be preserved during refresh() if an app is running. _env["SUNSHINE_APP_ID"] = std::to_string(_app_id); _env["SUNSHINE_APP_NAME"] = _app.name; _env["SUNSHINE_CLIENT_WIDTH"] = std::to_string(launch_session->width); @@ -752,7 +754,28 @@ namespace proc { auto proc_opt = proc::parse(file_name); if (proc_opt) { - proc = std::move(*proc_opt); + // If it is running, the environment variable (SUNSHINE_*) should be kept. + // These variables are dynamically added in execute() and should not be + // overridden by environment variables in the configuration file + if (proc.running()) { + const boost::process::v1::environment ¤t_env = proc.get_env(); + boost::process::v1::environment new_env = proc_opt->get_env(); + + // Copy the 'SUNSHINE_*' from the current environment into the new environment. + for (const auto &entry : current_env) { + const std::string &var_name = entry.get_name(); + if (var_name.find("SUNSHINE_") == 0) { + new_env[var_name] = entry.to_string(); + } + } + + proc.set_env(std::move(new_env)); + } + else { + // Not a running state, which can safely replace environment variables + proc.set_env(proc_opt->get_env()); + } + proc.set_apps(proc_opt->get_apps()); } } } // namespace proc From dd468582d2ae7b0734c54ff09291684f0bf4b356 Mon Sep 17 00:00:00 2001 From: Yundi339 Date: Tue, 3 Feb 2026 09:37:57 +0800 Subject: [PATCH 2/2] fix: refresh() made empty env --- src/process.cpp | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/process.cpp b/src/process.cpp index d29f91146d0..cf8bf325e6c 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -753,29 +753,30 @@ namespace proc { void refresh(const std::string &file_name) { auto proc_opt = proc::parse(file_name); - if (proc_opt) { - // If it is running, the environment variable (SUNSHINE_*) should be kept. - // These variables are dynamically added in execute() and should not be - // overridden by environment variables in the configuration file - if (proc.running()) { - const boost::process::v1::environment ¤t_env = proc.get_env(); - boost::process::v1::environment new_env = proc_opt->get_env(); - - // Copy the 'SUNSHINE_*' from the current environment into the new environment. - for (const auto &entry : current_env) { - const std::string &var_name = entry.get_name(); - if (var_name.find("SUNSHINE_") == 0) { - new_env[var_name] = entry.to_string(); - } + if (!proc_opt) { + return; + } + // If it is running, the environment variable (SUNSHINE_*) should be kept. + // These variables are dynamically added in execute() and should not be + // overridden by environment variables in the configuration file + if (proc.running()) { + const boost::process::v1::environment ¤t_env = proc.get_env(); + boost::process::v1::environment new_env = proc_opt->get_env(); + + // Copy the 'SUNSHINE_*' from the current environment into the new environment. + for (const auto &entry : current_env) { + const std::string &var_name = entry.get_name(); + if (var_name.find("SUNSHINE_") == 0) { + new_env[var_name] = entry.to_string(); } - - proc.set_env(std::move(new_env)); - } - else { - // Not a running state, which can safely replace environment variables - proc.set_env(proc_opt->get_env()); } - proc.set_apps(proc_opt->get_apps()); + + proc.set_env(std::move(new_env)); + } + else { + // Not a running state, which can safely replace environment variables + proc.set_env(proc_opt->get_env()); } + proc.set_apps(proc_opt->get_apps()); } } // namespace proc