process.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2019-2022 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. /**
  5. * Perform operations on the current process.
  6. *
  7. * This package is also accessible with `window.__TAURI__.process` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.
  8. * @module
  9. */
  10. import { invokeTauriCommand } from './helpers/tauri'
  11. /**
  12. * Exits immediately with the given `exitCode`.
  13. * @example
  14. * ```typescript
  15. * import { exit } from '@tauri-apps/api/process';
  16. * await exit(1);
  17. * ```
  18. *
  19. * @param exitCode The exit code to use.
  20. * @returns A promise indicating the success or failure of the operation.
  21. *
  22. * @since 1.0.0
  23. */
  24. async function exit(exitCode: number = 0): Promise<void> {
  25. return invokeTauriCommand({
  26. __tauriModule: 'Process',
  27. message: {
  28. cmd: 'exit',
  29. exitCode
  30. }
  31. })
  32. }
  33. /**
  34. * Exits the current instance of the app then relaunches it.
  35. * @example
  36. * ```typescript
  37. * import { relaunch } from '@tauri-apps/api/process';
  38. * await relaunch();
  39. * ```
  40. *
  41. * @returns A promise indicating the success or failure of the operation.
  42. *
  43. * @since 1.0.0
  44. */
  45. async function relaunch(): Promise<void> {
  46. return invokeTauriCommand({
  47. __tauriModule: 'Process',
  48. message: {
  49. cmd: 'relaunch'
  50. }
  51. })
  52. }
  53. export { exit, relaunch }