mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-04-24 10:39:51 +09:00
Only allow one instance of gsr-ui to run
This commit is contained in:
4
TODO
4
TODO
@@ -117,4 +117,6 @@ All steam game names by ID are available at https://api.steampowered.com/ISteamA
|
|||||||
|
|
||||||
Dont put widget position to int position when scrolling. This makes the UI jitter when it's coming to a halt.
|
Dont put widget position to int position when scrolling. This makes the UI jitter when it's coming to a halt.
|
||||||
|
|
||||||
Show a popup asking if the user wants to add the program to system startup when launching the program, with a dismiss option and "Do not show again".
|
Show a popup asking if the user wants to add the program to system startup when launching the program, with a dismiss option and "Do not show again".
|
||||||
|
|
||||||
|
Show warning if another instance of gpu screen recorder is already running when starting recording?
|
||||||
@@ -17,6 +17,5 @@ namespace gsr {
|
|||||||
pid_t exec_program(const char **args, int *read_fd);
|
pid_t exec_program(const char **args, int *read_fd);
|
||||||
// Arguments ending with NULL. Returns the exit status of the program or -1 on error
|
// Arguments ending with NULL. Returns the exit status of the program or -1 on error
|
||||||
int exec_program_get_stdout(const char **args, std::string &result);
|
int exec_program_get_stdout(const char **args, std::string &result);
|
||||||
// |output_buffer| should be at least PATH_MAX in size
|
pid_t pidof(const char *process_name);
|
||||||
bool read_cmdline_arg0(const char *filepath, char *output_buffer);
|
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,15 @@ namespace gsr {
|
|||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool is_number(const char *str) {
|
||||||
|
for(int i = 0; str[i]; ++i) {
|
||||||
|
char c = str[i];
|
||||||
|
if(c < '0' || c > '9')
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool exec_program_daemonized(const char **args) {
|
bool exec_program_daemonized(const char **args) {
|
||||||
/* 1 argument */
|
/* 1 argument */
|
||||||
if(args[0] == nullptr)
|
if(args[0] == nullptr)
|
||||||
@@ -134,7 +143,8 @@ namespace gsr {
|
|||||||
return exit_status;
|
return exit_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool read_cmdline_arg0(const char *filepath, char *output_buffer) {
|
// |output_buffer| should be at least PATH_MAX in size
|
||||||
|
bool read_cmdline_arg0(const char *filepath, char *output_buffer, int output_buffer_size) {
|
||||||
output_buffer[0] = '\0';
|
output_buffer[0] = '\0';
|
||||||
|
|
||||||
const char *arg0_end = NULL;
|
const char *arg0_end = NULL;
|
||||||
@@ -151,13 +161,40 @@ namespace gsr {
|
|||||||
if(!arg0_end)
|
if(!arg0_end)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
memcpy(output_buffer, buffer, arg0_end - buffer);
|
if((arg0_end - buffer) + 1 <= output_buffer_size) {
|
||||||
output_buffer[arg0_end - buffer] = '\0';
|
memcpy(output_buffer, buffer, arg0_end - buffer);
|
||||||
close(fd);
|
output_buffer[arg0_end - buffer] = '\0';
|
||||||
return true;
|
close(fd);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
err:
|
err:
|
||||||
close(fd);
|
close(fd);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid_t pidof(const char *process_name) {
|
||||||
|
pid_t result = -1;
|
||||||
|
DIR *dir = opendir("/proc");
|
||||||
|
if(!dir)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
char cmdline_filepath[PATH_MAX];
|
||||||
|
char arg0[PATH_MAX];
|
||||||
|
|
||||||
|
struct dirent *entry;
|
||||||
|
while((entry = readdir(dir)) != NULL) {
|
||||||
|
if(!is_number(entry->d_name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
snprintf(cmdline_filepath, sizeof(cmdline_filepath), "/proc/%s/cmdline", entry->d_name);
|
||||||
|
if(read_cmdline_arg0(cmdline_filepath, arg0, sizeof(arg0)) && strcmp(process_name, arg0) == 0) {
|
||||||
|
result = atoi(entry->d_name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "../include/GlobalHotkeysX11.hpp"
|
#include "../include/GlobalHotkeysX11.hpp"
|
||||||
#include "../include/GlobalHotkeysLinux.hpp"
|
#include "../include/GlobalHotkeysLinux.hpp"
|
||||||
#include "../include/gui/Utils.hpp"
|
#include "../include/gui/Utils.hpp"
|
||||||
|
#include "../include/Process.hpp"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@@ -170,6 +171,13 @@ int main(int argc, char **argv) {
|
|||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pid_t gsr_ui_pid = gsr::pidof("gsr-ui");
|
||||||
|
if(gsr_ui_pid != -1) {
|
||||||
|
const char *args[] = { "gsr-notify", "--text", "Another instance of GPU Screen Recorder UI is already running", "--timeout", "5.0", "--icon-color", "ff0000", "--bg-color", "ff0000", nullptr };
|
||||||
|
gsr::exec_program_daemonized(args);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Cant get window texture when prime-run is used
|
// Cant get window texture when prime-run is used
|
||||||
disable_prime_run();
|
disable_prime_run();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user