This commit is contained in:
2025-12-16 22:16:14 +01:00
parent 5d633c1706
commit dafbf2974e

18
main.go
View File

@@ -15,6 +15,8 @@ import (
"time" "time"
) )
const appUserModelID = "de.stadthilden.GoSysNotifyAgent"
type Notification struct { type Notification struct {
ID int64 `json:"id"` ID int64 `json:"id"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
@@ -29,6 +31,7 @@ var (
) )
func main() { func main() {
if v := os.Getenv("SERVICE_URL"); v != "" { if v := os.Getenv("SERVICE_URL"); v != "" {
serviceURL = strings.TrimRight(v, "/") serviceURL = strings.TrimRight(v, "/")
} }
@@ -149,12 +152,15 @@ func showToast(title, message string) error {
title = escapeXML(title) title = escapeXML(title)
message = escapeXML(message) message = escapeXML(message)
psScript := fmt.Sprintf(` psScript := `
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] > $null [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] > $null
# AppId von "Windows PowerShell" holen (oder erste gefundene App als Fallback) # bevorzugt Windows Terminal, sonst Windows PowerShell, sonst erste App
$appid = (Get-StartApps | Where-Object Name -eq 'Windows PowerShell').AppId $appid = (Get-StartApps | Where-Object Name -eq 'Windows Terminal').AppId
if (-not $appid) {
$appid = (Get-StartApps | Where-Object Name -eq 'Windows PowerShell').AppId
}
if (-not $appid) { if (-not $appid) {
$appid = (Get-StartApps | Select-Object -First 1).AppId $appid = (Get-StartApps | Select-Object -First 1).AppId
} }
@@ -163,8 +169,8 @@ $xmlString = @"
<toast activationType="foreground"> <toast activationType="foreground">
<visual> <visual>
<binding template="ToastGeneric"> <binding template="ToastGeneric">
<text>%s</text> <text>` + title + `</text>
<text>%s</text> <text>` + message + `</text>
</binding> </binding>
</visual> </visual>
</toast> </toast>
@@ -176,7 +182,7 @@ $xml.LoadXml($xmlString)
$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($appid) $notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($appid)
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml) $toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
$notifier.Show($toast) $notifier.Show($toast)
`, title, message) `
cmd := exec.Command("powershell", "-NoProfile", "-NonInteractive", "-Command", psScript) cmd := exec.Command("powershell", "-NoProfile", "-NonInteractive", "-Command", psScript)
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()