fix(windows): handle missing registry key in isEnabled#42
Open
jabagawee wants to merge 1 commit into
Open
Conversation
isEnabled() reads HKCU\...\CurrentVersion\Run through Registry.openPath, which throws a WindowsException when the key does not exist rather than returning null. On a fresh Windows install where no application has registered a startup entry, that key can be absent, so isEnabled() throws instead of reporting that auto-start is off. The exception propagates to callers and can abort application startup. This change guards the registry reads in isEnabled() and _isStartupApproved(). A missing Run key is treated as not enabled and a missing StartupApproved key as approved, so isEnabled() returns false on a fresh install instead of throwing. The catch is scoped to ERROR_FILE_NOT_FOUND and rethrows any other WindowsException (such as access denied) so genuine failures are not masked. This matches the macOS and Linux implementations, which return false when startup has not been configured.
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.
isEnabled()reads theRunkey viaRegistry.openPath, which throws aWindowsException(ERROR_FILE_NOT_FOUND) when the key doesn't exist instead of returning null. On a fresh Windows install where no app has registered a startup entry, that key (and the lazily createdStartupApproved\Run) can be absent, soisEnabled()throws rather than reporting "off". Downstream this can abort an app's startup; in our case it aborted beforerunApp()and showed a blank window.This guards both reads, treating a missing key as not-enabled / approved, consistent with the macOS and Linux implementations. The catch is scoped to
ERROR_FILE_NOT_FOUNDand rethrows anything else (e.g. access denied). Scoping it that way needsWindowsException/HRESULT_FROM_WIN32, whichwin32_registrydoesn't re-export, so this declareswin32(already a transitive dependency) directly.Note:
enable()opens the same keys andcreateValuedoesn't create a missing parent, so it can still throw on a fresh install whereRunis absent. Out of scope here; worth a separate fix.