返回 DeepSeek-Reasonix
sender_darwin.go
根目录 / internal / notify / sender_darwin.go
1 //go:build darwin
2
3 package notify
4
5 import (
6 "os/exec"
7 "reasonix/internal/secrets"
8 "strings"
9 )
10
11 // PlatformSender delivers notifications through the host OS.
12 type PlatformSender struct{}
13
14 // NewPlatformSender returns the best-effort sender for the current platform.
15 func NewPlatformSender() PlatformSender { return PlatformSender{} }
16
17 func (PlatformSender) Send(m Message) error {
18 script := `display notification "` + appleScriptString(m.Body) + `" with title "` + appleScriptString(m.Title) + `"`
19 cmd := exec.Command("osascript", "-e", script)
20 cmd.Env = secrets.ProcessEnv()
21 if err := cmd.Start(); err != nil {
22 return err
23 }
24 go func() { _ = cmd.Wait() }()
25 return nil
26 }
27
28 func appleScriptString(s string) string {
29 s = strings.ReplaceAll(s, `\`, `\\`)
30 return strings.ReplaceAll(s, `"`, `\"`)
31 }
32
32 lines GO