| |
| |
| |
|
|
| |
|
|
| use serde::{Deserialize, Deserializer}; |
|
|
| use crate::scope::OpenScope; |
| use std::str::FromStr; |
|
|
| |
| #[deprecated(since = "2.1.0", note = "Use tauri-plugin-opener instead.")] |
| pub enum Program { |
| |
| Open, |
| |
| Start, |
| |
| XdgOpen, |
| |
| Gio, |
| |
| GnomeOpen, |
| |
| KdeOpen, |
| |
| WslView, |
| |
| Firefox, |
| |
| Chrome, |
| |
| Chromium, |
| |
| Safari, |
| } |
|
|
| impl FromStr for Program { |
| type Err = super::Error; |
|
|
| fn from_str(s: &str) -> Result<Self, Self::Err> { |
| let p = match s.to_lowercase().as_str() { |
| "open" => Self::Open, |
| "start" => Self::Start, |
| "xdg-open" => Self::XdgOpen, |
| "gio" => Self::Gio, |
| "gnome-open" => Self::GnomeOpen, |
| "kde-open" => Self::KdeOpen, |
| "wslview" => Self::WslView, |
| "firefox" => Self::Firefox, |
| "chrome" | "google chrome" => Self::Chrome, |
| "chromium" => Self::Chromium, |
| "safari" => Self::Safari, |
| _ => return Err(crate::Error::UnknownProgramName(s.to_string())), |
| }; |
| Ok(p) |
| } |
| } |
|
|
| impl<'de> Deserialize<'de> for Program { |
| fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> |
| where |
| D: Deserializer<'de>, |
| { |
| let s = String::deserialize(deserializer)?; |
| Program::from_str(&s).map_err(|e| serde::de::Error::custom(e.to_string())) |
| } |
| } |
|
|
| impl Program { |
| pub(crate) fn name(self) -> &'static str { |
| match self { |
| Self::Open => "open", |
| Self::Start => "start", |
| Self::XdgOpen => "xdg-open", |
| Self::Gio => "gio", |
| Self::GnomeOpen => "gnome-open", |
| Self::KdeOpen => "kde-open", |
| Self::WslView => "wslview", |
|
|
| #[cfg(target_os = "macos")] |
| Self::Firefox => "Firefox", |
| #[cfg(not(target_os = "macos"))] |
| Self::Firefox => "firefox", |
|
|
| #[cfg(target_os = "macos")] |
| Self::Chrome => "Google Chrome", |
| #[cfg(not(target_os = "macos"))] |
| Self::Chrome => "google-chrome", |
|
|
| #[cfg(target_os = "macos")] |
| Self::Chromium => "Chromium", |
| #[cfg(not(target_os = "macos"))] |
| Self::Chromium => "chromium", |
|
|
| #[cfg(target_os = "macos")] |
| Self::Safari => "Safari", |
| #[cfg(not(target_os = "macos"))] |
| Self::Safari => "safari", |
| } |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #[deprecated(since = "2.1.0", note = "Use tauri-plugin-opener instead.")] |
| pub fn open<P: AsRef<str>>( |
| scope: Option<&OpenScope>, |
| path: P, |
| with: Option<Program>, |
| ) -> crate::Result<()> { |
| |
| if let Some(scope) = scope { |
| scope.open(path.as_ref(), with).map_err(Into::into) |
| } else { |
| |
| match with.map(Program::name) { |
| Some(program) => ::open::with_detached(path.as_ref(), program), |
| None => ::open::that_detached(path.as_ref()), |
| } |
| .map_err(Into::into) |
| } |
| } |
|
|