Skip to content

Commit

Permalink
wait for the process to start before closing handles
Browse files Browse the repository at this point in the history
  • Loading branch information
aloneguid committed Feb 1, 2024
1 parent 2e86212 commit 7e03a07
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'Build'

env:
VERSION: 3.7.0
VERSION: 3.7.1
BUILD_TYPE: Release
ARCH: x64
VCPKG_CONFIG: Release
Expand Down
30 changes: 29 additions & 1 deletion bt/app/browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ namespace bt {
}

//win32::shell::exec(b->open_cmd, arg);
win32::process::start(b->open_cmd + " " + arg, false);
//win32::process::start(b->open_cmd + " " + arg, false);
launch_win32_process_and_foreground(b->open_cmd + " " + arg);
}

bool browser_instance::is_match(const url_payload& up, match_rule& mr) const {
Expand Down Expand Up @@ -290,4 +291,31 @@ namespace bt {
}
}
}

void browser_instance::launch_win32_process_and_foreground(const std::string& cmdline) const {
STARTUPINFO si{};
PROCESS_INFORMATION pi{};
DWORD pid{0};

if(::CreateProcess(nullptr,
const_cast<wchar_t*>(str::to_wstr(cmdline).c_str()),
nullptr,
nullptr,
false,
0,
nullptr,
nullptr,
&si,
&pi)) {

// Wait for the process to start before closing the handles,
// otherwise the process will be terminated (browser will be shown in the background).

// Wait for 5 seconds maximum
::WaitForSingleObject(pi.hProcess, 5000);

::CloseHandle(pi.hProcess);
::CloseHandle(pi.hThread);
}
}
}
1 change: 1 addition & 0 deletions bt/app/browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ namespace bt {
void set_rules_from_text(std::vector<std::string> rules_txt);

private:
void launch_win32_process_and_foreground(const std::string& cmdline) const;
};

struct browser_match_result {
Expand Down
6 changes: 6 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 3.7.1

### Improvements

- Hopefully fixed browser being backgrounded for some users (#39).

## 3.7.0

### New features
Expand Down

0 comments on commit 7e03a07

Please sign in to comment.