操作系统信息
使用操作系统信息插件读取操作系统信息。
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 osyarn run tauri add ospnpm tauri add osbun tauri add oscargo 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-osyarn add @tauri-apps/plugin-ospnpm add @tauri-apps/plugin-osbun 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 consolelet platform = tauri_plugin_os::platform();println!("Platform: {}", platform);// Prints "windows" to the terminal 
© 2024 Tauri中文网