Skip to content

Commit fb0108b

Browse files
committed
Updated it so you cant have multiple instances open
1 parent 4cbaaad commit fb0108b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/win/WinApp.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,21 @@ LRESULT CALLBACK WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
3737
return DefWindowProc(hwnd, msg, wParam, lParam);
3838
}
3939

40-
int RunWindowsApp ( ) {
40+
int RunWindowsApp() {
41+
HANDLE hMutex = CreateMutexA(NULL, TRUE, "Global//SplitLoaf");
42+
if (!hMutex) {
43+
MessageBoxA(NULL, "Failed to create mutex.", "Error", MB_OK | MB_ICONERROR);
44+
return 1;
45+
}
46+
47+
if (GetLastError() == ERROR_ALREADY_EXISTS) {
48+
MessageBoxA(NULL, "Split Loaf is already running.", "Info", MB_OK | MB_ICONINFORMATION);
49+
CloseHandle(hMutex);
50+
return 0; // exit this duplicate instance
51+
}
52+
4153
g_hInstance = GetModuleHandle(NULL);
4254

43-
// Initialize keybinds & settings
4455
WinSettings_Init();
4556

4657
WNDCLASS wc = {};
@@ -65,6 +76,8 @@ int RunWindowsApp ( ) {
6576

6677
if (msg.message == WM_QUIT) {
6778
Platform::shutdown();
79+
ReleaseMutex(hMutex);
80+
CloseHandle(hMutex);
6881
return 0;
6982
}
7083
}

0 commit comments

Comments
 (0)