From 8b7984f8159d810c107574f6fe740a0f3c0d0029 Mon Sep 17 00:00:00 2001 From: epwalsh Date: Fri, 26 Jul 2024 10:25:24 -0700 Subject: [PATCH] Fix `:TimerSession` command to not duplicate timers --- CHANGELOG.md | 6 ++++-- lua/pomo/commands/timer_repeat.lua | 2 +- lua/pomo/commands/timer_session.lua | 10 ++++++---- lua/pomo/init.lua | 17 +++++++++++------ lua/pomo/notifiers/default.lua | 2 +- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c47f098..f2a576f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased ### Added + - Added `:TimerSession ` 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 diff --git a/lua/pomo/commands/timer_repeat.lua b/lua/pomo/commands/timer_repeat.lua index d02f8a2..052336c 100644 --- a/lua/pomo/commands/timer_repeat.lua +++ b/lua/pomo/commands/timer_repeat.lua @@ -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 diff --git a/lua/pomo/commands/timer_session.lua b/lua/pomo/commands/timer_session.lua index f97fa50..4652895 100644 --- a/lua/pomo/commands/timer_session.lua +++ b/lua/pomo/commands/timer_session.lua @@ -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) diff --git a/lua/pomo/init.lua b/lua/pomo/init.lua index 4164ad3..e6d7aa6 100644 --- a/lua/pomo/init.lua +++ b/lua/pomo/init.lua @@ -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 diff --git a/lua/pomo/notifiers/default.lua b/lua/pomo/notifiers/default.lua index a7fedfb..029e57e 100644 --- a/lua/pomo/notifiers/default.lua +++ b/lua/pomo/notifiers/default.lua @@ -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