Closed jakintosh closed 2 years ago
This is not ready for merging, I'm still testing it and living with it to see if/how it works
Setting this to draft for the moment, then. Will take a look later.
Perhaps hold off on a deeper look until I push more changes, been working through a bunch of little gotchas this morning. Definitely more of a sketch as-is.
Little bit of a mess littered with logs, and not refactored into anything clean yet, but it seems I have the broad strokes functioning now. Gonna see how it handles a real-world transition or two, and continue condensing and refactoring.
Still testing this locally to see how it performs IRL, and code is still in a debugging state, but feeling a bit better about the structure and implementation. I'll update here again once I see consistent real-world behavior.
This latest commit seems to work "correctly".
The reason for the quotes: In order to schedule the transition, I'm using NSBackgroundActivityScheduler, but for some reason it tries to run the transition block early. In the execution block, I now check the current time to return .deferred
if it's trying to execute early, but based on the logs it seems like it tries to schedule it every minute after the first miss. Running a date comparison once per minute probably won't cause serious performance issues, but I was curious if anyone had insight on why my scheduled block tries so hard to execute before its scheduled .interval
time? (I'm setting the .tolerance
as well.) It would be nice if this worked as I expect it to, where I schedule the block for a time, and it executes it at that time.
You can watch the os logs via:
log stream | grep "net.ryanthomson.Nightfall:scheduler"
A (trimmed) excerpt from the logs on this latest commit:
2022-02-03 16:19:28.748695-0500 scheduled transition to dark at 2022-02-03 22:04:40 +0000
2022-02-03 16:43:36.254433-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 16:43:51.359039-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 16:45:01.747366-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 16:47:43.848473-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 16:49:05.255951-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 16:50:11.367011-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 16:51:13.089069-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 16:52:17.561488-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 16:54:41.326106-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 16:58:05.674932-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 16:59:11.730609-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 17:00:17.554030-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 17:01:17.640992-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 17:02:17.729724-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 17:03:17.822178-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 17:04:17.890334-0500 tried to run transition "dark" early, that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 17:05:17.945052-0500 running transition dark that was scheduled for TIME 2022-02-03 22:04:40 +0000
2022-02-03 17:05:17.946414-0500 getting next transition (loop: 0)
2022-02-03 17:05:17.946858-0500 getting next transition (loop: 1)
2022-02-03 17:05:17.947576-0500 scheduled transition to light at 2022-02-04 12:08:16 +0000
Just a hunch on the early execution:
Looks like it's making the first attempt about halfway through the interval. My understanding is that's the default behavior if no tolerance is set. Maybe setting tolerance to 0 as here is still causing the default tolerance behavior. Might try 1 instead and see if it still happens.
Been messing with it all morning and I'm starting to think it has to do with a leaky abstraction... I think whatever system this interfaces with behind the scenes is "remembering" things I don't want it to remember about what to do with schedulers of a given ID. Was getting really weird behavior, but then I changed the identifier and it seems to be fixed.
Fingers crossed these scheduling issues are resolved now. Didn't realize how difficult macOS makes it to just "do {ACTION} at {TIME}" 😅.
If everything goes well for a few days of transitions, I'll do a round of clean up and edge case testing and be ready for review.
Sorry about not being able to look at this for a while, I've been occupied by other things.
I appreciate your contribution, but I'm not sure if this feature should be part of Nightfall's main codebase. I've been trying to keep the app fairly lean, and I think this feature is outside the bounds of what I intended the app to do— especially since it duplicates a system feature (even if that feature doesn't work for everyone).
I think this would be better as another app that controls Nightfall through scripting. Right now, you could probably do that by invoking the "Toggle Dark Mode" service, but in the future I'll probably add some AppleScript support.
The built in timing for automatic color switching in macOS has never worked for me. This is an attempt to add a checkbox that should hopefully make this work better.
This PR: • adds a dependency to https://github.com/ceeK/Solar, which calculates sunset/sunrise times given a date and location • adds a new UserDefault preference for auto mode • adds a new checkbox to the menu bar preference view • adds functions to allow requesting for light or dark, instead of just toggling
This is not ready for merging, I'm still testing it and living with it to see if/how it works, but wanted to surface to @r-thomson asap, to gauge interest. I've also never worked with macOS apps before, only iOS, so open to pointers and feedback.