feat: add instance guard

This commit is contained in:
Curve 2021-02-27 19:03:53 +01:00
parent 74a80907f9
commit 76db90bd46
No known key found for this signature in database
GPG Key ID: 460F6C466BD35813
4 changed files with 17 additions and 2 deletions

5
.gitmodules vendored
View File

@ -15,4 +15,7 @@
url = https://github.com/btzy/nativefiledialog-extended/
[submodule "src/ui/impl/webview/lib/soundux-ui"]
path = src/ui/impl/webview/lib/soundux-ui
url = https://github.com/Soundux/soundux-ui
url = https://github.com/Soundux/soundux-ui
[submodule "lib/InstanceGuard"]
path = lib/InstanceGuard
url = https://github.com/Grandbrain/InstanceGuard

View File

@ -13,6 +13,7 @@ add_executable(soundux ${src})
target_include_directories(soundux PRIVATE "lib/miniaudio")
target_include_directories(soundux PRIVATE "lib/fancypp/include")
target_include_directories(soundux PRIVATE "lib/json/single_include")
target_include_directories(soundux PRIVATE "lib/InstanceGuard/Source")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
@ -29,7 +30,8 @@ endif()
add_subdirectory(src/ui/impl/webview/lib/webview)
add_subdirectory(lib/nativefiledialog-extended)
target_link_libraries(soundux PUBLIC webview nfd)
add_subdirectory(lib/InstanceGuard/Source)
target_link_libraries(soundux PUBLIC webview nfd InstanceGuard)
# [[ Build Frontend ]]
if (MSVC)

1
lib/InstanceGuard Submodule

@ -0,0 +1 @@
Subproject commit 5e3efce2036d744c04f1b190536d7c57e567040d

View File

@ -1,8 +1,17 @@
#include "core/global/globals.hpp"
#include "ui/impl/webview/webview.hpp"
#include <InstanceGuard.hpp>
#include <fancy.hpp>
int main()
{
InstanceGuard::InstanceGuard guard("soundux-guard");
if (guard.IsAnotherInstanceRunning())
{
Fancy::fancy.logTime().failure() << "Another Instance is already running!" << std::endl;
std::terminate();
}
#if defined(__linux__)
if (!Soundux::Globals::gPulse.isSwitchOnConnectLoaded())
{