Skip to content
Tauri 中文网

操作系统信息

使用 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.

使用项目的包管理器添加依赖:

npm run tauri add os

🌐 Usage

使用此插件,你可以查询当前操作系统的多种信息。请参阅 JavaScript APIRust 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 返回一个描述正在使用的特定操作系统的字符串。该值在编译时设置。可能的值是 linuxmacosiosfreebsddragonflynetbsdopenbsdsolarisandroidwindows

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

🌐 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.

src-tauri/capabilities/default.json
{
"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

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.


Tauri 中文网 - 粤ICP备13048890号
Nodejs.cn 旗下网站