Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native-messaging: fix Windows checker script not to fail on missing HKCU when HKLM is set #558

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dahn-zk
Copy link

@dahn-zk dahn-zk commented Apr 20, 2024

Description

from #557 :

this line will throw when you create required key in HKEY_LOCAL_MACHINE instead of HKEY_CURRENT_USER ( which is allowed ) , so this script should not behave like this :

key = winreg.OpenKey(getattr(winreg, root), key_path)

also , as the script is in Python anyway , the whole thing can be simplified using for-else :

for root in key_roots:
    try:
        key = winreg.OpenKey(getattr(winreg, root), key_path)
        print('Checking:', root, key_path)
        res = winreg.QueryValueEx(key, '')
    except FileNotFoundError:
        continue
    break
else:
    raise ValueError('Could not find a registry entry, aborting.')

Motivation

i was bored

Additional details

update : ignore the following , i created a PR for that mdn/content#33211

btw , in the docs https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging#registry there is an incorrect info about registry keys . it says "two registry entries should be created for the messaging to work" as if "both" in HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE . but this is not true . only one should be . here is the proof in the Firefox source code : https://searchfox.org/mozilla-central/source/toolkit/components/extensions/NativeManifests.sys.mjs#59-83

Related issues and pull requests

fixes #557

Copy link

It looks like this is your first pull request. 🎉 Thank you for your contribution! One of the project maintainers will triage and assign the pull request for review. We appreciate your patience. To safeguard the health of the project, please take a moment to read our code of conduct.

@dahn-zk dahn-zk force-pushed the fix-native-messaging-example-checker-script branch from d3c69df to 2a93ff8 Compare April 20, 2024 15:33
there was a bug when missing key in HKEY_CURRENT_USER would throw from `winreg.OpenKey` call
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.

minor bug with native messaging example
1 participant