0
# Application Lifecycle & Metadata
1
2
The app module provides APIs for managing application lifecycle, retrieving metadata, and controlling application-level behavior across platforms.
3
4
## Capabilities
5
6
### Application Metadata
7
8
Retrieve information about the current application.
9
10
```typescript { .api }
11
/**
12
* Get the application version
13
* @returns Promise resolving to version string
14
*/
15
function getVersion(): Promise<string>;
16
17
/**
18
* Get the application name
19
* @returns Promise resolving to app name
20
*/
21
function getName(): Promise<string>;
22
23
/**
24
* Get the Tauri version being used
25
* @returns Promise resolving to Tauri version string
26
*/
27
function getTauriVersion(): Promise<string>;
28
29
/**
30
* Get the application identifier
31
* @returns Promise resolving to app identifier
32
*/
33
function getIdentifier(): Promise<string>;
34
35
/**
36
* Get the bundle type of the current application
37
* @returns Promise resolving to bundle type
38
*/
39
function getBundleType(): Promise<BundleType>;
40
41
enum BundleType {
42
/** Windows NSIS */
43
Nsis = 'nsis',
44
/** Windows MSI */
45
Msi = 'msi',
46
/** Linux Debian package */
47
Deb = 'deb',
48
/** Linux RPM package */
49
Rpm = 'rpm',
50
/** Linux AppImage */
51
AppImage = 'appimage',
52
/** macOS app bundle */
53
App = 'app'
54
}
55
```
56
57
**Usage Examples:**
58
59
```typescript
60
import { getVersion, getName, getTauriVersion, getBundleType } from '@tauri-apps/api/app';
61
62
// Get basic app information
63
const appName = await getName();
64
const appVersion = await getVersion();
65
const tauriVersion = await getTauriVersion();
66
67
console.log(`${appName} v${appVersion} (Tauri ${tauriVersion})`);
68
69
// Check bundle type for platform-specific behavior
70
const bundleType = await getBundleType();
71
if (bundleType === BundleType.App) {
72
console.log('Running on macOS');
73
} else if (bundleType === BundleType.Nsis || bundleType === BundleType.Msi) {
74
console.log('Running on Windows');
75
}
76
```
77
78
### Application Visibility
79
80
Control application visibility and focus, particularly on macOS.
81
82
```typescript { .api }
83
/**
84
* Show the application (macOS only)
85
* Does not automatically focus any specific window
86
* @returns Promise that resolves when operation completes
87
*/
88
function show(): Promise<void>;
89
90
/**
91
* Hide the application (macOS only)
92
* @returns Promise that resolves when operation completes
93
*/
94
function hide(): Promise<void>;
95
```
96
97
**Usage Examples:**
98
99
```typescript
100
import { show, hide } from '@tauri-apps/api/app';
101
102
// Show application in dock (macOS)
103
await show();
104
105
// Hide application from dock (macOS)
106
await hide();
107
```
108
109
### Application Theming
110
111
Control the application's theme appearance.
112
113
```typescript { .api }
114
/**
115
* Set the application theme
116
* @param theme - Theme to apply ('light', 'dark', or null for system default)
117
* @returns Promise that resolves when theme is applied
118
*/
119
function setTheme(theme?: Theme | null): Promise<void>;
120
121
type Theme = 'light' | 'dark';
122
```
123
124
**Usage Examples:**
125
126
```typescript
127
import { setTheme } from '@tauri-apps/api/app';
128
129
// Set dark theme
130
await setTheme('dark');
131
132
// Set light theme
133
await setTheme('light');
134
135
// Use system theme
136
await setTheme(null);
137
```
138
139
### Dock Management
140
141
Control dock visibility and behavior on macOS.
142
143
```typescript { .api }
144
/**
145
* Set dock icon visibility (macOS only)
146
* @param visible - Whether dock icon should be visible
147
* @returns Promise that resolves when visibility is set
148
*/
149
function setDockVisibility(visible: boolean): Promise<void>;
150
```
151
152
**Usage Examples:**
153
154
```typescript
155
import { setDockVisibility } from '@tauri-apps/api/app';
156
157
// Hide from dock (useful for background/menu bar apps)
158
await setDockVisibility(false);
159
160
// Show in dock
161
await setDockVisibility(true);
162
```
163
164
### Application Icon
165
166
Access the default window icon for the application.
167
168
```typescript { .api }
169
/**
170
* Get the default window icon
171
* @returns Promise resolving to Image instance or null if no icon
172
*/
173
function defaultWindowIcon(): Promise<Image | null>;
174
```
175
176
**Usage Example:**
177
178
```typescript
179
import { defaultWindowIcon } from '@tauri-apps/api/app';
180
181
const icon = await defaultWindowIcon();
182
if (icon) {
183
const size = await icon.size();
184
console.log(`Default icon size: ${size.width}x${size.height}`);
185
}
186
```
187
188
### Data Store Management
189
190
Manage application data stores and their lifecycle.
191
192
```typescript { .api }
193
/**
194
* Get identifiers for all data stores
195
* @returns Promise resolving to array of data store identifiers
196
*/
197
function fetchDataStoreIdentifiers(): Promise<DataStoreIdentifier[]>;
198
199
/**
200
* Remove a data store
201
* @param identifier - Data store identifier to remove
202
* @returns Promise that resolves when store is removed
203
*/
204
function removeDataStore(identifier: DataStoreIdentifier): Promise<void>;
205
206
type DataStoreIdentifier = [
207
number, number, number, number,
208
number, number, number, number,
209
number, number, number, number,
210
number, number, number, number
211
];
212
```
213
214
**Usage Examples:**
215
216
```typescript
217
import { fetchDataStoreIdentifiers, removeDataStore } from '@tauri-apps/api/app';
218
219
// List all data stores
220
const stores = await fetchDataStoreIdentifiers();
221
console.log(`Found ${stores.length} data stores`);
222
223
// Remove a specific data store
224
if (stores.length > 0) {
225
await removeDataStore(stores[0]);
226
console.log('Removed first data store');
227
}
228
```
229
230
## Platform-Specific Behavior
231
232
### macOS
233
- `show()` and `hide()` control application visibility in dock
234
- `setDockVisibility()` can create menu bar only applications
235
- Theme changes affect system-wide appearance in some cases
236
237
### Windows
238
- `show()` and `hide()` have limited effect, primarily for integration scenarios
239
- `setDockVisibility()` is a no-op
240
241
### Linux
242
- Most visibility functions are no-ops or have limited effect
243
- Behavior depends on desktop environment
244
245
## Error Handling
246
247
```typescript
248
import { getName, show } from '@tauri-apps/api/app';
249
250
try {
251
const name = await getName();
252
await show();
253
} catch (error) {
254
// Common error scenarios:
255
// - Permission denied
256
// - Platform not supported
257
// - Application state conflicts
258
console.error('App operation failed:', error);
259
}
260
```
261
262
## Integration Examples
263
264
```typescript
265
import { getName, getVersion, setTheme, setDockVisibility } from '@tauri-apps/api/app';
266
import { getCurrentWindow } from '@tauri-apps/api/window';
267
268
// Create a menu bar app
269
async function setupMenuBarApp() {
270
await setDockVisibility(false);
271
272
const window = getCurrentWindow();
273
await window.setSkipTaskbar(true);
274
await window.setAlwaysOnTop(true);
275
}
276
277
// Setup app info display
278
async function displayAppInfo() {
279
const name = await getName();
280
const version = await getVersion();
281
282
document.title = `${name} v${version}`;
283
}
284
285
// Theme synchronization
286
async function syncTheme() {
287
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
288
await setTheme(prefersDark ? 'dark' : 'light');
289
}
290
```