Merge pull request #558 from dahn-zk/fix-native-messaging-example-checker-script

native-messaging: fix Windows checker script not to fail on missing HKCU when HKLM is set
This commit is contained in:
Simeon Vincent
2024-07-12 19:29:55 -07:00
committed by GitHub
2 changed files with 7 additions and 13 deletions

View File

@@ -16,7 +16,7 @@ To get this working, there's a little setup to do.
### Windows setup ### ### Windows setup ###
1. Check you have Python installed, and that your system's PATH environment variable includes the path to Python. See [Using Python on Windows](https://docs.python.org/2/using/windows.html). You'll need to restart the web browser after making this change, or the browser won't pick up the new environment variable. 1. Check you have Python installed, and that your system's PATH environment variable includes the path to Python. See [Using Python on Windows](https://docs.python.org/3/using/windows.html). You'll need to restart the web browser after making this change, or the browser won't pick up the new environment variable.
2. Edit the "path" property of "ping_pong.json" to point to the location of "ping_pong_win.bat" on your computer. Note that you'll need to escape the Windows directory separator, like this: `"path": "C:\\Users\\MDN\\native-messaging\\app\\ping_pong_win.bat"`. 2. Edit the "path" property of "ping_pong.json" to point to the location of "ping_pong_win.bat" on your computer. Note that you'll need to escape the Windows directory separator, like this: `"path": "C:\\Users\\MDN\\native-messaging\\app\\ping_pong_win.bat"`.
3. Edit "ping_pong_win.bat" to refer to the location of "ping_pong.py" on your computer. 3. Edit "ping_pong_win.bat" to refer to the location of "ping_pong.py" on your computer.
4. Add a registry key containing the path to "ping_pong.json" on your computer. See [App manifest location ](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_manifests#Manifest_location) to find details of the registry key to add. 4. Add a registry key containing the path to "ping_pong.json" on your computer. See [App manifest location ](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_manifests#Manifest_location) to find details of the registry key to add.

View File

@@ -16,21 +16,15 @@ key_path = 'Software\\Mozilla\\NativeMessagingHosts\\ping_pong'
# Assuming current user overrides local machine. # Assuming current user overrides local machine.
key_roots = ['HKEY_CURRENT_USER', 'HKEY_LOCAL_MACHINE'] key_roots = ['HKEY_CURRENT_USER', 'HKEY_LOCAL_MACHINE']
found_key = False for key_root in key_roots:
for root in key_roots:
key = winreg.OpenKey(getattr(winreg, root), key_path)
try: try:
print('Checking:', root, key_path) print('Checking:', key_root, key_path)
key = winreg.OpenKey(getattr(winreg, key_root), key_path)
res = winreg.QueryValueEx(key, '') res = winreg.QueryValueEx(key, '')
break
except FileNotFoundError: except FileNotFoundError:
print('...error finding key') print('... error finding key')
continue else:
found_key = True
break
if not found_key:
raise ValueError('Could not find a registry entry, aborting.') raise ValueError('Could not find a registry entry, aborting.')
json_path = res[0] json_path = res[0]