Skip to content

Commit

Permalink
Fix :TimerSession command to not duplicate timers
Browse files Browse the repository at this point in the history
  • Loading branch information
epwalsh committed Jul 26, 2024
1 parent 247c69c commit 8b7984f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## Unreleased

### Added

- Added `:TimerSession <session_name>` command to create and manage Pomodoro like sessions.
- Added Windows support for System notifications.

### Added
### Changed

- Added Windows support for System notifications.
- Changed the arguments of `pomo.start_timer()` to accept a table of options.

## [v0.6.0](https://github.com/epwalsh/pomo.nvim/releases/tag/v0.6.0) - 2024-04-02

Expand Down
2 changes: 1 addition & 1 deletion lua/pomo/commands/timer_repeat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ return function(data)

local name = data.fargs[3]

pomo.start_timer(time_limit, name, repititions)
pomo.start_timer(time_limit, { name = name, repeat_n = repititions })
end
10 changes: 6 additions & 4 deletions lua/pomo/commands/timer_session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ return function(data)
return
end

local timer = pomo.start_timer(time_limit, timer_config.name)
timer:start(function()
start_session(current_session, index + 1)
end)
pomo.start_timer(time_limit, {
name = timer_config.name,
timer_done = function()
start_session(current_session, index + 1)
end,
})
end

start_session(session, 1)
Expand Down
17 changes: 11 additions & 6 deletions lua/pomo/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,27 @@ end

---Start a new timer.
---@param time_limit integer The time limit, in seconds.
---@param name string|? A name for the timer. Does not have to be unique.
---@param repeat_n integer|? The number of the times to repeat the timer.
---@param cfg pomo.Config|? Override the config.
---@param opts string|{ name: string|?, repeat_n: integer|?, cfg: pomo.Config|?, timer_done: fun() }|?
---@return pomo.Timer timer
M.start_timer = function(time_limit, name, repeat_n, cfg)
M.start_timer = function(time_limit, opts)
local Timer = require "pomo.timer"

cfg = cfg and cfg or M.get_config()
opts = opts or {}
if type(opts) == "string" then
opts = { name = opts }
end

local cfg = opts.cfg or M.get_config()
local timer_id = timers:first_available_id()
local timer = Timer.new(timer_id, time_limit, name, cfg, repeat_n)
local timer = Timer.new(timer_id, time_limit, opts.name, cfg, opts.repeat_n)

timers:store(timer)

timer:start(function(t)
timers:remove(t)
if opts.timer_done then
opts.timer_done()
end
end)

return timer
Expand Down
2 changes: 1 addition & 1 deletion lua/pomo/notifiers/default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ DefaultNotifier.start = function(self)
---@type integer|boolean
local timeout = false
if not self.sticky then
timeout = 1000
timeout = 2000
end
self:_update(string.format(" %s starting...", self.text_icon), vim.log.levels.INFO, timeout)
end
Expand Down

0 comments on commit 8b7984f

Please sign in to comment.