操作系统信息
使用 OS 信息插件阅读有关操作系统的信息。
¥Read information about the operating system using the OS Information plugin.
支持的平台
¥Supported Platforms
This plugin requires a Rust version of at least 1.77.2
Platform | Level | Notes |
---|---|---|
windows | ||
linux | ||
macos | ||
android | ||
ios |
设置
¥Setup
安装 OS 信息插件以开始使用。
¥Install the OS Information plugin to get started.
使用项目的包管理器添加依赖:
¥Use your project’s package manager to add the dependency:
npm run tauri add os
yarn run tauri add os
pnpm tauri add os
deno task tauri add os
bun tauri add os
cargo tauri add os
-
Run the following command in the
src-tauri
folder to add the plugin to the project’s dependencies inCargo.toml
:cargo add tauri-plugin-os -
Modify
lib.rs
to initialize the plugin:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().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-osdeno add npm:@tauri-apps/plugin-osbun add @tauri-apps/plugin-os
使用
¥Usage
使用此插件,你可以从当前操作系统查询多种信息。在 JavaScript API 参考中查看所有 JavaScript API。
¥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
返回一个字符串,描述正在使用的特定操作系统。该值在编译时设置。可能的值是 linux
、macos
、ios
、freebsd
、dragonfly
、netbsd
、openbsd
、solaris
、android
、windows
。
¥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';// when using `"withGlobalTauri": true`, you may use// const { platform } = window.__TAURI__.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
权限
¥Permissions
默认情况下,所有潜在危险的插件命令和范围都会被阻止,无法访问。你必须修改 capabilities
配置中的权限才能启用这些权限。
¥By default all potentially dangerous plugin commands and scopes are blocked and cannot be accessed. You must modify the permissions in your capabilities
configuration to enable these.
有关更详细的说明,请参阅 功能概述。
¥See the Capabilities Overview for more information and the step by step guide to use plugin permissions.
{ "permissions": [ ..., "os:default" ]}
Default Permission
This permission set configures which operating system information are available to gather from the frontend.
Granted Permissions
All information except the host name are available.
This default permission set includes the following:
allow-arch
allow-exe-extension
allow-family
allow-locale
allow-os-type
allow-platform
allow-version
Permission Table
Identifier | Description |
---|---|
|
Enables the arch command without any pre-configured scope. |
|
Denies the arch command without any pre-configured scope. |
|
Enables the exe_extension command without any pre-configured scope. |
|
Denies the exe_extension command without any pre-configured scope. |
|
Enables the family command without any pre-configured scope. |
|
Denies the family command without any pre-configured scope. |
|
Enables the hostname command without any pre-configured scope. |
|
Denies the hostname command without any pre-configured scope. |
|
Enables the locale command without any pre-configured scope. |
|
Denies the locale command without any pre-configured scope. |
|
Enables the os_type command without any pre-configured scope. |
|
Denies the os_type command without any pre-configured scope. |
|
Enables the platform command without any pre-configured scope. |
|
Denies the platform command without any pre-configured scope. |
|
Enables the version command without any pre-configured scope. |
|
Denies the version command without any pre-configured scope. |
Tauri v2.5 中文网 - 粤ICP备13048890号
Nodejs.cn 旗下网站