Skip to content

Commit 23f5e4c

Browse files
committed
fix: linux open url with firefox usind xdmg
1 parent 1c07705 commit 23f5e4c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/src/main.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ windows_subsystem = "windows"
44
)]
55
use std::env;
66

7+
#[cfg(not(target_os = "linux"))]
78
use webbrowser;
89

910
use tauri::{Manager};
@@ -183,12 +184,23 @@ fn zoom_window(window: tauri::Window, scale_factor: f64) {
183184

184185
#[tauri::command]
185186
fn open_url_in_browser(url: String) -> Result<(), String> {
186-
// Attempt to open the URL in the default web browser
187-
if webbrowser::open(&url).is_ok() {
188-
Ok(())
189-
} else {
190-
Err("Failed to open URL in the browser".into())
187+
#[cfg(target_os = "linux")]
188+
{
189+
// Use xdg-open for Linux
190+
Command::new("xdg-open")
191+
.arg(&url)
192+
.spawn()
193+
.map_err(|err| format!("Failed to open URL on Linux: {}", err))?;
191194
}
195+
196+
#[cfg(any(target_os = "windows", target_os = "macos"))]
197+
{
198+
// Use the webbrowser crate for Windows and Mac
199+
webbrowser::open(&url)
200+
.map_err(|err| format!("Failed to open URL in the browser: {}", err))?;
201+
}
202+
203+
Ok(())
192204
}
193205

194206
fn process_window_event(event: &GlobalWindowEvent) {

0 commit comments

Comments
 (0)