diff --git a/dotfiles/emacs.d/README.org b/dotfiles/emacs.d/README.org index 3821efce..28254267 100644 --- a/dotfiles/emacs.d/README.org +++ b/dotfiles/emacs.d/README.org @@ -3843,9 +3843,20 @@ This is useful with server mode when editing gmail messages. I think that it is #+BEGIN_SRC emacs-lisp (use-package alert :defer t + :preface + (defun imalison:windows-toast-notify (info) + (let ((message (plist-get info :message)) + (title (plist-get info :title))) + (shell-command (format "windows_toast '%s' '%s'" (or title "No title") (or message "No message"))))) :config (progn - (setq alert-default-style 'libnotify))) + (setq alert-default-style 'libnotify) + (when (not (string-empty-p (shell-command-to-string "grep -i microsoft /proc/version"))) + (alert-define-style + 'windows-toast + :title "Windows Toast" + :notifier 'imalison:windows-toast-notify) + (setq alert-default-style 'windows-toast)))) #+END_SRC ** sauron #+BEGIN_SRC emacs-lisp diff --git a/dotfiles/lib/bin/windows-toast.ps1 b/dotfiles/lib/bin/windows-toast.ps1 new file mode 100755 index 00000000..2206f5cf --- /dev/null +++ b/dotfiles/lib/bin/windows-toast.ps1 @@ -0,0 +1,17 @@ +param($Title) +$ErrorActionPreference = "Stop" +[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null +$Template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02) + +$RawXml = [xml] $Template.GetXml() +($RawXml.toast.visual.binding.text | Where-Object { $_.id -eq "1" }).AppendChild($RawXml.CreateTextNode($Title)) > $null +($RawXml.toast.visual.binding.text | Where-Object { $_.id -eq "2" }).AppendChild($RawXml.CreateTextNode($args[0])) > $null + +$SerializedXml = New-Object Windows.Data.Xml.Dom.XmlDocument +$SerializedXml.LoadXml($RawXml.OuterXml) + +$Toast = [Windows.UI.Notifications.ToastNotification]::new($SerializedXml) +$Toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(30) + +$Notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Emacs") +$Notifier.Show($Toast); diff --git a/dotfiles/lib/functions/windows_toast b/dotfiles/lib/functions/windows_toast new file mode 100755 index 00000000..bfc136f5 --- /dev/null +++ b/dotfiles/lib/functions/windows_toast @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +function windows_toast { + powershell.exe -File ~/dotfiles/dotfiles/lib/bin/windows-toast.ps1 -Title "$@" 2>/dev/null +} + +windows_toast "$@"