Skip to content

Commit f68603a

Browse files
committed
chore(docs): simplify event system documentation
1 parent 4866404 commit f68603a

File tree

7 files changed

+20
-13
lines changed

7 files changed

+20
-13
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": patch
3+
---
4+
5+
Change `WindowLabel` type to `string`.

core/tauri/scripts/bundle.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.

docs/usage/guides/events.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ emit('click', {
3636
Window-specific events are exposed on the `window` module.
3737

3838
```ts
39-
import { getCurrent, WebviewWindow } from '@tauri-apps/api/window'
39+
import { appWindow, WebviewWindow } from '@tauri-apps/api/window'
4040

4141
// emit an event that are only visible to the current window
42-
const current = getCurrent()
43-
current.emit('event', { message: 'Tauri is awesome!' })
42+
appWindow.emit('event', { message: 'Tauri is awesome!' })
4443

4544
// create a new webview window and emit an event only to that window
4645
const webview = new WebviewWindow('window')

examples/api/public/build/bundle.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/api/public/build/bundle.js.map

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

examples/api/src/components/Window.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<script>
2-
import { appWindow, WebviewWindow, LogicalSize, LogicalPosition, UserAttentionType, getCurrent, PhysicalSize, PhysicalPosition } from "@tauri-apps/api/window";
2+
import { appWindow, WebviewWindow, LogicalSize, LogicalPosition, UserAttentionType, PhysicalSize, PhysicalPosition } from "@tauri-apps/api/window";
33
import { open as openDialog } from "@tauri-apps/api/dialog";
44
import { open } from "@tauri-apps/api/shell";
55
66
window.UserAttentionType = UserAttentionType;
7-
let selectedWindow = getCurrent().label;
7+
let selectedWindow = appWindow.label;
88
const windowMap = {
99
[selectedWindow]: appWindow
1010
}

tooling/api/src/window.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ function getAll(): WebviewWindow[] {
220220
// events that are emitted right here instead of by the created webview
221221
const localTauriEvents = ['tauri://created', 'tauri://error']
222222
/** @ignore */
223-
export type WindowLabel = string | null | undefined
223+
export type WindowLabel = string
224224
/**
225225
* A webview window handle allows emitting and listening to events from the backend that are tied to the window.
226226
*/
@@ -230,8 +230,8 @@ class WebviewWindowHandle {
230230
/** Local event listeners. */
231231
listeners: { [key: string]: Array<EventCallback<any>> }
232232

233-
constructor(label: WindowLabel) {
234-
this.label = label
233+
constructor(label: WindowLabel | null | undefined) {
234+
this.label = label ?? window.__TAURI__.__currentWindow.label
235235
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
236236
this.listeners = Object.create(null)
237237
}
@@ -1092,7 +1092,10 @@ class WindowManager extends WebviewWindowHandle {
10921092
* ```
10931093
*/
10941094
class WebviewWindow extends WindowManager {
1095-
constructor(label: WindowLabel, options: WindowOptions = {}) {
1095+
constructor(
1096+
label: WindowLabel | null | undefined,
1097+
options: WindowOptions = {}
1098+
) {
10961099
super(label)
10971100
// @ts-expect-error
10981101
if (!options?.skip) {

0 commit comments

Comments
 (0)