Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windows support to system notifier #25

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading