mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-03-31 01:07:05 +09:00
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:
@@ -41,6 +41,7 @@ namespace gsr {
|
||||
bool is_xdg_autostart_enabled();
|
||||
// Returns 0 on success
|
||||
int set_xdg_autostart(bool enable);
|
||||
void replace_xdg_autostart_with_current_gsr_type();
|
||||
|
||||
// Systemd user service helpers
|
||||
bool is_systemd_service_enabled(const char *service_name);
|
||||
|
||||
@@ -1864,8 +1864,6 @@ namespace gsr {
|
||||
exit_reason = "back-to-old-ui";
|
||||
else
|
||||
exit_reason = "exit";
|
||||
|
||||
set_xdg_autostart(false);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,27 @@
|
||||
#include "../include/Utils.hpp"
|
||||
#include "../include/Process.hpp"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <optional>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include "../include/Process.hpp"
|
||||
|
||||
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) {
|
||||
size_t index = 0;
|
||||
while(index < str.size()) {
|
||||
@@ -241,15 +254,8 @@ namespace gsr {
|
||||
}
|
||||
|
||||
bool is_xdg_autostart_enabled() {
|
||||
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 false;
|
||||
return output.find("Hidden=true") == std::string::npos;
|
||||
const std::optional<std::string> output = get_xdg_autostart_content();
|
||||
return output.has_value() && output.value().find("Hidden=true") == std::string::npos;
|
||||
}
|
||||
|
||||
int set_xdg_autostart(bool enable) {
|
||||
@@ -261,7 +267,8 @@ namespace gsr {
|
||||
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=gsr-ui launch-daemon";
|
||||
|
||||
@@ -286,6 +293,19 @@ namespace gsr {
|
||||
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) {
|
||||
const char *args[] = { "systemctl", "--user", "is-enabled", service_name, nullptr };
|
||||
std::string output;
|
||||
|
||||
@@ -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.
|
||||
|
||||
std::string exit_reason;
|
||||
@@ -344,6 +346,7 @@ int main(int argc, char **argv) {
|
||||
mgl_deinit();
|
||||
|
||||
if(exit_reason == "back-to-old-ui") {
|
||||
gsr::set_xdg_autostart(false);
|
||||
const char *args[] = { "gpu-screen-recorder-gtk", "use-old-ui", nullptr };
|
||||
execvp(args[0], (char* const*)args);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user