-
Notifications
You must be signed in to change notification settings - Fork 141
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
Improved CountDown timer #300
Conversation
dmgerman
commented
Jun 5, 2023
- Improved configuration of the notification area (size and transparency)
- Added optional icons in the menubar to start, pause and end the time, and notify of remaining time
- It is now able to deal with suspending the laptop during the timer i.e. time runs in "user" time, not "computer running" time
- added hotkeys
- able to call timer again with last period
- or set new period
Is there anything else I can do to have this pull request merged? thank you. |
I apologize, I told @cmsj I'd take over for him re spoons, but had some unexpected interruptions occur. I'm hoping I can get back to this in the next day or so and run through a dry run to make sure I don't screw anything up and then start testing/merging this weekend. |
hi,
I appreciate your response.
there is no rush at all. I am happy to know somebody is thinking about it.
I have other improvements that I can share, once things get rolling.
…--daniel
On Wed, Aug 30, 2023 at 1:25 PM A-Ron ***@***.***> wrote:
I apologize, I told @cmsj <https://github.com/cmsj> I'd take over for him
re spoons, but had some unexpected interruptions occur. I'm hoping I can
get back to this in the next day or so and run through a dry run to make
sure I don't screw anything up and then start testing/merging this weekend.
—
Reply to this email directly, view it on GitHub
<#300 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABIZ4BRGVJYNSYJPMUCQ2DXX6ORZANCNFSM6AAAAAAY3HWQ7U>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
--dmg
---
D M German
http://turingmachine.org
|
@dmgerman looks like you're missing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some minor nitpicks.
Source/CountDown.spoon/init.lua
Outdated
end | ||
|
||
function obj:query_time_and_start() | ||
local button, time = hs.dialog.textPrompt("Enter time", "in minutes", string.format("%s", obj.defaultLenMin), "Ok", "Cancel") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local button, time = hs.dialog.textPrompt("Enter time", "in minutes", string.format("%s", obj.defaultLenMin), "Ok", "Cancel") | |
local button, time = hs.dialog.textPrompt("Enter time", "in minutes", string.format("%s", obj.defaultLenMin), "OK", "Cancel") |
Source/CountDown.spoon/init.lua
Outdated
|
||
function obj:query_time_and_start() | ||
local button, time = hs.dialog.textPrompt("Enter time", "in minutes", string.format("%s", obj.defaultLenMin), "Ok", "Cancel") | ||
if button == "Ok" then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if button == "Ok" then | |
if button == "OK" then |
Source/CountDown.spoon/init.lua
Outdated
-- default timer in minutes | ||
|
||
obj.defaultLenMin = 25 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- default timer in minutes | |
obj.defaultLenMin = 25 | |
-- default timer in minutes | |
obj.defaultLenMin = 25 |
Source/CountDown.spoon/init.lua
Outdated
function obj:create_bar_timer(minutes) | ||
local mainScreen = hs.screen.primaryScreen() | ||
local mainRes = mainScreen:fullFrame() | ||
obj.canvas:frame({x=mainRes.x, y=mainRes.h-obj.canvasHeight, w=mainRes.w, obj.canvasHeight}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is here h=
missing?
obj.canvas:frame({x=mainRes.x, y=mainRes.h-obj.canvasHeight, w=mainRes.w, obj.canvasHeight}) | |
obj.canvas:frame({x=mainRes.x, y=mainRes.h-obj.canvasHeight, w=mainRes.w, h=obj.canvasHeight}) |
Source/CountDown.spoon/init.lua
Outdated
if obj.timer then | ||
-- reset current timer and do nothing | ||
obj:reset() | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if the minutes
value is changed?
- I think it is better to cleanup if there a timer exists and start over with setting the values to have a clean state
- or check if minutes are change
if obj.timer then | |
-- reset current timer and do nothing | |
obj:reset() | |
else | |
if obj.timer then | |
-- reset current timer and do nothing | |
obj:reset() | |
end |
Source/CountDown.spoon/init.lua
Outdated
local pausedSeconds = obj:time_absolute_seconds() - obj.pausedAt | ||
obj.startTime = obj.startTime + pausedSeconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think this calculation is not valid if there are multiple pauses and resumes.
Source/CountDown.spoon/init.lua
Outdated
local mainScreen = hs.screen.primaryScreen() | ||
local mainRes = mainScreen:fullFrame() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong variable naming
local mainScreen = hs.screen.primaryScreen() | |
local mainRes = mainScreen:fullFrame() | |
local primaryScreen = hs.screen.primaryScreen() | |
local mainRes = primaryScreen:fullFrame() |
Source/CountDown.spoon/init.lua
Outdated
local mainScreen = hs.screen.primaryScreen() | ||
local mainRes = mainScreen:fullFrame() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong variable naming
local mainScreen = hs.screen.primaryScreen() | |
local mainRes = mainScreen:fullFrame() | |
local primaryScreen = hs.screen.primaryScreen() | |
local mainRes = primaryScreen:fullFrame() |
Source/CountDown.spoon/init.lua
Outdated
else | ||
message = string.format("Illegal number [%s]", time) | ||
end | ||
hs.alert.show(message, nil, hs.screen.mainScreen()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The canvas is changed to primaryScreen
— should the alert
be as well?
Source/CountDown.spoon/init.lua
Outdated
withdrawAfter = 100 | ||
}):soundName(obj.sound):send() | ||
|
||
hs.alert.show(message, nil, hs.screen.mainScreen(), obj.alertLenMin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The canvas is changed to primaryScreen
— should the alert
be as well?
Thanks for the comment. There are some new features I have implemented. I'll address your comments and submit an update. |
5b9a4ac
to
72b703e
Compare
Lots of improvements over original timer. They can be divided into several categories: - Improve timer handler. The original timer counted seconds via a callback. If the computer was suspended, the timer would have been suspended too. The new timer continues to run even when the computer is suspended. - Improved configurability of countdown timer Many of its properties can now be configured via object attributes - Added menu bar: A menu bar item allows to start/pause/resume/cancel a timer - Optional progress messages: It can optionally display messages to the screen as the timer is advancing - Improved time-up messages. I found that the end of the timer notifications were too subtle to be noticed. It now allows several ways to configure the notifications - A callback. User can specify a callback to the evaluated as the timer is started/paused/resumed/cancelled. - In addition to minutes, a timer can now be set using a time of day,
59380ca
to
b03f19a
Compare
Hi everybody, I have uploaded my current improvements. I have added several features since I first uploaded these changes. I also fixed the documentation errors. This is the complete summary:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some notes
--- the minutes that were requested. | ||
--- The callback is not called if timer is cancelled | ||
function obj:startFor(minutes, callback) | ||
if not minutes then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could test minutes for type=function then minutes get the default minutes and place minutes into callback. so the minutes are optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean: if minutes is a function, call it and use return value as length of the timer?
currently, minutes is optional, if provided, if not provided it will use defaultLenMinutes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that if minutes would be an optional parameter, but someone want a callback
function obj:startFor([minutes,] callback)
I have seen this on some places at hammerspoon:
if type(minutes)=='function' then
callback = minutes
minutes = obj.defaultLenMinutes
end
if not minutes then | ||
minutes = obj.defaultLenMinutes | ||
end | ||
if obj.timerRunning then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe do here a timer:cancel() and start over with a new timer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to issue an error. The reasons is that one might accidentally try to set another timer without noticing the current one is running. I guess a better option would be to make this optional (via a variable). What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or alternatively, ask the user.
-- configure some bindings | ||
countDown:bindHotkeys({ | ||
startFor = {{"cmd", "ctrl", "alt"}, "P"}, | ||
startInteractive = {{"cmd", "ctrl", "alt", "shift"}, "P"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is here this is missing:
pauseOrResume = {{"cmd", "ctrl", "alt"}, "P"},
your alerts are not on the same place always - is this by design? /* 227 */ hs.alert.show(msg, obj.messageAttributes, nil, duration) -- nil
/* 291 */ hs.alert.show(message, obj.alertAttributes, screen, obj.alertLen) -- .mainScreen() / currentWin:screen()
/* 600 */ hs.alert.show(message, nil, hs.screen.mainScreen()) -- .mainScreen()
/* 630 */ hs.alert.show(message, nil, hs.screen.mainScreen()) -- .mainScreen() |
I realized that I removed this function. To maintain full backwards compatibility I have added it back. Adds a new type of event (setProgress).
Yes. We have three types of messsage: warnings (optional), messages while setting/modifying the timer, and final alert. |