跳转到内容
Tauri

操作系统信息

使用操作系统信息插件读取操作系统信息。

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

用法

通过这个插件,您可以查询当前操作系统的多个信息。请参阅 JavaScript APIRust API 参考资料中的所有可用函数。

示例:操作系统平台

platform 返回一个描述使用的特定操作系统的字符串。该值在编译时设置。可能的值有 linuxmacosiosfreebsddragonflynetbsdopenbsdsolarisandroidwindows

import { platform } from '@tauri-apps/plugin-os';
// 当设置 `"withGlobalTauri": true` 时,你可以用
// const { platform } = window.__TAURI__.os;
const currentPlatform = platform();
console.log(currentPlatform);
// 将 "windows" 输出到控制台

权限

默认情况下,所有具有潜在危险的插件命令和范围都会被阻止且无法访问。您必须修改 capabilities 文件夹中的配置来启用它们。

参见能力概览以获取更多信息,以及插件的分步导览来调整插件权限。

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.


© 2025 Tauri Contributors. CC-BY / MIT