Skip to content

Commit

Permalink
Merge pull request #17 from miniben-90/fix-win32-url
Browse files Browse the repository at this point in the history
[WIN32] Fix issue #16 - Electron problem with multithread and url recovery
  • Loading branch information
miniben-90 authored Feb 27, 2024
2 parents cc0f257 + fc70790 commit edaf0d5
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/win32/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,21 +427,19 @@ fn get_window_information(hwnd: HWND) -> WindowInfo {

fn get_browser_url(hwnd: HWND, exec_name: String) -> String {
unsafe {
if CoInitializeEx(None, COINIT_MULTITHREADED).is_ok() {
if CoInitializeEx(None, COINIT_APARTMENTTHREADED).is_ok() {
let automation: Result<IUIAutomation, _> = CoCreateInstance(&CUIAutomation, None, CLSCTX_ALL);
if automation.is_ok() {
let automation: IUIAutomation = automation.unwrap();
let element: Result<IUIAutomationElement, _> = automation.ElementFromHandle(hwnd);
if element.is_ok() {
let element: IUIAutomationElement = element.unwrap();
/* Chromium part to get url from search bar */
if exec_name.contains(&"firefox") {
return get_url_from_automation_id(&automation, &element, "urlbar-input".to_owned());
} else if exec_name.contains(&"msedge") {
return get_url_from_automation_id(&automation, &element, "view_1020".to_owned());
} else {
return get_url_for_chromium(&automation, &element);
}
return match &exec_name.to_lowercase() {
x if x.contains(&"firefox") => get_url_from_automation_id(&automation, &element, "urlbar-input".to_owned()),
x if x.contains(&"msedge") => get_url_from_automation_id(&automation, &element, "view_1020".to_owned()),
_ => get_url_for_chromium(&automation, &element)
};
}
}
}
Expand Down

0 comments on commit edaf0d5

Please sign in to comment.