app.cjs 2.8 KB

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