From a1e40480c1bc20ce0202d8e12666aa8d79774968 Mon Sep 17 00:00:00 2001 From: Manuel Quarneti Date: Tue, 21 Sep 2021 21:24:09 +0200 Subject: [PATCH] Typing (api/os) (#2558) Co-authored-by: Lucas Nogueira Co-authored-by: lucasfernog Co-authored-by: Ngo Iok Ui (Wu Yu Wei) Co-authored-by: david Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: chip Co-authored-by: Amr Bashir <48618675+amrbashir@users.noreply.github.com> --- tooling/api/src/os.ts | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/tooling/api/src/os.ts b/tooling/api/src/os.ts index 7fede4f7e..81cdf8fae 100644 --- a/tooling/api/src/os.ts +++ b/tooling/api/src/os.ts @@ -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 { - return invokeTauriCommand({ +async function platform(): Promise { + return invokeTauriCommand({ __tauriModule: 'Os', message: { cmd: 'platform' @@ -58,11 +64,13 @@ async function version(): Promise { }) } +type OsType = LiteralUnion<'Linux' | 'Darwin' | 'Windows_NT', string> + /** * Returns `'Linux'` on Linux, `'Darwin'` on macOS, and `'Windows_NT'` on Windows. */ -async function type(): Promise { - return invokeTauriCommand({ +async function type(): Promise { + return invokeTauriCommand({ __tauriModule: 'Os', message: { cmd: 'type' @@ -70,11 +78,26 @@ async function type(): Promise { }) } +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 { - return invokeTauriCommand({ +async function arch(): Promise { + return invokeTauriCommand({ __tauriModule: 'Os', message: { cmd: 'arch' @@ -95,3 +118,4 @@ async function tempdir(): Promise { } export { EOL, platform, version, type, arch, tempdir } +export type { Platform, OsType, Arch }