操作系统(os)

提供与操作系统相关的实用方法和属性。

tauri.conf.json 中的 build.withGlobalTauri 设置为 true 时,可以通过 window.__TAURI__.os 访问此包。

这些 API 必须添加到 tauri.conf.json 中的 tauri.allowlist.os 中:

{
  "tauri": {
    "allowlist": {
      "os": {
        "all": true, // enable all Os APIs
      }
    }
  }
}

建议仅将您使用的 API 列入白名单,以获得最佳的包大小和安全性。

Type Aliases

Arch

  • Arch: "x86" | "x86_64" | "arm" | "aarch64" | "mips" | "mips64" | "powerpc" | "powerpc64" | "riscv64" | "s390x" | "sparc64"

定义在: os.ts:43

OsType

  • OsType: "Linux" | "Darwin" | "Windows_NT"

定义在: os.ts:41

Platform

  • Platform: "linux" | "darwin" | "ios" | "freebsd" | "dragonfly" | "netbsd" | "openbsd" | "solaris" | "android" | "win32"

定义在: os.ts:29

Variables

EOL

  • Const EOL: "\n" | "\r\n"

返回特定于操作系统的行尾标记。

  • \n on POSIX

  • \r\n on Windows

Since: 1.0.0

定义在: os.ts:63

Functions

arch

返回为 tauri 应用编译的操作系统 CPU 架构。可能的值有 'x86''x86_64''arm''aarch64''mips''mips64''powerpc''powerpc64''riscv64''s390x''sparc64'

示例

import { arch } from '@tauri-apps/api/os';
const archName = await arch();

Since: 1.0.0

返回: Promise<Arch>

platform

返回标识操作系统平台的字符串。该值在编译时设置。可能的值有 'linux''darwin''ios''freebsd''dragonfly''netbsd''openbsd''solaris''android''win32'

示例

import { platform } from '@tauri-apps/api/os';
const platformName = await platform();

Since: 1.0.0

返回: Promise<Platform>

tempdir

返回操作系统默认的临时文件目录的字符串。

示例

import { tempdir } from '@tauri-apps/api/os';
const tempdirPath = await tempdir();

Since: 1.0.0

返回: Promise<string>

type

在 Linux 上返回 'Linux',在 macOS 上返回 'Darwin',在 Windows 上返回 'Windows_NT'

示例

import { type } from '@tauri-apps/api/os';
const osType = await type();

Since: 1.0.0

返回: Promise<OsType>

version

返回标识内核版本的字符串。

示例

import { version } from '@tauri-apps/api/os';
const osVersion = await version();

Since: 1.0.0

返回: Promise<string>