Files
tauri/tooling/api/src/process.ts
2022-06-12 21:44:33 -03:00

55 lines
1.3 KiB
TypeScript

// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/**
* Perform operations on the current process.
*
* This package is also accessible with `window.__TAURI__.process` when `tauri.conf.json > build > withGlobalTauri` is set to true.
* @module
*/
import { invokeTauriCommand } from './helpers/tauri'
/**
* Exits immediately with the given `exitCode`.
* @example
* ```typescript
* import { exit } from '@tauri-apps/api/process';
* await exit(1);
* ```
*
* @param exitCode The exit code to use.
* @returns A promise indicating the success or failure of the operation.
*/
async function exit(exitCode: number = 0): Promise<void> {
return invokeTauriCommand({
__tauriModule: 'Process',
message: {
cmd: 'exit',
exitCode
}
})
}
/**
* Exits the current instance of the app then relaunches it.
* @example
* ```typescript
* import { relaunch } from '@tauri-apps/api/process';
* await relaunch();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async function relaunch(): Promise<void> {
return invokeTauriCommand({
__tauriModule: 'Process',
message: {
cmd: 'relaunch'
}
})
}
export { exit, relaunch }