From 58bbfc3e67a798824809d362f3728ea87dfcd65f Mon Sep 17 00:00:00 2001 From: Yukino Song Date: Fri, 7 Feb 2025 21:11:03 +0800 Subject: [PATCH] Show running app in Apps page --- src/confighttp.cpp | 2 + src/process.cpp | 5 ++ src/process.h | 1 + src_assets/common/assets/web/apps.html | 47 ++++++++++++++----- .../assets/web/public/assets/locale/en.json | 4 +- .../assets/web/public/assets/locale/zh.json | 3 ++ 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/confighttp.cpp b/src/confighttp.cpp index eced778f..4a68eb4b 100644 --- a/src/confighttp.cpp +++ b/src/confighttp.cpp @@ -552,6 +552,8 @@ namespace confighttp { } } + file_tree["current_app"] = proc::proc.get_running_app_uuid(); + send_response(response, file_tree); } catch (std::exception &e) { BOOST_LOG(warning) << "GetApps: "sv << e.what(); diff --git a/src/process.cpp b/src/process.cpp index 93ca6ed4..326259e1 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -604,6 +604,7 @@ namespace proc { _app_id = -1; _app_name.clear(); + _app = {}; display_name.clear(); initial_display.clear(); _launch_session.reset(); @@ -636,6 +637,10 @@ namespace proc { return _app_name; } + std::string proc_t::get_running_app_uuid() { + return _app.uuid; + } + boost::process::environment proc_t::get_env() { return _env; } diff --git a/src/process.h b/src/process.h index a6080321..34921f99 100644 --- a/src/process.h +++ b/src/process.h @@ -117,6 +117,7 @@ namespace proc { std::vector &get_apps(); std::string get_app_image(int app_id); std::string get_last_run_app_name(); + std::string get_running_app_uuid(); boost::process::environment get_env(); void terminate(bool immediate = false); diff --git a/src_assets/common/assets/web/apps.html b/src_assets/common/assets/web/apps.html index 5cb4cbc7..9cb472ff 100644 --- a/src_assets/common/assets/web/apps.html +++ b/src_assets/common/assets/web/apps.html @@ -89,15 +89,18 @@ {{app.name}} - - - + + @@ -444,12 +447,14 @@ return { apps: [], showEditForm: false, + actionDisabled: false, editForm: null, detachedCmd: "", coverSearching: false, coverFinderBusy: false, coverCandidates: [], platform: "", + currentApp: "" }; }, created() { @@ -469,6 +474,7 @@ .then(r => r.json()) .then(r => { this.apps = r.apps.map(i => ({...i, launching: false})); + this.currentApp = r.current_app; }); }, newApp() { @@ -477,20 +483,40 @@ }, launchApp(app) { if (confirm(this.$t('apps.launch_warning'))) { - app.launching = true; + this.actionDisabled = true; fetch("./api/apps/launch?uuid=" + app.uuid, { credentials: 'include', method: "POST", }) .then(r => r.json()) .then(r => { - if (r.status) { - alert(this.$t('apps.launch_success')); - } else { + if (!r.status) { alert(this.$t('apps.launch_failed') + r.error); } }) - .finally(() => app.launching = false); + .finally(() => { + this.actionDisabled = false; + this.loadApps() + }); + } + }, + closeApp() { + if (confirm(this.$t('apps.close_warning'))) { + this.actionDisabled = true; + fetch("./api/apps/close", { + credentials: 'include', + method: "POST" + }) + .then((r) => r.json()) + .then((r) => { + if (!r.status) { + alert("apps.close_failed") + } + }) + .finally(() => { + this.actionDisabled = false; + this.loadApps() + }); } }, editApp(app) { @@ -620,7 +646,6 @@ save() { this.editForm.name = this.editForm.name.trim(); this.editForm["image-path"] = this.editForm["image-path"].toString().trim().replace(/"/g, ''); - delete this.editForm["launching"]; delete this.editForm["id"]; fetch("./api/apps", { credentials: 'include', 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 99e18158..fdef7562 100644 --- a/src_assets/common/assets/web/public/assets/locale/en.json +++ b/src_assets/common/assets/web/public/assets/locale/en.json @@ -40,6 +40,9 @@ "applications_title": "Applications", "auto_detach": "Continue streaming if the application exits quickly", "auto_detach_desc": "This will attempt to automatically detect launcher-type apps that close quickly after launching another program or instance of themselves. When a launcher-type app is detected, it is treated as a detached app.", + "close": "Terminate", + "close_warning": "Are you sure to terminate the current running app?", + "close_failed": "App termination failed.", "cmd": "Command", "cmd_desc": "The main application to start. If blank, no application will be started.", "cmd_note": "If the path to the command executable contains spaces, you must enclose it in quotes.", @@ -80,7 +83,6 @@ "image_desc": "Application icon/picture/image path that will be sent to client. Image must be a PNG file. If not set, Apollo will send default box image.", "launch": "Launch", "launch_warning": "Are you sure you want to launch this app? This will terminate the currently running app.", - "launch_success": "App launched successfully!", "launch_failed": "App launch failed: ", "loading": "Loading...", "name": "Name", 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 31052080..cb2cbe37 100644 --- a/src_assets/common/assets/web/public/assets/locale/zh.json +++ b/src_assets/common/assets/web/public/assets/locale/zh.json @@ -40,6 +40,9 @@ "applications_title": "应用", "auto_detach": "启动串流后应用突然关闭时不退出串流", "auto_detach_desc": "这将尝试自动检测在启动另一个程序或自身实例后很快关闭的启动类应用。 检测到启动型应用程序时,它会被视为一个分离的应用程序。", + "close": "终止", + "close_warning": "确定要终止当前正在运行的APP吗?", + "close_failed": "APP终止失败。", "cmd": "命令", "cmd_desc": "要启动的主要应用程序。如果为空,将不会启动任何应用程序。", "cmd_note": "如果命令中可执行文件的路径包含空格,则必须用引号括起来。",