os
提供与操作系统相关的实用程序方法和属性。
当 tauri.conf.json 中的 build.withGlobalTauri 设置为 true 时,也可以通过 window.__TAURI__.os 访问此软件包。
API 必须添加到 tauri.conf.json 中的 tauri.allowlist.os 中:
{
"tauri": {
"allowlist": {
"os": {
"all": true, // 启用所有Os API
}
}
}
}
建议只允许列出您使用的 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
ConstEOL:"\n"|"\r\n"
操作系统专用的行结束标记。
\non POSIX\r\non Windows
自1.0.0版本起
定义在: os.ts:63
方法
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版本起
locale
locale():
Promise<string|null>
返回包含BCP-47语言标记的字符串。如果无法获取语言环境,则返回null。
示例
import { locale } from '@tauri-apps/api/os';
const locale = await locale();
if (locale) {
// 在此处使用 locale 字符串
}
自1.4.0版本起
返回值: Promise<string | null>
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版本起
tempdir
tempdir():
Promise<string>
以字符串形式返回操作系统默认的临时文件目录。
示例
import { tempdir } from '@tauri-apps/api/os';
const tempdirPath = await tempdir();
自1.0.0版本起
返回值: Promise<string>
type
在 Linux 上返回 Linux,在 macOS 上返回 Darwin,在 Windows 上返回 Windows_NT。
示例
import { type } from '@tauri-apps/api/os';
const osType = await type();
自1.0.0版本起
version
version():
Promise<string>
返回内核版本的字符串。
示例
import { version } from '@tauri-apps/api/os';
const osVersion = await version();
自1.0.0版本起
返回值: Promise<string>