OS Information
Read information about the operating system using the OS Information plugin.
Setup
Install the OS Information plugin to get started.
Use your project’s package manager to add the dependency:
npm run tauri add osyarn run tauri add ospnpm tauri add osbun tauri add oscargo tauri add os-
Run
cargo add tauri-plugin-osto add the plugin to the project’s dependencies inCargo.toml. -
Modify
lib.rsto initialize the plugin:lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default()// Initialize the plugin.plugin(tauri_plugin_os::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
If you’d like to use in JavaScript then install the npm package as well:
npm install @tauri-apps/plugin-osyarn add @tauri-apps/plugin-ospnpm add @tauri-apps/plugin-osbun add @tauri-apps/plugin-os
Usage
With this plugin you can query multiple information from current operational system. See all available functions in the JavaScript API or Rust API references.
Example: OS Platform
platform returns a string describing the specific operating system in use. The value is set at compile time. Possible values are linux, macos, ios, freebsd, dragonfly, netbsd, openbsd, solaris, android, windows.
import { platform } from '@tauri-apps/plugin-os';
const currentPlatform = await platform();console.log(currentPlatform);// Prints "windows" to the consolelet platform = tauri_plugin_os::platform();println!("Platform: {}", platform);// Prints "windows" to the terminalPermissions
By default all plugin commands are blocked and cannot be accessed.
You must define a list of permissions in your capabilities configuration.
See Permissions Overview for more information.
{ "permissions": [ ..., "os:allow-arch", "os:allow-hostname", "os:allow-os-type" ]}| Permission | Description |
|---|---|
os:allow-arch | Enables the arch command without any pre-configured scope. |
os:deny-arch | Denies the arch command without any pre-configured scope. |
os:allow-exe-extension | Enables the exe-extension command without any pre-configured scope. |
os:deny-exe-extension | Denies the exe-extension command without any pre-configured scope. |
os:allow-family | Enables the family command without any pre-configured scope. |
os:deny-family | Denies the family command without any pre-configured scope. |
os:allow-hostname | Enables the hostname command without any pre-configured scope. |
os:deny-hostname | Denies the hostname command without any pre-configured scope. |
os:allow-locale | Enables the locale command without any pre-configured scope. |
os:deny-locale | Denies the locale command without any pre-configured scope. |
os:allow-os-type | Enables the os-type command without any pre-configured scope. |
os:deny-os-type | Denies the os-type command without any pre-configured scope. |
os:allow-platform | Enables the platform command without any pre-configured scope. |
os:deny-platform | Denies the platform command without any pre-configured scope. |
os:allow-version | Enables the version command without any pre-configured scope. |
os:deny-version | Denies the version command without any pre-configured scope. |
© 2024 Tauri Contributors. CC-BY / MIT