diff options
author | Peter Elliott <pelliott@ualberta.ca> | 2021-07-21 21:35:04 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-22 23:34:15 +0200 |
commit | bf16591c077c5d77a8ba8fae2401157a81e18704 (patch) | |
tree | 7cb66d5cb23fe9222b4b421990ad29bcdde28617 /Userland | |
parent | fdcfd2816eaaa03cc58949721fd19eaee07e3673 (diff) | |
download | serenity-bf16591c077c5d77a8ba8fae2401157a81e18704.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Applications/Assistant/main.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
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 <AK/QuickSort.h> #include <AK/String.h> +#include <LibCore/LockFile.h> #include <LibGUI/Application.h> #include <LibGUI/BoxLayout.h> #include <LibGUI/Event.h> @@ -17,6 +18,7 @@ #include <LibGUI/TextBox.h> #include <LibGfx/Palette.h> #include <LibThreading/Mutex.h> +#include <string.h> #include <unistd.h> 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); |