Automatically treat launcher-type apps as detached

This commit is contained in:
Cameron Gutman
2023-10-03 23:14:41 -05:00
parent cfd78b5ce7
commit ed95b50f7a
4 changed files with 38 additions and 0 deletions

View File

@@ -254,6 +254,7 @@ Application List
- ``image-path`` - The full path to the cover art image to use. - ``image-path`` - The full path to the cover art image to use.
- ``name`` - The name of the application/game - ``name`` - The name of the application/game
- ``output`` - The file where the output of the command is stored - ``output`` - The file where the output of the command is stored
- ``auto-detach`` - Specifies whether the app should be treated as detached if it exits quickly
- ``prep-cmd`` - A list of commands to be run before/after the application - ``prep-cmd`` - A list of commands to be run before/after the application
- If any of the prep-commands fail, starting the application is aborted - If any of the prep-commands fail, starting the application is aborted

View File

@@ -227,6 +227,8 @@ namespace proc {
} }
} }
_app_launch_time = std::chrono::steady_clock::now();
fg.disable(); fg.disable();
return 0; return 0;
@@ -237,9 +239,17 @@ namespace proc {
if (placebo || _process.running()) { if (placebo || _process.running()) {
return _app_id; return _app_id;
} }
else if (_app.auto_detach && _process.native_exit_code() == 0 &&
std::chrono::steady_clock::now() - _app_launch_time < 5s) {
BOOST_LOG(info) << "App exited gracefully within 5 seconds of launch. Treating the app as a detached command."sv;
BOOST_LOG(info) << "Adjust this behavior in the Applications tab or apps.json if this is not what you want."sv;
placebo = true;
return _app_id;
}
// Perform cleanup actions now if needed // Perform cleanup actions now if needed
if (_process) { if (_process) {
BOOST_LOG(info) << "App exited with code ["sv << _process.native_exit_code() << ']';
terminate(); terminate();
} }
@@ -548,6 +558,7 @@ namespace proc {
auto image_path = app_node.get_optional<std::string>("image-path"s); auto image_path = app_node.get_optional<std::string>("image-path"s);
auto working_dir = app_node.get_optional<std::string>("working-dir"s); auto working_dir = app_node.get_optional<std::string>("working-dir"s);
auto elevated = app_node.get_optional<bool>("elevated"s); auto elevated = app_node.get_optional<bool>("elevated"s);
auto auto_detach = app_node.get_optional<bool>("auto-detach"s);
std::vector<proc::cmd_t> prep_cmds; std::vector<proc::cmd_t> prep_cmds;
if (!exclude_global_prep.value_or(false)) { if (!exclude_global_prep.value_or(false)) {
@@ -606,6 +617,7 @@ namespace proc {
} }
ctx.elevated = elevated.value_or(false); ctx.elevated = elevated.value_or(false);
ctx.auto_detach = auto_detach.value_or(true);
auto possible_ids = calculate_app_id(name, ctx.image_path, i++); auto possible_ids = calculate_app_id(name, ctx.image_path, i++);
if (ids.count(std::get<0>(possible_ids)) == 0) { if (ids.count(std::get<0>(possible_ids)) == 0) {

View File

@@ -52,6 +52,7 @@ namespace proc {
std::string image_path; std::string image_path;
std::string id; std::string id;
bool elevated; bool elevated;
bool auto_detach;
}; };
class proc_t { class proc_t {
@@ -93,6 +94,7 @@ namespace proc {
boost::process::environment _env; boost::process::environment _env;
std::vector<ctx_t> _apps; std::vector<ctx_t> _apps;
ctx_t _app; ctx_t _app;
std::chrono::steady_clock::time_point _app_launch_time;
// If no command associated with _app_id, yet it's still running // If no command associated with _app_id, yet it's still running
bool placebo {}; bool placebo {};

View File

@@ -229,6 +229,25 @@
permissions to run properly. permissions to run properly.
</div> </div>
</div> </div>
<!-- auto-detach -->
<div class="mb-3 form-check">
<label for="autoDetach" class="form-check-label"
>Continue streaming if the application exits quickly</label
>
<input
type="checkbox"
class="form-check-input"
id="autoDetach"
v-model="editForm['auto-detach']"
true-value="true"
false-value="false"
/>
<div class="form-text">
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.
</div>
</div>
<!-- Image path --> <!-- Image path -->
<div class="mb-3"> <div class="mb-3">
<label for="appImagePath" class="form-label">Image</label> <label for="appImagePath" class="form-label">Image</label>
@@ -379,6 +398,7 @@
index: -1, index: -1,
"exclude-global-prep-cmd": false, "exclude-global-prep-cmd": false,
elevated: false, elevated: false,
"auto-detach": true,
"prep-cmd": [], "prep-cmd": [],
detached: [], detached: [],
"image-path": "" "image-path": ""
@@ -398,6 +418,9 @@
if(this.editForm["elevated"] === undefined && this.platform === 'windows'){ if(this.editForm["elevated"] === undefined && this.platform === 'windows'){
this.$set(this.editForm, "elevated", false); this.$set(this.editForm, "elevated", false);
} }
if(this.editForm["auto-detach"] === undefined){
this.$set(this.editForm, "auto-detach", true);
}
this.showEditForm = true; this.showEditForm = true;
}, },
showDeleteForm(id) { showDeleteForm(id) {