Skip to content

Commit d6ab03b

Browse files
committed
chore: add _open_url_in_browser_win API
1 parent 17c8fcc commit d6ab03b

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src-tauri/src/main.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,31 @@ fn _get_clipboard_files() -> Option<Vec<String>> {
114114
}
115115
}
116116

117+
#[tauri::command]
118+
fn _open_url_in_browser_win(url: String, browser: String) -> Result<(), String> {
119+
#[cfg(target_os = "windows")]
120+
{
121+
let browser_path = match browser.as_str() {
122+
"firefox" => "C:\\Program Files\\Mozilla Firefox\\firefox.exe",
123+
"chrome" => "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
124+
"edge" => "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe",
125+
_ => return Err(format!("Browser '{}' is not supported.", browser))
126+
};
127+
128+
// Spawn the browser process without waiting for it to finish
129+
Command::new(browser_path)
130+
.arg(url)
131+
.spawn()
132+
.map_err(|e| format!("Failed to open URL in {}: {}", browser, e.to_string()))?;
133+
134+
Ok(())
135+
}
136+
#[cfg(not(target_os = "windows"))]
137+
{
138+
Err("This API is only supported on Windows.".to_string())
139+
}
140+
}
141+
117142
// this in memory hashmap is used to supplement the LMDB node layer in a multi window environment.
118143
struct Storage {
119144
map: Mutex<HashMap<String, String>>,
@@ -412,7 +437,8 @@ fn main() {
412437
toggle_devtools, console_log, console_error, _get_commandline_args, get_current_working_dir,
413438
_get_window_labels,
414439
put_item, get_item, get_all_items, delete_item,
415-
_get_windows_drives, _rename_path, show_in_folder, move_to_trash, zoom_window, _get_clipboard_files])
440+
_get_windows_drives, _rename_path, show_in_folder, move_to_trash, zoom_window,
441+
_get_clipboard_files, _open_url_in_browser_win])
416442
.setup(|app| {
417443
init::init_app(app);
418444
#[cfg(target_os = "linux")]

0 commit comments

Comments
 (0)