-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): Expose application metadata and functions to JS api - fix #…
- Loading branch information
Showing
16 changed files
with
6,306 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"tauri-api": minor | ||
"tauri": minor | ||
--- | ||
|
||
Added new Javascript API to extract `name`, `version`, `tauri version` from the running application. We exposed `relaunch` and `exit` as well to control your application state. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { invokeTauriCommand } from './helpers/tauri' | ||
|
||
/** | ||
* @name getVersion | ||
* @description Get application version | ||
* @returns {Promise<string>} Promise resolving to application version | ||
*/ | ||
async function getVersion(): Promise<string> { | ||
return invokeTauriCommand<string>({ | ||
__tauriModule: 'App', | ||
mainThread: true, | ||
message: { | ||
cmd: 'getAppVersion' | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* @name getName | ||
* @description Get application name | ||
* @returns {Promise<string>} Promise resolving to application name | ||
*/ | ||
async function getName(): Promise<string> { | ||
return invokeTauriCommand<string>({ | ||
__tauriModule: 'App', | ||
mainThread: true, | ||
message: { | ||
cmd: 'getAppName' | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* @name getTauriVersion | ||
* @description Get tauri version | ||
* @returns {Promise<string>} Promise resolving to tauri version | ||
*/ | ||
async function getTauriVersion(): Promise<string> { | ||
return invokeTauriCommand<string>({ | ||
__tauriModule: 'App', | ||
mainThread: true, | ||
message: { | ||
cmd: 'getTauriVersion' | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* @name exit | ||
* @description Exits immediately with exitCode. | ||
* @param [exitCode] defaults to 0. | ||
* @returns {Promise<void>} Application is closing, nothing is returned | ||
*/ | ||
async function exit(exitCode: Number = 0): Promise<void> { | ||
return invokeTauriCommand<string>({ | ||
__tauriModule: 'App', | ||
mainThread: true, | ||
message: { | ||
cmd: 'exit', | ||
exitCode | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* @name relaunch | ||
* @description Relaunches the app when current instance exits. | ||
* @returns {Promise<void>} Application is restarting, nothing is returned | ||
*/ | ||
async function relaunch(): Promise<void> { | ||
return invokeTauriCommand<string>({ | ||
__tauriModule: 'App', | ||
mainThread: true, | ||
message: { | ||
cmd: 'relaunch' | ||
} | ||
}) | ||
} | ||
|
||
export { getName, getVersion, getTauriVersion, relaunch, exit } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.