waveterm/cmd/wsh/cmd/wshcmd-notify.go
Evan Simkowitz b51ff834b2
Happy new year! (#1684)
Update all 2024 references to 2025
2025-01-04 20:56:57 -08:00

46 lines
1.2 KiB
Go

// Copyright 2025, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/wavetermdev/waveterm/pkg/wshrpc"
"github.com/wavetermdev/waveterm/pkg/wshutil"
)
var notifyTitle string
var notifySilent bool
var setNotifyCmd = &cobra.Command{
Use: "notify <message> [-t <title>] [-s]",
Short: "create a notification",
Args: cobra.ExactArgs(1),
RunE: notifyRun,
PreRunE: preRunSetupRpcClient,
}
func init() {
setNotifyCmd.Flags().StringVarP(&notifyTitle, "title", "t", "Wsh Notify", "the notification title")
setNotifyCmd.Flags().BoolVarP(&notifySilent, "silent", "s", false, "whether or not the notification sound is silenced")
rootCmd.AddCommand(setNotifyCmd)
}
func notifyRun(cmd *cobra.Command, args []string) (rtnErr error) {
defer func() {
sendActivity("notify", rtnErr == nil)
}()
message := args[0]
notificationOptions := &wshrpc.WaveNotificationOptions{
Title: notifyTitle,
Body: message,
Silent: notifySilent,
}
_, err := RpcClient.SendRpcRequest(wshrpc.Command_Notify, notificationOptions, &wshrpc.RpcOpts{Timeout: 2000, Route: wshutil.ElectronRoute})
if err != nil {
return fmt.Errorf("sending notification: %w", err)
}
return nil
}