55 lines
1 KiB
Go
55 lines
1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
|
"lmika.dev/pkg/modash/moslice"
|
|
)
|
|
|
|
// App struct
|
|
type App struct {
|
|
ctx context.Context
|
|
}
|
|
|
|
// NewApp creates a new App application struct
|
|
func NewApp() *App {
|
|
return &App{}
|
|
}
|
|
|
|
// startup is called when the app starts. The context is saved
|
|
// so we can call the runtime methods
|
|
func (a *App) startup(ctx context.Context) {
|
|
a.ctx = ctx
|
|
}
|
|
|
|
// Greet returns a greeting for the given name
|
|
func (a *App) ProcessText(req ProcessTextRequest) {
|
|
filter, ok := TextFilters[req.Action]
|
|
if !ok {
|
|
log.Printf("Unknown filter: [%s]", req.Action)
|
|
return
|
|
}
|
|
|
|
resp, err := moslice.MapWithError(req.Input, func(span TextSpan) (TextSpan, error) {
|
|
outStr, err := filter(span.Text)
|
|
if err != nil {
|
|
return TextSpan{}, err
|
|
}
|
|
return TextSpan{
|
|
Text: outStr,
|
|
Pos: span.Pos,
|
|
Len: span.Len,
|
|
}, nil
|
|
})
|
|
if err != nil {
|
|
log.Printf("Error running filter: %s", err)
|
|
return
|
|
}
|
|
|
|
runtime.EventsEmit(a.ctx, "process-text-response", ProcessTextResponse{
|
|
Output: resp,
|
|
})
|
|
}
|