Skip to content

fix(windows): handle missing registry key in isEnabled#42

Open
jabagawee wants to merge 1 commit into
leanflutter:mainfrom
jabagawee:fix/windows-isenabled-missing-key
Open

fix(windows): handle missing registry key in isEnabled#42
jabagawee wants to merge 1 commit into
leanflutter:mainfrom
jabagawee:fix/windows-isenabled-missing-key

Conversation

@jabagawee

Copy link
Copy Markdown

isEnabled() reads the Run key via Registry.openPath, which throws a WindowsException (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 created StartupApproved\Run) can be absent, so isEnabled() throws rather than reporting "off". Downstream this can abort an app's startup; in our case it aborted before runApp() 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_FOUND and rethrows anything else (e.g. access denied). Scoping it that way needs WindowsException / HRESULT_FROM_WIN32, which win32_registry doesn't re-export, so this declares win32 (already a transitive dependency) directly.

Note: enable() opens the same keys and createValue doesn't create a missing parent, so it can still throw on a fresh install where Run is absent. Out of scope here; worth a separate fix.

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.
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.

1 participant