Skip to content

Commit

Permalink
Add Windows support to system notifier (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinn committed May 17, 2024
1 parent e650447 commit ed72657
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions doc/pomo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions lua/pomo/notifiers/system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit ed72657

Please sign in to comment.