Skip to content

Commit 8b7984f

Browse files
committed
Fix :TimerSession command to not duplicate timers
1 parent 247c69c commit 8b7984f

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
## Unreleased
88

99
### Added
10+
1011
- Added `:TimerSession <session_name>` command to create and manage Pomodoro like sessions.
12+
- Added Windows support for System notifications.
1113

12-
### Added
14+
### Changed
1315

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

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

lua/pomo/commands/timer_repeat.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ return function(data)
1919

2020
local name = data.fargs[3]
2121

22-
pomo.start_timer(time_limit, name, repititions)
22+
pomo.start_timer(time_limit, { name = name, repeat_n = repititions })
2323
end

lua/pomo/commands/timer_session.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ return function(data)
3232
return
3333
end
3434

35-
local timer = pomo.start_timer(time_limit, timer_config.name)
36-
timer:start(function()
37-
start_session(current_session, index + 1)
38-
end)
35+
pomo.start_timer(time_limit, {
36+
name = timer_config.name,
37+
timer_done = function()
38+
start_session(current_session, index + 1)
39+
end,
40+
})
3941
end
4042

4143
start_session(session, 1)

lua/pomo/init.lua

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,27 @@ end
1919

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

29-
cfg = cfg and cfg or M.get_config()
27+
opts = opts or {}
28+
if type(opts) == "string" then
29+
opts = { name = opts }
30+
end
3031

32+
local cfg = opts.cfg or M.get_config()
3133
local timer_id = timers:first_available_id()
32-
local timer = Timer.new(timer_id, time_limit, name, cfg, repeat_n)
34+
local timer = Timer.new(timer_id, time_limit, opts.name, cfg, opts.repeat_n)
3335

3436
timers:store(timer)
3537

3638
timer:start(function(t)
3739
timers:remove(t)
40+
if opts.timer_done then
41+
opts.timer_done()
42+
end
3843
end)
3944

4045
return timer

lua/pomo/notifiers/default.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ DefaultNotifier.start = function(self)
100100
---@type integer|boolean
101101
local timeout = false
102102
if not self.sticky then
103-
timeout = 1000
103+
timeout = 2000
104104
end
105105
self:_update(string.format(" %s starting...", self.text_icon), vim.log.levels.INFO, timeout)
106106
end

0 commit comments

Comments
 (0)