Skip to content

Commit

Permalink
[Workspaces]Fix launching incorrect workspace via shortcut (#35233)
Browse files Browse the repository at this point in the history
ensure one launcher instance is running
  • Loading branch information
SeraphimaZykova authored Oct 3, 2024
1 parent bcb5ce8 commit 5770441
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/modules/Workspaces/WorkspacesLauncher/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

const std::wstring moduleName = L"Workspaces\\WorkspacesLauncher";
const std::wstring internalPath = L"";
const std::wstring instanceMutexName = L"Local\\PowerToys_WorkspacesLauncher_InstanceMutex";

int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cmdShow)
{
Expand All @@ -28,6 +29,18 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cm
return 0;
}

auto mutex = CreateMutex(nullptr, true, instanceMutexName.c_str());
if (mutex == nullptr)
{
Logger::error(L"Failed to create mutex. {}", get_last_error_or_default(GetLastError()));
}

if (GetLastError() == ERROR_ALREADY_EXISTS)
{
Logger::warn(L"WorkspacesLauncher instance is already running");
return 0;
}

std::wstring cmdLineStr{ GetCommandLineW() };
auto cmdArgs = split(cmdLineStr, L" ");
if (cmdArgs.workspaceId.empty())
Expand Down

0 comments on commit 5770441

Please sign in to comment.