fix: cache preview PNG bytes to avoid regeneration on apply#18
Merged
Conversation
Closed
Copilot
AI
changed the title
[WIP] Fix image regeneration when applying settings
fix: cache preview PNG bytes to avoid regeneration on apply
Apr 14, 2026
Agent-Logs-Url: https://github.com/jiuya/locksun/sessions/ba933c57-421a-4801-b43c-f480d90d30bd Co-authored-by: jiuya <6884687+jiuya@users.noreply.github.com>
…ebase After rebasing onto main (which updated enhance_image to take &[u8]), revert call sites back to passing &png_bytes / &base_png accordingly.
97bb043 to
d4f7995
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Clicking "Apply" after previewing regenerated the image from scratch — wasting Gemini API quota and risking a different result than what was previewed (non-deterministic generation + sun position drift between calls).
Changes
AppState— new cache fieldcached_preview: Mutex<Option<Vec<u8>>>to hold the last previewed PNG bytes in memorycommands/mod.rs— populate & consume cachepreview_image_with_config/preview_image_enhanced_with_config: now acceptState<'_, AppState>and store generated bytes into the cache after encoding (no extraclone)apply_to_lockscreen_with_config: takes cache viatake()(consuming it atomically); if present, writes directly to disk and applies — skipping all regeneration; falls back torun_once_with_configif cache is emptyscheduler/mod.rs— cache invalidationrun_once_with_configclears the cache at the start of every scheduled/manual update cycle, preventing stale preview bytes from being applied by the scheduleroutput_image_pathpromoted topubso the apply command can resolve the output path without duplicating logicFlow