-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
os.ts
151 lines (139 loc) · 3.4 KB
/
os.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/**
* Provides operating system-related utility methods and properties.
*
* This package is also accessible with `window.__TAURI__.os` when `tauri.conf.json > build > withGlobalTauri` is set to true.
*
* The APIs must be allowlisted on `tauri.conf.json`:
* ```json
* {
* "tauri": {
* "allowlist": {
* "os": {
* "all": true, // enable all Os APIs
* }
* }
* }
* }
* ```
* It is recommended to allowlist only the APIs you use for optimal bundle size and security.
* @module
*/
import { isWindows } from './helpers/os-check'
import { invokeTauriCommand } from './helpers/tauri'
type Platform =
| 'linux'
| 'darwin'
| 'ios'
| 'freebsd'
| 'dragonfly'
| 'netbsd'
| 'openbsd'
| 'solaris'
| 'android'
| 'win32'
type OsType = 'Linux' | 'Darwin' | 'Windows_NT'
type Arch =
| 'x86'
| 'x86_64'
| 'arm'
| 'aarch64'
| 'mips'
| 'mips64'
| 'powerpc'
| 'powerpc64'
| 'riscv64'
| 's390x'
| 'sparc64'
/**
* The operating system-specific end-of-line marker.
* - `\n` on POSIX
* - `\r\n` on Windows
* */
const EOL = isWindows() ? '\r\n' : '\n'
/**
* Returns a string identifying the operating system platform.
* The value is set at compile time. Possible values are `'linux'`, `'darwin'`, `'ios'`, `'freebsd'`, `'dragonfly'`, `'netbsd'`, `'openbsd'`, `'solaris'`, `'android'`, `'win32'`
* @example
* ```typescript
* import { platform } from '@tauri-apps/api/os';
* const platformName = await platform();
* ```
*/
async function platform(): Promise<Platform> {
return invokeTauriCommand<Platform>({
__tauriModule: 'Os',
message: {
cmd: 'platform'
}
})
}
/**
* Returns a string identifying the kernel version.
* @example
* ```typescript
* import { version } from '@tauri-apps/api/os';
* const osVersion = await version();
* ```
*/
async function version(): Promise<string> {
return invokeTauriCommand<string>({
__tauriModule: 'Os',
message: {
cmd: 'version'
}
})
}
/**
* Returns `'Linux'` on Linux, `'Darwin'` on macOS, and `'Windows_NT'` on Windows.
* @example
* ```typescript
* import { type } from '@tauri-apps/api/os';
* const osType = await type();
* ```
*/
async function type(): Promise<OsType> {
return invokeTauriCommand<OsType>({
__tauriModule: 'Os',
message: {
cmd: 'osType'
}
})
}
/**
* Returns the operating system CPU architecture for which the tauri app was compiled.
* Possible values are `'x86'`, `'x86_64'`, `'arm'`, `'aarch64'`, `'mips'`, `'mips64'`, `'powerpc'`, `'powerpc64'`, `'riscv64'`, `'s390x'`, `'sparc64'`.
* @example
* ```typescript
* import { arch } from '@tauri-apps/api/os';
* const archName = await arch();
* ```
*/
async function arch(): Promise<Arch> {
return invokeTauriCommand<Arch>({
__tauriModule: 'Os',
message: {
cmd: 'arch'
}
})
}
/**
* Returns the operating system's default directory for temporary files as a string.
* @example
* ```typescript
* import { tempdir } from '@tauri-apps/api/os';
* const tempdirPath = await tempdir();
* ```
*/
async function tempdir(): Promise<string> {
return invokeTauriCommand<string>({
__tauriModule: 'Os',
message: {
cmd: 'tempdir'
}
})
}
export { EOL, platform, version, type, arch, tempdir }
export type { Platform, OsType, Arch }