From 02698251796ef93f39e1fde90dcee4e865a8dfb2 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Thu, 5 Mar 2026 14:59:40 +0100 Subject: [PATCH] fix: windows single instance mutex --- windows/runner/main.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/windows/runner/main.cpp b/windows/runner/main.cpp index 4c305dd0..43a8489b 100644 --- a/windows/runner/main.cpp +++ b/windows/runner/main.cpp @@ -7,6 +7,18 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, _In_ wchar_t *command_line, _In_ int show_command) { + // Single instance enforcement + HANDLE mutex = CreateMutex(nullptr, TRUE, L"com.edde746.Plezy.SingleInstance"); + if (GetLastError() == ERROR_ALREADY_EXISTS) { + HWND existing = FindWindow(L"FLUTTER_RUNNER_WIN32_WINDOW", L"Plezy"); + if (existing) { + ShowWindow(existing, SW_RESTORE); + SetForegroundWindow(existing); + } + CloseHandle(mutex); + 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()) {