mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 22:55:48 +01:00
docs: fix issues from PR review comments
- menus.mdx: add Update() call after adding items to context menu snippet - application.mdx: fix Emit() signature — remove fabricated bool return - events-reference.mdx: fix files-dropped JS example to account for variadic wrapping (event.data[0] is the files array) - bridge.mdx: fix progress event example — use variadic args directly and destructure event.data array in JS Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e2e0f5c95e
commit
6fcf2d6210
4 changed files with 15 additions and 9 deletions
|
|
@ -538,10 +538,7 @@ func ProcessLargeFile(path string) error {
|
|||
for scanner.Scan() {
|
||||
lineNum++
|
||||
// Emit progress events
|
||||
app.Event.Emit("file-progress", map[string]interface{}{
|
||||
"line": lineNum,
|
||||
"text": scanner.Text(),
|
||||
})
|
||||
app.Event.Emit("file-progress", lineNum, scanner.Text())
|
||||
}
|
||||
|
||||
return scanner.Err()
|
||||
|
|
@ -553,8 +550,10 @@ import { Events } from '@wailsio/runtime'
|
|||
import { ProcessLargeFile } from './bindings/FileService'
|
||||
|
||||
// Listen for progress
|
||||
// event.data is an array of the variadic args: [lineNum, text]
|
||||
Events.On('file-progress', (event) => {
|
||||
console.log(`Line ${event.data.line}: ${event.data.text}`)
|
||||
const [line, text] = event.data
|
||||
console.log(`Line ${line}: ${text}`)
|
||||
})
|
||||
|
||||
// Start processing
|
||||
|
|
|
|||
|
|
@ -214,7 +214,10 @@ Then listen in JavaScript:
|
|||
import { Events } from '@wailsio/runtime';
|
||||
|
||||
Events.On('files-dropped', (event) => {
|
||||
event.data.forEach(file => {
|
||||
// EmitEvent is variadic, so event.data is a []any wrapping the args.
|
||||
// The files array is the first element.
|
||||
const files = event.data[0];
|
||||
files.forEach(file => {
|
||||
console.log('File dropped:', file);
|
||||
handleFileUpload(file);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -436,6 +436,12 @@ When creating a custom context menu, you provide a unique identifier (name) that
|
|||
```go
|
||||
// Create a context menu with identifier "imageMenu"
|
||||
contextMenu := application.NewContextMenu("imageMenu")
|
||||
|
||||
// Add items and call Update() to apply changes
|
||||
contextMenu.Add("Cut")
|
||||
contextMenu.Add("Copy")
|
||||
contextMenu.Add("Paste")
|
||||
contextMenu.Update()
|
||||
```
|
||||
|
||||
The name parameter ("imageMenu" in this example) serves as a unique identifier that will be used to:
|
||||
|
|
|
|||
|
|
@ -347,11 +347,9 @@ app.RegisterService(application.NewService(&MyService{}))
|
|||
Emits a custom event.
|
||||
|
||||
```go
|
||||
func (em *EventManager) Emit(name string, data ...any) bool
|
||||
func (em *EventManager) Emit(name string, data ...any)
|
||||
```
|
||||
|
||||
**Returns:** `true` if the event was cancelled by a hook.
|
||||
|
||||
**Example:**
|
||||
|
||||
```go
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue