Files
lazyntfy/internal/tui/cmd.go
T

37 lines
751 B
Go
Raw Permalink Normal View History

package tui
import (
"context"
"os/exec"
"time"
tea "charm.land/bubbletea/v2"
"lazyntfy/internal/config"
"lazyntfy/internal/ntfy"
)
type publishDone struct{ err error }
type openDone struct{ err error }
func publishCmd(client *ntfy.Client, sub config.Sub, req ntfy.PublishRequest) tea.Cmd {
return func() tea.Msg {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
return publishDone{err: client.Publish(ctx, sub.Origin, sub.Name, sub.Auth, req)}
}
}
func openCmd(raw string) tea.Cmd {
return func() tea.Msg {
return openDone{err: openURL(raw)}
}
}
func openURL(raw string) error {
if err := validateURL(raw); err != nil {
return err
}
return exec.Command("xdg-open", raw).Start()
}