From bf16591c077c5d77a8ba8fae2401157a81e18704 Mon Sep 17 00:00:00 2001 From: Peter Elliott Date: Wed, 21 Jul 2021 21:35:04 -0600 Subject: [PATCH] Assistant: Only open one Assistant at once I found myself accidentally opening two assistants at once with the Window+Space shortcut. Since only one assistant window is usable at the same time, I made assistant only spawn 1 instance at most. --- Userland/Applications/Assistant/main.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Userland/Applications/Assistant/main.cpp b/Userland/Applications/Assistant/main.cpp index 3655a4adc1..703d843aa9 100644 --- a/Userland/Applications/Assistant/main.cpp +++ b/Userland/Applications/Assistant/main.cpp @@ -7,6 +7,7 @@ #include "Providers.h" #include #include +#include #include #include #include @@ -17,6 +18,7 @@ #include #include #include +#include #include namespace Assistant { @@ -191,11 +193,23 @@ static constexpr size_t MAX_SEARCH_RESULTS = 6; int main(int argc, char** argv) { - if (pledge("stdio recvfd sendfd rpath unix proc exec thread", nullptr) < 0) { + if (pledge("stdio recvfd sendfd rpath cpath unix proc exec thread", nullptr) < 0) { perror("pledge"); return 1; } + Core::LockFile lockfile("/tmp/lock/assistant.lock"); + + if (!lockfile.is_held()) { + if (lockfile.error_code()) { + warnln("Core::LockFile: {}", strerror(lockfile.error_code())); + return 1; + } + + // Another assistant is open, so exit silently. + return 0; + } + auto app = GUI::Application::construct(argc, argv); auto window = GUI::Window::construct(); window->set_minimizable(false);