Skip to content

Instantly share code, notes, and snippets.

@dotemacs
Last active February 9, 2020 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotemacs/db564cb18c42d27a46875a213b5cafb1 to your computer and use it in GitHub Desktop.
Save dotemacs/db564cb18c42d27a46875a213b5cafb1 to your computer and use it in GitHub Desktop.
Menubar app getting stuck

Problem

Menubar app as shown above is getting stuck.

What does the app do?

It's just a simple app that runs in the menubar and shows the current time in Paris.

It is written in fennel and transpiles to Lua. I have the sample of the original Fennel code and transpiled Lua.

How does the problem manifest?

After running for a while, while I use my macbook, I put it to sleep, awake, sleep... (just using it regularly) the system clock would show the current time, but the menubar app would "drift".

There would be a difference of few hours between the current time, say 18:45 and the time shown in the app would be 12:23.

If you look at the code, the difference should ever only be one hour between the time in the menubar app and the system time.

My "feelings"

I think that Hammerspoon process is somehow getting put to sleep and it's not being woken up later.

But what is strange, all the other key shortcuts that I have they all work as expected, regardless if the menubar app is stuck or not.

Question

What can I do to determine what is going on with the menubar app?

What can I do to prevent the menubar app from going to sleep, after the computer usage is resumed?

Thanks

Suggestions

On Wednesday 5th February:

After asking on #hammerspoon on Freenode, it was suggested that I make the instance of hs.menubar.new a global variable. So I did that in paris-2.fnl and you can see what that transpiles in paris-2.lua below.

(global menu-bar (hs.menubar.new))
(lambda paris-bar-clock
[]
"Display the time in Paris on the menubar."
(hs.timer.doEvery 1 (fn []
(let [seconds-ahead 3600
seconds-now (+ (os.time) seconds-ahead)
minutes (math.modf (% (/ seconds-now 60) 60))
hours (math.modf (% (/ seconds-now 3600) 24))
display (fn [place hours minutes]
(string.format "%s: %02d:%02d" place hours minutes))]
(doto menu-bar
(: :setTitle (display "Paris" hours minutes))
(: :setTooltip "This is grand"))))))
(paris-bar-clock)
__fnl_global__menu_2dbar = hs.menubar.new()
local function paris_bar_clock()
local function _0_()
local seconds_ahead = 3600
local seconds_now = (os.time() + seconds_ahead)
local minutes = math.modf(((seconds_now / 60) % 60))
local hours = math.modf(((seconds_now / 3600) % 24))
local function _1_(place, hours, minutes)
return string.format("%s: %02d:%02d", place, hours, minutes)
end
local display = _1_
do
local _2_0 = __fnl_global__menu_2dbar
_2_0:setTitle(display("Paris", hours, minutes))
_2_0:setTooltip("This is grand")
return _2_0
end
end
return hs.timer.doEvery(1, _0_)
end
return paris_bar_clock
;; Paris clock
(lambda paris-bar-clock
[]
"Display the time in Paris on the menubar."
(let [menu-bar (hs.menubar.new)]
(hs.timer.doEvery 1 (fn []
(let [seconds-ahead 3600
seconds-now (+ (os.time) seconds-ahead)
minutes (math.modf (% (/ seconds-now 60) 60))
hours (math.modf (% (/ seconds-now 3600) 24))
display (fn [place hours minutes]
(string.format "%s: %02d:%02d" place hours minutes))]
(doto menu-bar
(: :setTitle (display "Paris" hours minutes))
(: :setTooltip "This is grand")))))))
local function paris_bar_clock()
local menu_bar = hs.menubar.new()
local function _0_()
local seconds_ahead = 3600
local seconds_now = (os.time() + seconds_ahead)
local minutes = math.modf(((seconds_now / 60) % 60))
local hours = math.modf(((seconds_now / 3600) % 24))
local function _1_(place, hours, minutes)
return string.format("%s: %02d:%02d", place, hours, minutes)
end
local display = _1_
do
local _2_0 = menu_bar
_2_0:setTitle(display("Paris", hours, minutes))
_2_0:setTooltip("This is grand")
return _2_0
end
end
return hs.timer.doEvery(1, _0_)
end
return paris_bar_clock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment