diff --git a/linux/my_application.cc b/linux/my_application.cc index b9b8da8..810e737 100644 --- a/linux/my_application.cc +++ b/linux/my_application.cc @@ -102,6 +102,6 @@ static void my_application_init(MyApplication* self) {} MyApplication* my_application_new() { return MY_APPLICATION(g_object_new(my_application_get_type(), "application-id", APPLICATION_ID, - "flags", G_APPLICATION_NON_UNIQUE, + "flags", G_APPLICATION_FLAGS_NONE, nullptr)); } diff --git a/windows/runner/main.cpp b/windows/runner/main.cpp index 5297d1e..162b619 100644 --- a/windows/runner/main.cpp +++ b/windows/runner/main.cpp @@ -8,8 +8,29 @@ auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP); #include "flutter_window.h" #include "utils.h" +HANDLE g_hMutex = NULL; + +bool CheckIfAlreadyRunning() { + g_hMutex = CreateMutex(NULL, FALSE, L"Global\\SolianDesktop"); + + if (g_hMutex == NULL) { + return true; // Mutex creation failed + } + + if (GetLastError() == ERROR_ALREADY_EXISTS) { + CloseHandle(g_hMutex); + return true; // Another instance is running + } + + return false; +} + int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, _In_ wchar_t *command_line, _In_ int show_command) { + if (CheckIfAlreadyRunning()) { + return EXIT_SUCCESS; + } + // Attach to console when present (e.g., 'flutter run') or create a // new console when running with a debugger. if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {