Skip to content

Add screensaver restore behaviour#606

Open
sanialmccormick wants to merge 3 commits into
e-dream-ai:masterfrom
sanialmccormick:fix/windows-screensaver-state
Open

Add screensaver restore behaviour#606
sanialmccormick wants to merge 3 commits into
e-dream-ai:masterfrom
sanialmccormick:fix/windows-screensaver-state

Conversation

@sanialmccormick
Copy link
Copy Markdown
Contributor

@sanialmccormick sanialmccormick commented May 1, 2026

Fixes Windows screensaver handling so disabling “Keep screensaver enabled” restores the user’s previous screensaver. If none, then goes back to none, if other selected, that is restored.

The app now captures the current Windows screensaver state before applying Infinidream, but avoids saving Infinidream itself as the restore target. It stores the restore state in HKCU and applies/restores immediately when the setting is toggled.

Looking #602

@sanialmccormick
Copy link
Copy Markdown
Contributor Author

Also deals with #599

Copy link
Copy Markdown
Contributor

@scottdraves scottdraves left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diagnostic logging in ScreensaverInstallerWin32.cpp was removed in this PR — the prior version logged the opt-out skip, the missing .scr case, the registry-open failure, and the before/after values when SCRNSAVE.EXE or ScreenSaveActive changed. Could we put those back, and add equivalents on the new save/restore paths (e.g. what was captured into the backup, what was written back on restore, and any failure to open the Desktop or backup keys)?

This code touches the Windows registry on user machines we can't debug interactively, and runtime logs are written to C:\ProgramData\Infinidream\Logs\YYYY_MM_DD.log precisely so we can diagnose this kind of thing after the fact. If a user reports "my screensaver didn't come back when I unchecked Keep," the log is the only signal we have — right now it would say nothing.

@scottdraves
Copy link
Copy Markdown
Contributor

this is good but 599 and 602 are very related, it might make sense to do them together.
i want to have more of a plan in mind before merging.

@sanialmccormick
Copy link
Copy Markdown
Contributor Author

Yeah I saw 599 after this, and realised it answers both problems. Gunna get the logging put back in and commit and then wait for further plans

@scottdraves
Copy link
Copy Markdown
Contributor

for one thing, we have a settings.json file, would it make sense to store the previous setting there, instead of in the registry?

@sanialmccormick
Copy link
Copy Markdown
Contributor Author

Every time I tried to store it in the settings.json it would get overwritten. Although that was before the logic change of 'if isn't already infinidream'. Will test more tomorrow.

@sanialmccormick
Copy link
Copy Markdown
Contributor Author

Problem
When the app launched for the first time with "Keep screensaver enabled" ticked by default, the user's previous Windows screensaver settings (exe path, timeout, password-on-resume) were not being reliably saved. As a result, unticking the checkbox had no effect — the restore call found no valid backup and Infinidream remained as the screensaver.
Root cause
CElectricSheep::Startup() in client.h calls InitStorage() a second time with _bReadOnly = true (when m_MultipleInstancesMode is true). Any settings written before this call — including the screensaver backup — were silently discarded when the storage was reopened read-only, leaving screensaver_backup as an empty string in settings.json.
Fix
Split EnsureScreensaverActive into two phases in client_win32.h:

SaveOriginalScreensaverSettingsOnce is called before CElectricSheep::Startup(), while settings is still read-write. This ensures the backup is written to and committed to settings.json successfully.
EnsureScreensaverActive is called after CElectricSheep::Startup() as before, handling the registry write to set Infinidream as the active screensaver.

ScreensaverInstallerWin32.cpp was also refactored to store the backup in settings.json (via settings.app.screensaver_backup) rather than a separate registry key, keeping all app state in one place. A verify read-back log line was added to SaveBackupToSettings to aid future debugging.
Behaviour

First launch: user's previous screensaver (exe, timeout, active state) is saved to settings.json, Infinidream is set as the active screensaver
Unticking the checkbox: previous screensaver is restored immediately from the backup
Reticking the checkbox: Infinidream is reasserted, backup is refreshed
Setting persists across restarts correctly in both directions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants