Typing (api/os) (#2558)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
Co-authored-by: lucasfernog <lucasfernog@users.noreply.github.com>
Co-authored-by: Ngo Iok Ui (Wu Yu Wei) <wusyong9104@gmail.com>
Co-authored-by: david <david@lemarier.ca>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: chip <chip@chip.sh>
Co-authored-by: Amr Bashir <48618675+amrbashir@users.noreply.github.com>
This commit is contained in:
Manuel Quarneti
2021-09-21 21:24:09 +02:00
committed by GitHub
parent fe381a0bde
commit a1e40480c1

View File

@@ -23,6 +23,7 @@
* @module
*/
import { LiteralUnion } from 'type-fest'
import { isWindows } from './helpers/os-check'
import { invokeTauriCommand } from './helpers/tauri'
@@ -33,12 +34,17 @@ import { invokeTauriCommand } from './helpers/tauri'
* */
const EOL = isWindows() ? '\r\n' : '\n'
type Platform = LiteralUnion<
'aix' | 'darwin' | 'freebsd' | 'linux' | 'openbsd' | 'sunos' | 'win32',
string
>
/**
* Returns a string identifying the operating system platform.
* The value is set at compile time. Possible values are `'aix'`, `'darwin'`, `'freebsd'`, `'linux'`, `'openbsd'`, `'sunos'`, and `'win32'`.
*/
async function platform(): Promise<string> {
return invokeTauriCommand<string>({
async function platform(): Promise<Platform> {
return invokeTauriCommand<Platform>({
__tauriModule: 'Os',
message: {
cmd: 'platform'
@@ -58,11 +64,13 @@ async function version(): Promise<string> {
})
}
type OsType = LiteralUnion<'Linux' | 'Darwin' | 'Windows_NT', string>
/**
* Returns `'Linux'` on Linux, `'Darwin'` on macOS, and `'Windows_NT'` on Windows.
*/
async function type(): Promise<string> {
return invokeTauriCommand<string>({
async function type(): Promise<OsType> {
return invokeTauriCommand<OsType>({
__tauriModule: 'Os',
message: {
cmd: 'type'
@@ -70,11 +78,26 @@ async function type(): Promise<string> {
})
}
type Arch = LiteralUnion<
| 'x86'
| 'x86_64'
| 'arm'
| 'aarch64'
| 'mips'
| 'mips64'
| 'powerpc'
| 'powerpc64'
| 'riscv64'
| 's390x'
| 'sparc64',
string
>
/**
* 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'`
*/
async function arch(): Promise<string> {
return invokeTauriCommand<string>({
async function arch(): Promise<Arch> {
return invokeTauriCommand<Arch>({
__tauriModule: 'Os',
message: {
cmd: 'arch'
@@ -95,3 +118,4 @@ async function tempdir(): Promise<string> {
}
export { EOL, platform, version, type, arch, tempdir }
export type { Platform, OsType, Arch }