malob / DarkMode.spoon

Hammerspoon Spoon to enable, disable, and toggle DarkMode either manually, or on a schedule (by default enabled on sunset and disabled as sunrise).
3 stars 0 forks source link

DarkMode enables light mode when start() at night #5

Closed andreiborisov closed 5 years ago

andreiborisov commented 5 years ago

spoon.DarkMode:start() switches to light mode at night

andreiborisov commented 5 years ago

For example

spoon.DarkMode:start() print(hs.inspect.inspect(spoon.DarkMode:getSchedule()))

produces:

2018-11-04 19:40:36: { {
    onAt = {
      sunEvent = "sunset",
      time = "16:50:07"
    }
  }, {
    offAt = {
      sunEvent = "sunrise",
      time = "07:34:26"
    }
  } }

But when reloading config in Hammerspoon, it switches from already enabled dark theme to light one.

malob commented 5 years ago

I've been fighting with a few different issues that might be the cause of this. I'm going to play around a bit now and see if I can figure out what's going on.

malob commented 5 years ago

Which commit of the code are you on?

andreiborisov commented 5 years ago

The latest one (as of now): https://github.com/malob/DarkMode.spoon/commit/9d113a5ac13fd924bdc1a26255ea040d19e5cb76

malob commented 5 years ago

Cool, did updating to that commit fix the issue for you? There was a typo that was fixed in that commit that might have caused the issue.

andreiborisov commented 5 years ago

No, the issue persists😔 It's also the same if I try to set time manually with spoon.DarkMode:setSchedule()

malob commented 5 years ago

Alright, the issue is almost certainly in shouldDMBeOn(). I need to sit down once and for all and figure out what the logic should be there.

andreiborisov commented 5 years ago

Something like this?

local function shouldDMBeOn(onTime, offTime, currentTime)
  if onTime > offTime then
    if currentTime >= onTime or currentTime < offTime then
      return true
    end
  else
    if currentTime >= onTime and currentTime < offTime then
      return true
    end
  end
  return false
end
malob commented 5 years ago

I literally just wrote the same thing 😀 Is that working for you? I'm still testing it on my end.

andreiborisov commented 5 years ago

Seems to be working when doing spoon.DarkMode:start(), but it doesn't toggle on scheduled time. Although, it's probably different issue.

malob commented 5 years ago

Hmmm, so I'm pretty confident that code is right now. I'm experiencing a separate issue where, it's not changing Dark Mode the next time it's supposed to. I've been playing around with times using setSchedule() and I'm getting the following behavior.

Let's say it's 17:00, and Dark Mode is currently off on my computer.

If I run spoon.DarkMode:setSchedule("17:01", "17:04") in the console, Dark Mode doesn't turn on at all.

If I run spoon.DarkMode:setSchedule("16:56", "17:04") in the console, Dark Mode comes on right away (like it should), but it doesn't turn off at 17:04.

I've tested pretty carefully to make sure that the toggleTime set in manageDMSchedule() is working correctly. What seems to be going on, is that the timer isn't going off when it should to trigger the next change.

I'm trying to work out what's going on with that now.

andreiborisov commented 5 years ago

I’ve opened separate issue for it: https://github.com/malob/DarkMode.spoon/issues/6

malob commented 5 years ago

Issue should be resolved in commit 43e919b