|
| 1 | +import { invokeTauriCommand } from './helpers/tauri' |
| 2 | + |
| 3 | +/** |
| 4 | + * @name getVersion |
| 5 | + * @description Get application version |
| 6 | + * @returns {Promise<string>} Promise resolving to application version |
| 7 | + */ |
| 8 | +async function getVersion(): Promise<string> { |
| 9 | + return invokeTauriCommand<string>({ |
| 10 | + __tauriModule: 'App', |
| 11 | + mainThread: true, |
| 12 | + message: { |
| 13 | + cmd: 'getAppVersion' |
| 14 | + } |
| 15 | + }) |
| 16 | +} |
| 17 | + |
| 18 | +/** |
| 19 | + * @name getName |
| 20 | + * @description Get application name |
| 21 | + * @returns {Promise<string>} Promise resolving to application name |
| 22 | + */ |
| 23 | +async function getName(): Promise<string> { |
| 24 | + return invokeTauriCommand<string>({ |
| 25 | + __tauriModule: 'App', |
| 26 | + mainThread: true, |
| 27 | + message: { |
| 28 | + cmd: 'getAppName' |
| 29 | + } |
| 30 | + }) |
| 31 | +} |
| 32 | + |
| 33 | +/** |
| 34 | + * @name getTauriVersion |
| 35 | + * @description Get tauri version |
| 36 | + * @returns {Promise<string>} Promise resolving to tauri version |
| 37 | + */ |
| 38 | +async function getTauriVersion(): Promise<string> { |
| 39 | + return invokeTauriCommand<string>({ |
| 40 | + __tauriModule: 'App', |
| 41 | + mainThread: true, |
| 42 | + message: { |
| 43 | + cmd: 'getTauriVersion' |
| 44 | + } |
| 45 | + }) |
| 46 | +} |
| 47 | + |
| 48 | +/** |
| 49 | + * @name exit |
| 50 | + * @description Exits immediately with exitCode. |
| 51 | + * @param [exitCode] defaults to 0. |
| 52 | + * @returns {Promise<void>} Application is closing, nothing is returned |
| 53 | + */ |
| 54 | +async function exit(exitCode: Number = 0): Promise<void> { |
| 55 | + return invokeTauriCommand<string>({ |
| 56 | + __tauriModule: 'App', |
| 57 | + mainThread: true, |
| 58 | + message: { |
| 59 | + cmd: 'exit', |
| 60 | + exitCode |
| 61 | + } |
| 62 | + }) |
| 63 | +} |
| 64 | + |
| 65 | +/** |
| 66 | + * @name relaunch |
| 67 | + * @description Relaunches the app when current instance exits. |
| 68 | + * @returns {Promise<void>} Application is restarting, nothing is returned |
| 69 | + */ |
| 70 | +async function relaunch(): Promise<void> { |
| 71 | + return invokeTauriCommand<string>({ |
| 72 | + __tauriModule: 'App', |
| 73 | + mainThread: true, |
| 74 | + message: { |
| 75 | + cmd: 'relaunch' |
| 76 | + } |
| 77 | + }) |
| 78 | +} |
| 79 | + |
| 80 | +export { getName, getVersion, getTauriVersion, relaunch, exit } |
0 commit comments