forked from qodo-benchmark/tauri
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts
More file actions
292 lines (272 loc) · 6.02 KB
/
app.ts
File metadata and controls
292 lines (272 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { addPluginListener, invoke, PluginListener } from './core'
import { Image } from './image'
import { Theme } from './window'
/**
* Identifier type used for data stores on macOS and iOS.
*
* Represents a 128-bit identifier, commonly expressed as a 16-byte UUID.
*/
export type DataStoreIdentifier = [
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number
]
/**
* Bundle type of the current application.
*/
export enum BundleType {
/** Windows NSIS */
Nsis = 'nsis',
/** Windows MSI */
Msi = 'msi',
/** Linux Debian package */
Deb = 'deb',
/** Linux RPM */
Rpm = 'rpm',
/** Linux AppImage */
AppImage = 'appimage',
/** macOS app bundle */
App = 'app'
}
/**
* Application metadata and related APIs.
*
* @module
*/
/**
* Gets the application version.
* @example
* ```typescript
* import { getVersion } from '@tauri-apps/api/app';
* const appVersion = await getVersion();
* ```
*
* @since 1.0.0
*/
async function getVersion(): Promise<string> {
return invoke('plugin:app|version')
}
/**
* Gets the application name.
* @example
* ```typescript
* import { getName } from '@tauri-apps/api/app';
* const appName = await getName();
* ```
*
* @since 1.0.0
*/
async function getName(): Promise<string> {
return invoke('plugin:app|name')
}
/**
* Gets the Tauri framework version used by this application.
*
* @example
* ```typescript
* import { getTauriVersion } from '@tauri-apps/api/app';
* const tauriVersion = await getTauriVersion();
* ```
*
* @since 1.0.0
*/
async function getTauriVersion(): Promise<string> {
return invoke('plugin:app|tauri_version')
}
/**
* Gets the application identifier.
* @example
* ```typescript
* import { getIdentifier } from '@tauri-apps/api/app';
* const identifier = await getIdentifier();
* ```
*
* @returns The application identifier as configured in `tauri.conf.json`.
*
* @since 2.4.0
*/
async function getIdentifier(): Promise<string> {
return invoke('plugin:app|identifier')
}
/**
* Shows the application on macOS. This function does not automatically
* focus any specific app window.
*
* @example
* ```typescript
* import { show } from '@tauri-apps/api/app';
* await show();
* ```
*
* @since 1.2.0
*/
async function show(): Promise<void> {
return invoke('plugin:app|app_show')
}
/**
* Hides the application on macOS.
*
* @example
* ```typescript
* import { hide } from '@tauri-apps/api/app';
* await hide();
* ```
*
* @since 1.2.0
*/
async function hide(): Promise<void> {
return invoke('plugin:app|app_hide')
}
/**
* Fetches the data store identifiers on macOS and iOS.
*
* See https://developer.apple.com/documentation/webkit/wkwebsitedatastore for more information.
*
* @example
* ```typescript
* import { fetchDataStoreIdentifiers } from '@tauri-apps/api/app';
* const ids = await fetchDataStoreIdentifiers();
* ```
*
* @since 2.4.0
*/
async function fetchDataStoreIdentifiers(): Promise<DataStoreIdentifier[]> {
return invoke('plugin:app|fetch_data_store_identifiers')
}
/**
* Removes the data store with the given identifier.
*
* Note that any webview using this data store should be closed before running this API.
*
* See https://developer.apple.com/documentation/webkit/wkwebsitedatastore for more information.
*
* @example
* ```typescript
* import { fetchDataStoreIdentifiers, removeDataStore } from '@tauri-apps/api/app';
* for (const id of (await fetchDataStoreIdentifiers())) {
* await removeDataStore(id);
* }
* ```
*
* @since 2.4.0
*/
async function removeDataStore(uuid: DataStoreIdentifier): Promise<void> {
return invoke('plugin:app|remove_data_store', { uuid })
}
/**
* Gets the default window icon.
*
* @example
* ```typescript
* import { defaultWindowIcon } from '@tauri-apps/api/app';
* const icon = await defaultWindowIcon();
* ```
*
* @since 2.0.0
*/
async function defaultWindowIcon(): Promise<Image | null> {
return invoke<number | null>('plugin:app|default_window_icon').then((rid) =>
rid ? new Image(rid) : null
)
}
/**
* Sets the application's theme. Pass in `null` or `undefined` to follow
* the system theme.
*
* @example
* ```typescript
* import { setTheme } from '@tauri-apps/api/app';
* await setTheme('dark');
* ```
*
* #### Platform-specific
*
* - **iOS / Android:** Unsupported.
*
* @since 2.0.0
*/
async function setTheme(theme?: Theme | null): Promise<void> {
return invoke('plugin:app|set_app_theme', { theme })
}
/**
* Sets the dock visibility for the application on macOS.
*
* @param visible - Whether the dock should be visible or not.
*
* @example
* ```typescript
* import { setDockVisibility } from '@tauri-apps/api/app';
* await setDockVisibility(false);
* ```
*
* @since 2.5.0
*/
async function setDockVisibility(visible: boolean): Promise<void> {
return invoke('plugin:app|set_dock_visibility', { visible })
}
/**
* Gets the application bundle type.
*
* @example
* ```typescript
* import { getBundleType } from '@tauri-apps/api/app';
* const type = await getBundleType();
* ```
*
* @since 2.5.0
*/
async function getBundleType(): Promise<BundleType> {
return invoke('plugin:app|bundle_type')
}
/**
* Payload for the onBackButtonPress event.
*/
type OnBackButtonPressPayload = {
/** Whether the webview canGoBack property is true. */
canGoBack: boolean
}
/**
* Listens to the backButton event on Android.
* @param handler
*/
async function onBackButtonPress(
handler: (payload: OnBackButtonPressPayload) => void
): Promise<PluginListener> {
return addPluginListener<OnBackButtonPressPayload>(
'app',
'back-button',
handler
)
}
export {
getName,
getVersion,
getTauriVersion,
getIdentifier,
show,
hide,
defaultWindowIcon,
setTheme,
fetchDataStoreIdentifiers,
removeDataStore,
setDockVisibility,
getBundleType,
type OnBackButtonPressPayload,
onBackButtonPress
}