docs(api): add example for tauri://close-requested event usage

This commit is contained in:
Lucas Nogueira
2022-06-19 22:38:44 -03:00
parent 09241f9aca
commit 32f35196a3
2 changed files with 16 additions and 6 deletions

View File

@@ -247,8 +247,8 @@ async function ask(
* @example
* ```typescript
* import { confirm } from '@tauri-apps/api/dialog';
* const confirm = await confirm('Are you sure?', 'Tauri');
* const confirm2 = await confirm('This action cannot be reverted. Are you sure?', { title: 'Tauri', type: 'warning' });
* const confirmed = await confirm('Are you sure?', 'Tauri');
* const confirmed2 = await confirm('This action cannot be reverted. Are you sure?', { title: 'Tauri', type: 'warning' });
* ```
*
* @param {string} message The message to show.

View File

@@ -53,10 +53,10 @@
*
* Events can be listened using `appWindow.listen`:
* ```typescript
* import { appWindow } from '@tauri-apps/api/window'
* appWindow.listen('tauri://move', ({ event, payload }) => {
* const { x, y } = payload // payload here is a `PhysicalPosition`
* })
* import { appWindow } from "@tauri-apps/api/window"
* appWindow.listen("tauri://move", ({ event, payload }) => {
* const { x, y } = payload; // payload here is a `PhysicalPosition`
* });
* ```
*
* Window-specific events emitted by the backend:
@@ -78,6 +78,16 @@
* #### 'tauri://close-requested'
* Emitted when the user requests the window to be closed.
* If a listener is registered for this event, Tauri won't close the window so you must call `appWindow.close()` manually.
* ```typescript
* import { appWindow } from "@tauri-apps/api/window";
* import { confirm } from '@tauri-apps/api/dialog';
* appWindow.listen("tauri://close-requested", async ({ event, payload }) => {
* const confirmed = await confirm('Are you sure?');
* if (confirmed) {
* await appWindow.close();
* }
* });
* ```
*
* #### 'tauri://focus'
* Emitted when the window gains focus.