Skip to content

Commit 060de5b

Browse files
feat(api): implement getIdentifier() to access tauri.conf.json identifier (#12837)
* feat(api): implement getIdentifier() to access tauri.conf.json identifier * updated * chore(api): update change file and rebuild bundle * Update to @SInCE 2.4.0 * added tag * Update .changes/get-identifier.md Co-authored-by: Fabian-Lars <[email protected]> --------- Co-authored-by: Fabian-Lars <[email protected]>
1 parent c698a6d commit 060de5b

File tree

6 files changed

+58
-1
lines changed

6 files changed

+58
-1
lines changed

.changes/get-identifier.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": "minor:feat"
3+
"@tauri-apps/api": "minor:feat"
4+
---
5+
6+
Added `getIdentifier()` function to get the application identifier configured in tauri.conf.json

crates/tauri/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
148148
("version", true),
149149
("name", true),
150150
("tauri_version", true),
151+
("identifier", true),
151152
("app_show", false),
152153
("app_hide", false),
153154
("default_window_icon", false),

crates/tauri/permissions/app/autogenerated/reference.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Default permissions for the plugin.
55
- `allow-version`
66
- `allow-name`
77
- `allow-tauri-version`
8+
- `allow-identifier`
89

910
## Permission Table
1011

@@ -96,6 +97,32 @@ Denies the default_window_icon command without any pre-configured scope.
9697
<tr>
9798
<td>
9899

100+
`core:app:allow-identifier`
101+
102+
</td>
103+
<td>
104+
105+
Enables the identifier command without any pre-configured scope.
106+
107+
</td>
108+
</tr>
109+
110+
<tr>
111+
<td>
112+
113+
`core:app:deny-identifier`
114+
115+
</td>
116+
<td>
117+
118+
Denies the identifier command without any pre-configured scope.
119+
120+
</td>
121+
</tr>
122+
123+
<tr>
124+
<td>
125+
99126
`core:app:allow-name`
100127

101128
</td>

crates/tauri/scripts/bundle.global.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tauri/src/app/plugin.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ pub fn tauri_version() -> &'static str {
2525
crate::VERSION
2626
}
2727

28+
#[command(root = "crate")]
29+
pub fn identifier<R: Runtime>(app: AppHandle<R>) -> String {
30+
app.config().identifier.clone()
31+
}
32+
2833
#[command(root = "crate")]
2934
#[allow(unused_variables)]
3035
pub fn app_show<R: Runtime>(app: AppHandle<R>) -> crate::Result<()> {
@@ -63,6 +68,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
6368
version,
6469
name,
6570
tauri_version,
71+
identifier,
6672
app_show,
6773
app_hide,
6874
default_window_icon,

packages/api/src/app.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ async function getTauriVersion(): Promise<string> {
5555
return invoke('plugin:app|tauri_version')
5656
}
5757

58+
/**
59+
* Gets the application identifier.
60+
* @example
61+
* ```typescript
62+
* import { getIdentifier } from '@tauri-apps/api/app';
63+
* const identifier = await getIdentifier();
64+
* ```
65+
*
66+
* @returns The application identifier as configured in `tauri.conf.json`.
67+
*
68+
* @since 2.4.0
69+
*/
70+
async function getIdentifier(): Promise<string> {
71+
return invoke('plugin:app|identifier')
72+
}
73+
5874
/**
5975
* Shows the application on macOS. This function does not automatically focus any specific app window.
6076
*
@@ -125,6 +141,7 @@ export {
125141
getName,
126142
getVersion,
127143
getTauriVersion,
144+
getIdentifier,
128145
show,
129146
hide,
130147
defaultWindowIcon,

0 commit comments

Comments
 (0)