RC-1
This commit is contained in:
18
main.go
18
main.go
@@ -15,6 +15,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const appUserModelID = "de.stadthilden.GoSysNotifyAgent"
|
||||
|
||||
type Notification struct {
|
||||
ID int64 `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
@@ -29,6 +31,7 @@ var (
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
if v := os.Getenv("SERVICE_URL"); v != "" {
|
||||
serviceURL = strings.TrimRight(v, "/")
|
||||
}
|
||||
@@ -149,12 +152,15 @@ func showToast(title, message string) error {
|
||||
title = escapeXML(title)
|
||||
message = escapeXML(message)
|
||||
|
||||
psScript := fmt.Sprintf(`
|
||||
psScript := `
|
||||
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, 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)
|
||||
$appid = (Get-StartApps | Where-Object Name -eq 'Windows PowerShell').AppId
|
||||
# bevorzugt Windows Terminal, sonst Windows PowerShell, sonst erste App
|
||||
$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) {
|
||||
$appid = (Get-StartApps | Select-Object -First 1).AppId
|
||||
}
|
||||
@@ -163,8 +169,8 @@ $xmlString = @"
|
||||
<toast activationType="foreground">
|
||||
<visual>
|
||||
<binding template="ToastGeneric">
|
||||
<text>%s</text>
|
||||
<text>%s</text>
|
||||
<text>` + title + `</text>
|
||||
<text>` + message + `</text>
|
||||
</binding>
|
||||
</visual>
|
||||
</toast>
|
||||
@@ -176,7 +182,7 @@ $xml.LoadXml($xmlString)
|
||||
$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($appid)
|
||||
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
|
||||
$notifier.Show($toast)
|
||||
`, title, message)
|
||||
`
|
||||
|
||||
cmd := exec.Command("powershell", "-NoProfile", "-NonInteractive", "-Command", psScript)
|
||||
out, err := cmd.CombinedOutput()
|
||||
|
||||
Reference in New Issue
Block a user