From ed72657e7516dbf6cb191ecc5fe342c3409f7370 Mon Sep 17 00:00:00 2001 From: Juan Pedro Martin Date: Fri, 17 May 2024 18:47:54 +0200 Subject: [PATCH] Add Windows support to system notifier (#25) --- CHANGELOG.md | 6 +++++- README.md | 3 +-- doc/pomo.txt | 3 +-- lua/pomo/notifiers/system.lua | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 050b3c8..8bced8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased +### Added + +- Added Windows support for System notifications. + ## [v0.6.0](https://github.com/epwalsh/pomo.nvim/releases/tag/v0.6.0) - 2024-04-02 ### Added @@ -14,7 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [v0.5.0](https://github.com/epwalsh/pomo.nvim/releases/tag/v0.5.0) - 2024-03-27 -## Added +### Added - Added Linux support for System notifications. diff --git a/README.md b/README.md index b98cb6d..8726b47 100644 --- a/README.md +++ b/README.md @@ -118,8 +118,7 @@ This is a complete list of all of the options that can be passed to `require("po }, -- The "System" notifier sends a system notification when the timer is finished. - -- Available on MacOS natively and Linux via the `libnotify-bin` package. - -- Tracking: https://github.com/epwalsh/pomo.nvim/issues/3 + -- Available on MacOS and Windows natively and on Linux via the `libnotify-bin` package. { name = "System" }, -- You can also define custom notifiers by providing an "init" function instead of a name. diff --git a/doc/pomo.txt b/doc/pomo.txt index e8a10e3..6cfd12c 100644 --- a/doc/pomo.txt +++ b/doc/pomo.txt @@ -138,8 +138,7 @@ read each option carefully and customize it to your needs: }, -- The "System" notifier sends a system notification when the timer is finished. - -- Available on MacOS natively and Linux via the `libnotify-bin` package. - -- Tracking: https://github.com/epwalsh/pomo.nvim/issues/3 + -- Available on MacOS and Windows natively and on Linux via the `libnotify-bin` package. { name = "System" }, -- You can also define custom notifiers by providing an "init" function instead of a name. diff --git a/lua/pomo/notifiers/system.lua b/lua/pomo/notifiers/system.lua index 58c1ce5..3405209 100644 --- a/lua/pomo/notifiers/system.lua +++ b/lua/pomo/notifiers/system.lua @@ -38,6 +38,7 @@ SystemNotifier.done = function(self) ---@diagnostic disable-line: unused-local repetitions_str = string.format(" [%d/%d]", self.timer.repetitions + 1, self.timer.max_repetitions) end + -- macOS Notification if util.get_os() == util.OS.Darwin then os.execute( string.format( @@ -48,6 +49,7 @@ SystemNotifier.done = function(self) ---@diagnostic disable-line: unused-local repetitions_str ) ) + -- Linux Notification elseif util.get_os() == util.OS.Linux then os.execute( string.format( @@ -58,6 +60,24 @@ SystemNotifier.done = function(self) ---@diagnostic disable-line: unused-local repetitions_str ) ) + -- Windows Notification + elseif util.get_os() == util.OS.Windows then + os.execute( + string.format( + [[ + PowerShell -Command "Add-Type -AssemblyName System.Windows.Forms; + $notify = New-Object System.Windows.Forms.NotifyIcon; + $notify.Icon = [System.Drawing.SystemIcons]::Information; + $notify.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Info; + $notify.BalloonTipText = 'Timer #%d, %s%s'; + $notify.BalloonTipTitle = 'Timer done!'; + $notify.Visible = $true; + $notify.ShowBalloonTip(10000);" ]], + self.timer.id, + util.format_time(self.timer.time_limit), + repetitions_str + ) + ) else return log.error("SystemNotifier is not implemented for your OS (%s)", util.get_os()) end