Replace flatpak/native autostart with the current gsr-ui type when launching gsr-ui, for users that switch between them

This commit is contained in:
dec05eba
2026-03-27 02:18:06 +01:00
parent 5f3ace0c47
commit 13984f8636
4 changed files with 35 additions and 13 deletions

View File

@@ -41,6 +41,7 @@ namespace gsr {
bool is_xdg_autostart_enabled(); bool is_xdg_autostart_enabled();
// Returns 0 on success // Returns 0 on success
int set_xdg_autostart(bool enable); int set_xdg_autostart(bool enable);
void replace_xdg_autostart_with_current_gsr_type();
// Systemd user service helpers // Systemd user service helpers
bool is_systemd_service_enabled(const char *service_name); bool is_systemd_service_enabled(const char *service_name);

View File

@@ -1864,8 +1864,6 @@ namespace gsr {
exit_reason = "back-to-old-ui"; exit_reason = "back-to-old-ui";
else else
exit_reason = "exit"; exit_reason = "exit";
set_xdg_autostart(false);
exit(); exit();
} }

View File

@@ -1,14 +1,27 @@
#include "../include/Utils.hpp" #include "../include/Utils.hpp"
#include "../include/Process.hpp"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <optional>
#include <unistd.h> #include <unistd.h>
#include <pwd.h> #include <pwd.h>
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "../include/Process.hpp"
namespace gsr { namespace gsr {
static std::optional<std::string> get_xdg_autostart_content() {
const char *args[] = {
"/bin/sh", "-c",
"cat \"${XDG_CONFIG_HOME:-$HOME/.config}/autostart/gpu-screen-recorder-ui.desktop\"",
nullptr
};
std::string output;
if(exec_program_on_host_get_stdout(args, output, true) != 0)
return std::nullopt;
return output;
}
void string_split_char(std::string_view str, char delimiter, StringSplitCallback callback_func) { void string_split_char(std::string_view str, char delimiter, StringSplitCallback callback_func) {
size_t index = 0; size_t index = 0;
while(index < str.size()) { while(index < str.size()) {
@@ -241,15 +254,8 @@ namespace gsr {
} }
bool is_xdg_autostart_enabled() { bool is_xdg_autostart_enabled() {
const char *args[] = { const std::optional<std::string> output = get_xdg_autostart_content();
"/bin/sh", "-c", return output.has_value() && output.value().find("Hidden=true") == std::string::npos;
"cat \"${XDG_CONFIG_HOME:-$HOME/.config}/autostart/gpu-screen-recorder-ui.desktop\"",
nullptr
};
std::string output;
if(exec_program_on_host_get_stdout(args, output, true) != 0)
return false;
return output.find("Hidden=true") == std::string::npos;
} }
int set_xdg_autostart(bool enable) { int set_xdg_autostart(bool enable) {
@@ -261,7 +267,8 @@ namespace gsr {
return 67; return 67;
} }
const char *exec_line = (getenv("FLATPAK_ID") != nullptr) const bool is_flatpak = getenv("FLATPAK_ID") != nullptr;
const char *exec_line = is_flatpak
? "Exec=flatpak run com.dec05eba.gpu_screen_recorder gsr-ui launch-daemon" ? "Exec=flatpak run com.dec05eba.gpu_screen_recorder gsr-ui launch-daemon"
: "Exec=gsr-ui launch-daemon"; : "Exec=gsr-ui launch-daemon";
@@ -286,6 +293,19 @@ namespace gsr {
return exec_program_on_host_get_stdout(args, dummy, true); return exec_program_on_host_get_stdout(args, dummy, true);
} }
void replace_xdg_autostart_with_current_gsr_type() {
const std::optional<std::string> output = get_xdg_autostart_content();
if(!output.has_value())
return;
const bool is_flatpak = getenv("FLATPAK_ID") != nullptr;
const bool is_exec_flatpak = output.value().find("flatpak run") != std::string::npos;
if(is_flatpak != is_exec_flatpak) {
const bool is_autostart_enabled = output.value().find("Hidden=true") == std::string::npos;
set_xdg_autostart(is_autostart_enabled);
}
}
bool is_systemd_service_enabled(const char *service_name) { bool is_systemd_service_enabled(const char *service_name) {
const char *args[] = { "systemctl", "--user", "is-enabled", service_name, nullptr }; const char *args[] = { "systemctl", "--user", "is-enabled", service_name, nullptr };
std::string output; std::string output;

View File

@@ -319,6 +319,8 @@ int main(int argc, char **argv) {
} }
} }
gsr::replace_xdg_autostart_with_current_gsr_type();
// TODO: Add hotkeys in Overlay when using x11 global hotkeys. The hotkeys in Overlay should duplicate each key that is used for x11 global hotkeys. // TODO: Add hotkeys in Overlay when using x11 global hotkeys. The hotkeys in Overlay should duplicate each key that is used for x11 global hotkeys.
std::string exit_reason; std::string exit_reason;
@@ -344,6 +346,7 @@ int main(int argc, char **argv) {
mgl_deinit(); mgl_deinit();
if(exit_reason == "back-to-old-ui") { if(exit_reason == "back-to-old-ui") {
gsr::set_xdg_autostart(false);
const char *args[] = { "gpu-screen-recorder-gtk", "use-old-ui", nullptr }; const char *args[] = { "gpu-screen-recorder-gtk", "use-old-ui", nullptr };
execvp(args[0], (char* const*)args); execvp(args[0], (char* const*)args);
return 0; return 0;