From d316b272dac6ef67222ec151813094906506e8e9 Mon Sep 17 00:00:00 2001 From: Yukino Song Date: Wed, 4 Jun 2025 19:02:10 +0800 Subject: [PATCH] Add terminate on pause option for apps (resolves #801) --- src/process.cpp | 15 +++++++++++++++ src/process.h | 2 ++ src/stream.cpp | 4 +--- src_assets/common/assets/web/apps.html | 9 +++++++++ .../assets/web/public/assets/locale/en.json | 2 ++ .../assets/web/public/assets/locale/zh.json | 2 ++ 6 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/process.cpp b/src/process.cpp index 471b77af..0bd3cb52 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -593,6 +593,16 @@ namespace proc { return 0; } + void proc_t::pause() { + if (_app.terminate_on_pause) { + terminate(); + } else { +#if defined SUNSHINE_TRAY && SUNSHINE_TRAY >= 1 + system_tray::update_tray_pausing(proc::proc.get_last_run_app_name()); +#endif + } + } + void proc_t::terminate(bool immediate, bool needs_refresh) { std::error_code ec; placebo = false; @@ -1219,6 +1229,7 @@ namespace proc { ctx.use_app_identity = app_node.value("use-app-identity", false); ctx.per_client_app_identity = app_node.value("per-client-app-identity", false); ctx.allow_client_commands = app_node.value("allow-client-commands", true); + ctx.terminate_on_pause = app_node.value("terminate-on-pause", false); ctx.gamepad = app_node.value("gamepad", ""); // Calculate a unique application id. @@ -1284,6 +1295,7 @@ namespace proc { ctx.use_app_identity = false; ctx.per_client_app_identity = false; ctx.allow_client_commands = false; + ctx.terminate_on_pause = false; ctx.elevated = false; ctx.auto_detach = true; @@ -1317,6 +1329,7 @@ namespace proc { ctx.use_app_identity = false; ctx.per_client_app_identity = false; ctx.allow_client_commands = false; + ctx.terminate_on_pause = false; ctx.elevated = false; ctx.auto_detach = true; @@ -1351,6 +1364,7 @@ namespace proc { ctx.use_app_identity = false; ctx.per_client_app_identity = false; ctx.allow_client_commands = false; + ctx.terminate_on_pause = false; ctx.elevated = false; ctx.auto_detach = true; @@ -1386,6 +1400,7 @@ namespace proc { ctx.use_app_identity = false; ctx.per_client_app_identity = false; ctx.allow_client_commands = false; + ctx.terminate_on_pause = false; ctx.elevated = false; ctx.auto_detach = true; diff --git a/src/process.h b/src/process.h index 46af8be3..2c7494ff 100644 --- a/src/process.h +++ b/src/process.h @@ -94,6 +94,7 @@ namespace proc { bool use_app_identity; bool per_client_app_identity; bool allow_client_commands; + bool terminate_on_pause; int scale_factor; std::chrono::seconds exit_timeout; }; @@ -135,6 +136,7 @@ namespace proc { std::string get_last_run_app_name(); std::string get_running_app_uuid(); boost::process::v1::environment get_env(); + void pause(); void terminate(bool immediate = false, bool needs_refresh = true); private: diff --git a/src/stream.cpp b/src/stream.cpp index 4031dd76..34047e1f 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -2070,9 +2070,7 @@ namespace stream { if (--running_sessions == 0) { bool revert_display_config {config::video.dd.config_revert_on_disconnect}; if (proc::proc.running()) { -#if defined SUNSHINE_TRAY && SUNSHINE_TRAY >= 1 - system_tray::update_tray_pausing(proc::proc.get_last_run_app_name()); -#endif + proc::proc.pause(); } else { // We have no app running and also no clients anymore. revert_display_config = true; diff --git a/src_assets/common/assets/web/apps.html b/src_assets/common/assets/web/apps.html index 40353e69..3f50c2b7 100644 --- a/src_assets/common/assets/web/apps.html +++ b/src_assets/common/assets/web/apps.html @@ -324,6 +324,14 @@ v-model="editForm['wait-all']" default="true" > + +
@@ -503,6 +511,7 @@ "per-client-app-identity": false, "allow-client-commands": true, "virtual-display": false, + "terminate-on-pause": false, "gamepad": "" } diff --git a/src_assets/common/assets/web/public/assets/locale/en.json b/src_assets/common/assets/web/public/assets/locale/en.json index 40e1329d..3f1e8348 100644 --- a/src_assets/common/assets/web/public/assets/locale/en.json +++ b/src_assets/common/assets/web/public/assets/locale/en.json @@ -105,6 +105,8 @@ "run_as_desc": "This can be necessary for some applications that require administrator permissions to run properly. Might cause URL schemes to fail.", "save_failed": "Failed to save app: ", "save_order": "Save Order", + "terminate_on_pause": "Terminate on Pause", + "terminate_on_pause_desc": "Terminate the app when all clients are disconnected.", "use_app_identity": "Use App Identity", "use_app_identity_desc": "Use the app's own identity while creating virtual displays instead of client's. This is useful when you want display configuration for each APP separately.", "virtual_display": "Always use Virtual Display", diff --git a/src_assets/common/assets/web/public/assets/locale/zh.json b/src_assets/common/assets/web/public/assets/locale/zh.json index 94bf62ff..f6f64c11 100644 --- a/src_assets/common/assets/web/public/assets/locale/zh.json +++ b/src_assets/common/assets/web/public/assets/locale/zh.json @@ -106,6 +106,8 @@ "run_as_desc": "这可能是某些需要管理员权限才能正常运行的应用程序所必需的。可能会导致 URL schemes 无法正常启动。", "save_failed": "保存APP失败:", "save_order": "保存排序", + "terminate_on_pause": "暂停时终止", + "terminate_on_pause_desc": "当所有客户端断开连接时终止此 APP。", "use_app_identity": "使用 App 身份", "use_app_identity_desc": "在创建虚拟显示器时使用 App 自身的身份,而非客户端的。这样可以针对 APP 进行单独的显示器组合配置。", "virtual_display": "总是使用虚拟显示器",