浏览代码

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

Lucas Nogueira 3 年之前
父节点
当前提交
32f35196a3
共有 2 个文件被更改,包括 16 次插入6 次删除
  1. 2 2
      tooling/api/src/dialog.ts
  2. 14 4
      tooling/api/src/window.ts

+ 2 - 2
tooling/api/src/dialog.ts

@@ -247,8 +247,8 @@ async function ask(
  * @example
  * @example
  * ```typescript
  * ```typescript
  * import { confirm } from '@tauri-apps/api/dialog';
  * 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.
  * @param {string} message The message to show.

+ 14 - 4
tooling/api/src/window.ts

@@ -53,10 +53,10 @@
  *
  *
  * Events can be listened using `appWindow.listen`:
  * Events can be listened using `appWindow.listen`:
  * ```typescript
  * ```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:
  * Window-specific events emitted by the backend:
@@ -78,6 +78,16 @@
  * #### 'tauri://close-requested'
  * #### 'tauri://close-requested'
  * Emitted when the user requests the window to be closed.
  * 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.
  * 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'
  * #### 'tauri://focus'
  * Emitted when the window gains focus.
  * Emitted when the window gains focus.