You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pywry/docs/docs/guides/window-management.md
+18-15Lines changed: 18 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -149,7 +149,7 @@ handle = app.show(
149
149
150
150
## The Window Handle
151
151
152
-
`app.show()` returns a handle object. In native mode this is a `WindowProxy` — a full-featured wrapper around the OS window. In browser/notebook mode it's an `InlineWidget` with a subset of the same interface.
152
+
`app.show()` returns a `NativeWindowHandle` in native mode — a wrapper that provides the same `emit()` / `on()` interface as notebook widgets, plus access to the full OS window API via its `.proxy` attribute. In browser/notebook mode it's an `InlineWidget` with the same event interface.
153
153
154
154
### Common Methods (all modes)
155
155
@@ -158,10 +158,14 @@ handle = app.show(
158
158
|`handle.emit(event, data)`| Send an event from Python to the window's JavaScript |
159
159
|`handle.on(event, callback)`| Register a Python callback for events from the window |
160
160
|`handle.label`| The window/widget label |
161
+
|`handle.alert(message, ...)`| Show a toast notification |
162
+
|`handle.set_toolbar_value(id, value, ...)`| Update a toolbar component's value |
@@ -187,6 +187,53 @@ All events follow the `namespace:event-name` pattern:
187
187
188
188
---
189
189
190
+
## Auth Events (auth:*)
191
+
192
+
The `auth:*` namespace is used by the built-in OAuth2 authentication system.
193
+
Events flow in both directions: the frontend can request login/logout, and the
194
+
backend notifies the frontend when auth state changes (e.g. after a token
195
+
refresh or successful logout).
196
+
197
+
!!! note "Availability"
198
+
Auth events are only active when `PYWRY_DEPLOY__AUTH_ENABLED=true` and a
199
+
valid `PYWRY_OAUTH2__*` configuration is present. In native mode the full
200
+
flow is handled by `app.login()` / `app.logout()` — these events apply to
201
+
the frontend integration via `window.pywry.auth`.
202
+
203
+
### Auth Requests (JS → Python)
204
+
205
+
| Event | Payload | Description |
206
+
|-------|---------|-------------|
207
+
|`auth:login-request`|`{}`| Frontend requests a login flow (calls `window.pywry.auth.login()`). In native mode the backend opens the provider's authorization URL; in deploy mode it redirects to `/auth/login`. |
208
+
|`auth:logout-request`|`{}`| Frontend requests logout (calls `window.pywry.auth.logout()`). The backend revokes tokens, destroys the session, and emits `auth:logout` back. |
209
+
210
+
### Auth Notifications (Python → JS)
211
+
212
+
| Event | Payload | Description |
213
+
|-------|---------|-------------|
214
+
|`auth:state-changed`|`{authenticated, user_id?, roles?, token_type?}`| Auth state changed (login succeeded or session expired). When `authenticated` is `false`, `window.__PYWRY_AUTH__` is cleared. |
215
+
|`auth:token-refresh`|`{token_type, expires_in?}`| Access token was refreshed in the background. Updates the current session without requiring re-login. |
console.log("Logged in as", state.user_id, "with roles", state.roles);
344
+
} else {
345
+
console.log("Logged out");
346
+
}
347
+
});
348
+
```
349
+
350
+
**`window.__PYWRY_AUTH__`** is injected server-side for authenticated requests and
351
+
contains `{ user_id, roles, token_type }`. Use `window.pywry.auth.getState()`
352
+
rather than reading it directly — the helper normalizes the value and handles
353
+
the unauthenticated case.
354
+
274
355
### Tauri Access (Native Mode Only)
275
356
276
357
In native desktop mode, a subset of Tauri APIs and the PyTauri IPC bridge are available via `window.__TAURI__`. PyWry does **not** expose the full Tauri plugin ecosystem — only the APIs listed below are bundled and configured.
0 commit comments