Skip to content

Commit 55043d4

Browse files
author
deeleeramone
committed
doc pages update
1 parent c1d1173 commit 55043d4

2 files changed

Lines changed: 78 additions & 29 deletions

File tree

pywry/docs/docs/guides/javascript-bridge.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,26 +200,34 @@ gridOptions.api.setQuickFilter("search text");
200200

201201
## Tauri APIs (Native Mode Only)
202202

203-
In native desktop mode, the full [Tauri JavaScript API](https://tauri.app/references/javascript/) is available via `window.__TAURI__`. This gives access to OS-level capabilities that browsers can't provide:
203+
In native desktop mode, a subset of Tauri APIs are available via `window.__TAURI__`. PyWry bundles the **dialog** and **filesystem** plugins along with the **PyTauri IPC bridge** and the core **event system** — it does *not* expose the full Tauri plugin ecosystem.
204+
205+
!!! warning "PyWry uses `pytauri.pyInvoke()`, not `core.invoke()`"
206+
All JS → Python calls go through `window.__TAURI__.pytauri.pyInvoke()`. Do not use `window.__TAURI__.core.invoke()` — it won't reach PyWry's command handlers.
204207

205208
```javascript
206209
// Check if running in native mode
207210
if (window.__TAURI__) {
208-
// File dialog
209-
const { open } = window.__TAURI__.dialog;
210-
const path = await open({
211-
multiple: false,
212-
filters: [{ name: "CSV", extensions: ["csv"] }],
211+
// Native save dialog + write file
212+
const filePath = await window.__TAURI__.dialog.save({
213+
defaultPath: "export.csv",
214+
title: "Save File",
213215
});
214216

215-
if (path) {
216-
const { readTextFile } = window.__TAURI__.fs;
217-
const content = await readTextFile(path);
218-
window.pywry.emit("app:file-loaded", { path, content });
217+
if (filePath) {
218+
await window.__TAURI__.fs.writeTextFile(filePath, csvContent);
219+
window.pywry.emit("app:file-saved", { path: filePath });
219220
}
220221
}
221222
```
222223

224+
| API | Namespace | What's available |
225+
|-----|-----------|-----------------|
226+
| Event system | `window.__TAURI__.event` | `listen()`, `emit()` — Python ↔ JS event delivery |
227+
| Dialog | `window.__TAURI__.dialog` | `save()` — native save-file dialog |
228+
| Filesystem | `window.__TAURI__.fs` | `writeTextFile()` — write files to disk |
229+
| PyTauri IPC | `window.__TAURI__.pytauri` | `pyInvoke()` — JS → Python command calls |
230+
223231
!!! note "Tauri APIs are not available in browser or notebook mode"
224232
Check for `window.__TAURI__` before using any Tauri-specific API. In browser/notebook mode, only the `window.pywry` bridge is available.
225233

pywry/docs/docs/reference/events.md

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -273,27 +273,68 @@ window.__PYWRY_TOOLBAR__.setValue("component-id", value) // Set value
273273

274274
### Tauri Access (Native Mode Only)
275275

276-
In native desktop mode, Tauri APIs are available:
276+
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.
277+
278+
!!! warning "Do not use `window.__TAURI__.core.invoke()`"
279+
PyWry uses PyTauri for all JS → Python IPC. Call `window.__TAURI__.pytauri.pyInvoke()` instead of the standard Tauri `invoke()`. All registered [PyWry commands](#pytauri-commands) go through this path.
280+
281+
#### PyTauri Commands
282+
283+
All JS → Python communication uses `pyInvoke`:
284+
285+
```javascript
286+
if (window.__TAURI__ && window.__TAURI__.pytauri) {
287+
// Send a custom event to Python
288+
window.__TAURI__.pytauri.pyInvoke('pywry_event', {
289+
label: window.__PYWRY_LABEL__ || 'main',
290+
event_type: 'app:my-action',
291+
data: { key: 'value' }
292+
});
293+
294+
// Return a result to Python
295+
window.__TAURI__.pytauri.pyInvoke('pywry_result', {
296+
data: { answer: 42 },
297+
window_label: window.__PYWRY_LABEL__ || 'main'
298+
});
299+
}
300+
```
301+
302+
!!! tip "Prefer `window.pywry.emit()`"
303+
You rarely need to call `pyInvoke` directly. The `window.pywry.emit()` bridge wraps it for you and works across all rendering modes.
304+
305+
#### Available Tauri APIs
306+
307+
| API | Namespace | Used for |
308+
|-----|-----------|----------|
309+
| Event system | `window.__TAURI__.event` | Listening for Python → JS events (`listen`, `emit`) |
310+
| Dialog | `window.__TAURI__.dialog` | Native save-file dialog (`save()`) |
311+
| Filesystem | `window.__TAURI__.fs` | Writing files to disk (`writeTextFile()`) |
312+
| PyTauri IPC | `window.__TAURI__.pytauri` | JS → Python calls (`pyInvoke()`) |
313+
314+
**Example — native save dialog:**
315+
316+
```javascript
317+
if (window.__TAURI__ && window.__TAURI__.dialog && window.__TAURI__.fs) {
318+
const filePath = await window.__TAURI__.dialog.save({
319+
defaultPath: 'export.csv',
320+
title: 'Save File'
321+
});
322+
if (filePath) {
323+
await window.__TAURI__.fs.writeTextFile(filePath, csvContent);
324+
}
325+
}
326+
```
327+
328+
**Example — listening for Python events:**
277329

278330
```javascript
279-
if (window.__TAURI__) {
280-
const { invoke } = window.__TAURI__.core;
281-
const result = await invoke("my_command", { arg: "value" });
331+
if (window.__TAURI__ && window.__TAURI__.event) {
332+
window.__TAURI__.event.listen('pywry:event', function(event) {
333+
// event.payload contains {type, data}
334+
console.log('Received:', event.payload.type, event.payload.data);
335+
});
282336
}
283337
```
284338

285-
**Available Tauri Plugins:**
286-
287-
| Plugin | Namespace | Description |
288-
|--------|-----------|-------------|
289-
| Shell | `window.__TAURI__.shell` | Execute commands |
290-
| Dialog | `window.__TAURI__.dialog` | File dialogs |
291-
| Filesystem | `window.__TAURI__.fs` | File operations |
292-
| Clipboard | `window.__TAURI__.clipboard` | Copy/paste |
293-
| Notification | `window.__TAURI__.notification` | System notifications |
294-
| OS | `window.__TAURI__.os` | OS information |
295-
| Path | `window.__TAURI__.path` | Path utilities |
296-
| Process | `window.__TAURI__.process` | Process control |
297-
| HTTP | `window.__TAURI__.http` | HTTP client |
298-
| WebSocket | `window.__TAURI__.websocket` | WebSocket client |
299-
| Updater | `window.__TAURI__.updater` | App updates |
339+
!!! note "Tauri APIs are only available in native desktop mode"
340+
Check for `window.__TAURI__` before using any Tauri-specific API. In browser and notebook modes, only the `window.pywry` bridge is available — it abstracts the transport automatically.

0 commit comments

Comments
 (0)