Skip to content

Commit

Permalink
fix: skip redundant operations when GetLaunchOn[Startup/Exit] are e…
Browse files Browse the repository at this point in the history
…mpty

`WaitForSingleObject` causes the IDM floating bar to not display (#130). This commit attempts to avoid calling `WaitForSingleObject` and advises end users to avoid using this function until a better method is implemented.
  • Loading branch information
Bush2021 committed Dec 6, 2024
1 parent c250fa6 commit aacc0a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Binary file modified src/chrome++.ini
Binary file not shown.
20 changes: 14 additions & 6 deletions src/portable.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ std::wstring GetCommand(LPWSTR param) {
HANDLE hMutex = nullptr;
bool IsFirstRun() {
DWORD pid = GetCurrentProcessId();
std::wstring mutex_name = L"Global\\ChromePlusFirstRunMutex" + std::to_wstring(pid);
std::wstring mutex_name =
L"Global\\ChromePlusFirstRunMutex" + std::to_wstring(pid);
hMutex = CreateMutexW(nullptr, TRUE, mutex_name.c_str());
if (hMutex == nullptr || GetLastError() == ERROR_ALREADY_EXISTS) {
return false;
Expand Down Expand Up @@ -110,10 +111,13 @@ void KillLaunchOnExit(std::vector<HANDLE>* program_handles) {
}

void Portable(LPWSTR param) {
std::vector<HANDLE> program_handles = {nullptr};
bool first_run = IsFirstRun();
if (first_run) {
LaunchCommands(GetLaunchOnStartup(), SW_SHOW, &program_handles);
auto launch_on_startup = GetLaunchOnStartup();
auto launch_on_exit = GetLaunchOnExit();
std::vector<HANDLE> program_handles = {nullptr};

if (first_run && !launch_on_startup.empty()) {
LaunchCommands(launch_on_startup, SW_SHOW, &program_handles);
}

wchar_t path[MAX_PATH];
Expand All @@ -129,11 +133,15 @@ void Portable(LPWSTR param) {
sei.lpParameters = args.c_str();

if (ShellExecuteEx(&sei)) {
if (first_run) {
if (first_run && !launch_on_exit.empty()) {
// `WaitForSingleObject` causes IDM floating bar not to be displayed.
// Hence, end users should be reminded to avoid using this feature until a
// better method is implemented. See:
// https://github.com/Bush2021/chrome_plus/issues/130
WaitForSingleObject(sei.hProcess, INFINITE);
CloseHandle(hMutex);
KillLaunchOnExit(&program_handles);
LaunchCommands(GetLaunchOnExit(), SW_HIDE, nullptr);
LaunchCommands(launch_on_exit, SW_HIDE, nullptr);
}
ExitProcess(0);
}
Expand Down

0 comments on commit aacc0a7

Please sign in to comment.