feat: add sync_start to prevent startup flash; fix legacy timer jobstart fast-event error
#65
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds an opt-in option
sync_startthat performs the first dark-mode query synchronously (blocking), so users don’t see a brief flash of the default colorscheme at startup. Subsequent polling remains asynchronous.It also fixes a legacy Neovim bug where running the timer callback on versions without
vim.systemcaused:because
vim.fn.jobstart()was being invoked in a fast-event context. We nowvim.schedulethat call to the main loop.Motivation
vim.system) without fast-event errors.What’s changed
sync_start(defaultfalse)true, the first poll runs synchronously and applies the hooks immediately (novim.schedule), preventing startup flicker.vim.fn.jobstart(...)insidevim.schedule(function() ... end)when called from the timer to avoidE5560.poll_dark_mode(callback, sync?)now supports both sync and async modes in a single function.sync_startin code and corrected the docstring”.Backwards compatibility
sync_start = false).vim.system.jobstart(async) /system(sync) as before, now safely scheduled.Documentation new feature:
sync_startHere is a suggestion for an extension of current documentation:
Avoid startup flicker with
sync_startIf you notice a brief flash of your default colorscheme before auto-dark-mode applies the correct one, enable a synchronous first poll:
sync_start = trueperforms the first OS query blocking, then applies your hooks immediately (novim.schedule), so there’s no flash.Note: In your
init.lua, you don’t need to (and shouldn’t) callrequire("auto-dark-mode").init()manually;setup()already initializes the plugin.Disclaimer
This PR was prepared with the help of ChatGPT. All line codes have been tested, and the documentation reviewed manually.