snapshot of https://github.com/tauri-apps/plugins-workspace.git (v2, 2026-09-23; blobs > 131072B omitted)
Some checks failed
integration tests / run-integration-tests (windows-latest) (push) Has been cancelled
Test Rust / test (push) Has been cancelled
test plugins e2e (mobile) / ios (push) Has been cancelled
test plugins e2e / test (map[name:Windows os:windows-latest]) (push) Has been cancelled
test plugins e2e / test (map[name:macOS os:macos-latest]) (push) Has been cancelled
integration tests / run-integration-tests (macos-latest) (push) Has been cancelled
version or publish / version-or-publish (push) Failing after 0s
integration tests / run-integration-tests (ubuntu-22.04) (push) Failing after 0s
Lint JavaScript / eslint (push) Failing after 0s
Sync / sync-to-mirrors (push) Failing after 0s
test plugins e2e (mobile) / android (push) Failing after 0s
test plugins e2e / test (map[name:Linux os:ubuntu-latest]) (push) Failing after 0s
Test Rust / changes (push) Failing after 0s
Lint Rust / changes (push) Failing after 0s
Lint Rust / clippy (push) Has been skipped
Audit Rust / audit-rust (push) Failing after 1s
Audit JavaScript / audit-js (push) Failing after 1s

This commit is contained in:
upstream-mirror
2026-09-23 17:17:10 +05:00
commit 9ad64ec987
1469 changed files with 115067 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
#[tauri::command]
pub fn locale() -> Option<String> {
crate::locale()
}
#[tauri::command]
pub fn hostname() -> String {
crate::hostname()
}

20
plugins/os/src/error.rs Normal file
View File

@@ -0,0 +1,20 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use serde::{Serialize, Serializer};
/// All errors that can occur while running the os plugin.
///
/// This enum currently has no variants: none of the plugin's commands can fail.
#[derive(Debug, thiserror::Error)]
pub enum Error {}
impl Serialize for Error {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(self.to_string().as_ref())
}
}

16
plugins/os/src/init.js Normal file
View File

@@ -0,0 +1,16 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
// eslint-disable-next-line
Object.defineProperty(window, '__TAURI_OS_PLUGIN_INTERNALS__', {
value: {
eol: __TEMPLATE_eol__,
os_type: __TEMPLATE_os_type__,
platform: __TEMPLATE_platform__,
family: __TEMPLATE_family__,
version: __TEMPLATE_version__,
arch: __TEMPLATE_arch__,
exe_extension: __TEMPLATE_exe_extension__
}
})

150
plugins/os/src/lib.rs Normal file
View File

@@ -0,0 +1,150 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
//! Read information about the operating system.
#![doc(
html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png",
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
)]
use std::fmt::Display;
pub use os_info::Version;
use serialize_to_javascript::{default_template, DefaultTemplate, Template};
use tauri::{
plugin::{Builder, TauriPlugin},
Runtime,
};
mod commands;
mod error;
pub use error::Error;
/// The type of the current operating system, as returned by [`type_`].
pub enum OsType {
/// Linux and Linux-based systems such as FreeBSD, DragonFly BSD, NetBSD and OpenBSD.
Linux,
/// Windows.
Windows,
/// macOS.
Macos,
/// iOS.
IOS,
/// Android.
Android,
}
impl Display for OsType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Linux => write!(f, "linux"),
Self::Windows => write!(f, "windows"),
Self::Macos => write!(f, "macos"),
Self::IOS => write!(f, "ios"),
Self::Android => write!(f, "android"),
}
}
}
/// Returns a string describing the specific operating system in use, see [std::env::consts::OS].
pub fn platform() -> &'static str {
std::env::consts::OS
}
/// Returns the current operating system version.
pub fn version() -> Version {
os_info::get().version().clone()
}
/// Returns the current operating system type.
pub fn type_() -> OsType {
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
return OsType::Linux;
#[cfg(target_os = "windows")]
return OsType::Windows;
#[cfg(target_os = "macos")]
return OsType::Macos;
#[cfg(target_os = "ios")]
return OsType::IOS;
#[cfg(target_os = "android")]
return OsType::Android;
}
/// Returns the current operating system family, see [std::env::consts::FAMILY].
pub fn family() -> &'static str {
std::env::consts::FAMILY
}
/// Returns the current operating system architecture, see [std::env::consts::ARCH].
pub fn arch() -> &'static str {
std::env::consts::ARCH
}
/// Returns the file extension, if any, used for executable binaries on this platform. Example value is `exe`, see [std::env::consts::EXE_EXTENSION].
pub fn exe_extension() -> &'static str {
std::env::consts::EXE_EXTENSION
}
/// Returns the current operating system locale with the `BCP-47` language tag. If the locale couldn't be obtained, `None` is returned instead.
pub fn locale() -> Option<String> {
sys_locale::get_locale()
}
/// Returns the current operating system hostname.
pub fn hostname() -> String {
gethostname::gethostname().to_string_lossy().to_string()
}
#[derive(Template)]
#[default_template("./init.js")]
struct InitJavascript<'a> {
eol: &'static str,
os_type: String,
platform: &'a str,
family: &'a str,
version: String,
arch: &'a str,
exe_extension: &'a str,
}
impl InitJavascript<'_> {
fn new() -> Self {
Self {
#[cfg(windows)]
eol: "\r\n",
#[cfg(not(windows))]
eol: "\n",
os_type: crate::type_().to_string(),
platform: crate::platform(),
family: crate::family(),
version: crate::version().to_string(),
arch: crate::arch(),
exe_extension: crate::exe_extension(),
}
}
}
/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
let init_js = InitJavascript::new()
.render_default(&Default::default())
// this will never fail with the above global_os_api values
.unwrap();
Builder::new("os")
.js_init_script(init_js.to_string())
.invoke_handler(tauri::generate_handler![
commands::locale,
commands::hostname
])
.build()
}