feat: add warning popup if existing desktop process is present
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <montauk/config.h>
|
||||
#include <montauk/user.h>
|
||||
#include <gui/clipboard.hpp>
|
||||
#include <gui/dialogs.hpp>
|
||||
|
||||
// ============================================================================
|
||||
// App Manifest Scanning
|
||||
@@ -642,7 +643,46 @@ void gui::desktop_run(DesktopState* ds) {
|
||||
|
||||
static DesktopState* g_desktop;
|
||||
|
||||
static constexpr const char kDesktopBinaryName[] = "desktop.elf";
|
||||
static constexpr int DESKTOP_PROC_SCAN_MAX = 256;
|
||||
|
||||
static bool desktop_proc_alive(const Montauk::ProcInfo& proc) {
|
||||
return proc.state == 1 || proc.state == 2 || proc.state == 3;
|
||||
}
|
||||
|
||||
static bool proc_name_is_desktop(const char* name) {
|
||||
int name_len = montauk::slen(name);
|
||||
int binary_len = (int)sizeof(kDesktopBinaryName) - 1;
|
||||
if (name_len < binary_len) return false;
|
||||
|
||||
const char* suffix = name + name_len - binary_len;
|
||||
if (!montauk::streq(suffix, kDesktopBinaryName)) return false;
|
||||
return name_len == binary_len || suffix[-1] == '/';
|
||||
}
|
||||
|
||||
static bool existing_desktop_running() {
|
||||
static Montauk::ProcInfo procs[DESKTOP_PROC_SCAN_MAX];
|
||||
int count = montauk::proclist(procs, DESKTOP_PROC_SCAN_MAX);
|
||||
if (count <= 0) return false;
|
||||
|
||||
int self_pid = montauk::getpid();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (procs[i].pid == self_pid) continue;
|
||||
if (!desktop_proc_alive(procs[i])) continue;
|
||||
if (proc_name_is_desktop(procs[i].name)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
extern "C" void _start() {
|
||||
if (existing_desktop_running()) {
|
||||
gui::dialogs::message_box(
|
||||
"Desktop Already Running",
|
||||
"Cannot spawn new desktop process whilst an existing desktop session is active.",
|
||||
gui::dialogs::MESSAGE_BOX_OK);
|
||||
montauk::exit(0);
|
||||
}
|
||||
|
||||
DesktopState* ds = (DesktopState*)montauk::malloc(sizeof(DesktopState));
|
||||
montauk::memset(ds, 0, sizeof(DesktopState));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user