app.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { invokeTauriCommand } from './helpers/tauri.js';
  2. // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
  3. // SPDX-License-Identifier: Apache-2.0
  4. // SPDX-License-Identifier: MIT
  5. /**
  6. * Get application metadata.
  7. *
  8. * This package is also accessible with `window.__TAURI__.app` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.
  9. *
  10. * The APIs must be added to [`tauri.allowlist.app`](https://tauri.app/v1/api/config/#allowlistconfig.app) in `tauri.conf.json`:
  11. * ```json
  12. * {
  13. * "tauri": {
  14. * "allowlist": {
  15. * "app": {
  16. * "all": true, // enable all app APIs
  17. * "show": true,
  18. * "hide": true
  19. * }
  20. * }
  21. * }
  22. * }
  23. * ```
  24. * It is recommended to allowlist only the APIs you use for optimal bundle size and security.
  25. *
  26. * @module
  27. */
  28. /**
  29. * Gets the application version.
  30. * @example
  31. * ```typescript
  32. * import { getVersion } from '@tauri-apps/api/app';
  33. * const appVersion = await getVersion();
  34. * ```
  35. *
  36. * @since 1.0.0
  37. */
  38. async function getVersion() {
  39. return invokeTauriCommand({
  40. __tauriModule: 'App',
  41. message: {
  42. cmd: 'getAppVersion'
  43. }
  44. });
  45. }
  46. /**
  47. * Gets the application name.
  48. * @example
  49. * ```typescript
  50. * import { getName } from '@tauri-apps/api/app';
  51. * const appName = await getName();
  52. * ```
  53. *
  54. * @since 1.0.0
  55. */
  56. async function getName() {
  57. return invokeTauriCommand({
  58. __tauriModule: 'App',
  59. message: {
  60. cmd: 'getAppName'
  61. }
  62. });
  63. }
  64. /**
  65. * Gets the Tauri version.
  66. *
  67. * @example
  68. * ```typescript
  69. * import { getTauriVersion } from '@tauri-apps/api/app';
  70. * const tauriVersion = await getTauriVersion();
  71. * ```
  72. *
  73. * @since 1.0.0
  74. */
  75. async function getTauriVersion() {
  76. return invokeTauriCommand({
  77. __tauriModule: 'App',
  78. message: {
  79. cmd: 'getTauriVersion'
  80. }
  81. });
  82. }
  83. /**
  84. * Shows the application on macOS. This function does not automatically focus any specific app window.
  85. *
  86. * @example
  87. * ```typescript
  88. * import { show } from '@tauri-apps/api/app';
  89. * await show();
  90. * ```
  91. *
  92. * @since 1.2.0
  93. */
  94. async function show() {
  95. return invokeTauriCommand({
  96. __tauriModule: 'App',
  97. message: {
  98. cmd: 'show'
  99. }
  100. });
  101. }
  102. /**
  103. * Hides the application on macOS.
  104. *
  105. * @example
  106. * ```typescript
  107. * import { hide } from '@tauri-apps/api/app';
  108. * await hide();
  109. * ```
  110. *
  111. * @since 1.2.0
  112. */
  113. async function hide() {
  114. return invokeTauriCommand({
  115. __tauriModule: 'App',
  116. message: {
  117. cmd: 'hide'
  118. }
  119. });
  120. }
  121. export { getName, getTauriVersion, getVersion, hide, show };