Update plugins/os/src/lib.rs

Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de>
pull/346/head
Lucas Fernandes Nogueira 2 years ago committed by GitHub
parent a28f82bf6b
commit 914f501430
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,8 +12,6 @@ mod error;
pub use error::Error; pub use error::Error;
type Result<T> = std::result::Result<T, Error>; type Result<T> = std::result::Result<T, Error>;
pub struct OperatingSystem<R: Runtime>(AppHandle<R>);
pub enum Kind { pub enum Kind {
Linux, Linux,
Windows, Windows,
@ -34,20 +32,19 @@ impl Display for Kind {
} }
} }
impl<R: Runtime> OperatingSystem<R> { pub fn platform() -> &'static str {
pub fn platform(&self) -> &'static str {
match std::env::consts::OS { match std::env::consts::OS {
"windows" => "win32", "windows" => "win32",
"macos" => "darwin", "macos" => "darwin",
_ => std::env::consts::OS, _ => std::env::consts::OS,
} }
} }
pub fn version(&self) -> Version { pub fn version() -> Version {
os_info::get().version().clone() os_info::get().version().clone()
} }
pub fn kind(&self) -> Kind { pub fn kind() -> Kind {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
return Kind::Linux; return Kind::Linux;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
@ -58,25 +55,14 @@ impl<R: Runtime> OperatingSystem<R> {
return Kind::IOS; return Kind::IOS;
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
return Kind::Android; return Kind::Android;
}
pub fn arch(&self) -> &'static str {
std::env::consts::ARCH
}
pub fn tempdir(&self) -> PathBuf {
std::env::temp_dir()
}
} }
pub trait OperatingSystemExt<R: Runtime> { pub fn arch() -> &'static str {
fn os(&self) -> &OperatingSystem<R>; std::env::consts::ARCH
} }
impl<R: Runtime, T: Manager<R>> OperatingSystemExt<R> for T { pub fn tempdir() -> PathBuf {
fn os(&self) -> &OperatingSystem<R> { std::env::temp_dir()
self.state::<OperatingSystem<R>>().inner()
}
} }
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
@ -88,9 +74,5 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
commands::arch, commands::arch,
commands::tempdir commands::tempdir
]) ])
.setup(|app, _api| {
app.manage(OperatingSystem(app.clone()));
Ok(())
})
.build() .build()
} }

Loading…
Cancel
Save