Open a URL in the default browser.
(url: &str)
| 177 | |
| 178 | /// Open a URL in the default browser. |
| 179 | pub fn open_browser_url(url: &str) -> std::result::Result<(), String> { |
| 180 | #[cfg(target_os = "macos")] |
| 181 | { |
| 182 | std::process::Command::new("open") |
| 183 | .arg(url) |
| 184 | .spawn() |
| 185 | .map_err(|e| format!("failed to run `open`: {e}"))?; |
| 186 | } |
| 187 | |
| 188 | #[cfg(target_os = "linux")] |
| 189 | { |
| 190 | std::process::Command::new("xdg-open") |
| 191 | .arg(url) |
| 192 | .spawn() |
| 193 | .map_err(|e| format!("failed to run `xdg-open`: {e}"))?; |
| 194 | } |
| 195 | |
| 196 | #[cfg(target_os = "windows")] |
| 197 | { |
| 198 | std::process::Command::new("cmd") |
| 199 | .args(["/C", "start", url]) |
| 200 | .spawn() |
| 201 | .map_err(|e| format!("failed to open browser: {e}"))?; |
| 202 | } |
| 203 | |
| 204 | #[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))] |
| 205 | { |
| 206 | return Err("unsupported platform for browser opening".to_string()); |
| 207 | } |
| 208 | |
| 209 | Ok(()) |
| 210 | } |
| 211 | |
| 212 | /// Extract the origin (scheme + host) from a gateway endpoint URL. |
| 213 | /// |
no test coverage detected