跳到主要內容

作業系統

提供與作業系統相關的實用程式方法和屬性。

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,以最佳化套件大小和安全性。

類型別名

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

變數

EOL

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

作業系統特定的行尾標記。

  • \n 在 POSIX
  • \r\n 在 Windows

: 1.0.0

定義於: os.ts:63

函式

arch

arch(): Promise<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();

: 1.0.0

傳回: Promise<Arch>

locale

locale(): Promise<string | null>

傳回包含 BCP-47 語言標籤的字串。如果無法取得 locale,則傳回 null

範例

import { locale } from '@tauri-apps/api/os';
const locale = await locale();
if (locale) {
// use the locale string here
}

: 1.4.0

傳回: Promise<string | null>

platform

platform(): Promise<Platform>

傳回識別作業系統平台的字串。此值在編譯時設定。可能的值為 'linux''darwin''ios''freebsd''dragonfly''netbsd''openbsd''solaris''android''win32'

範例

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

: 1.0.0

傳回:Promise<Platform>

tempdir

tempdir(): Promise<string>

傳回作業系統的預設暫存檔案目錄,為字串。

範例

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

: 1.0.0

傳回:Promise<string>

type

type(): Promise<OsType>

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

範例

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

: 1.0.0

傳回:Promise<OsType>

version

version(): Promise<string>

傳回識別核心版本的字串。

範例

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

: 1.0.0

傳回:Promise<string>