操作系统信息
使用操作系统信息插件读取操作系统信息。
Supported Platforms
This plugin requires a Rust version of at least 1.77.2
Platform | Level | Notes |
---|---|---|
windows | ||
linux | ||
macos | ||
android | ||
ios |
设置
安装操作系统信息插件开始。
使用项目的包管理器来添加依赖:
npm run tauri add os
yarn run tauri add os
pnpm tauri add os
bun tauri add os
cargo tauri add os
-
运行
cargo add tauri-plugin-os
命令,将插件添加到项目的 cargo .toml 依赖中。 -
修改 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");}
- 如果你想在 JavaScript 中使用,还需要安装 npm 包。
npm install @tauri-apps/plugin-os
yarn add @tauri-apps/plugin-os
pnpm add @tauri-apps/plugin-os
bun add @tauri-apps/plugin-os
用法
通过这个插件,您可以查询当前操作系统的多个信息。请参阅 JavaScript API 或 Rust API 参考资料中的所有可用函数。
示例:操作系统平台
platform
返回一个描述使用的特定操作系统的字符串。该值在编译时设置。可能的值有 linux
、macos
、ios
、freebsd
、dragonfly
、netbsd
、openbsd
、solaris
、android
、windows
。
import { platform } from '@tauri-apps/plugin-os';
const currentPlatform = platform();console.log(currentPlatform);// Prints "windows" to the console
let platform = tauri_plugin_os::platform();println!("Platform: {}", platform);// Prints "windows" to the terminal
© 2025 Tauri Contributors. CC-BY / MIT