操作系统
提供与操作系统相关的实用程序方法和属性。
当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
ConstEOL:"\r\n"|"\n"
操作系统特定的行尾标记。
\n在 POSIX 系统上\r\n在 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) {
// use the locale string here
}
自: 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>