21 lines
857 B
Python
21 lines
857 B
Python
"""Manage only this helper's per-user browser registrations."""
|
|
from pathlib import Path
|
|
from host.common import HOST_NAME
|
|
|
|
|
|
def unregister(root: Path):
|
|
import winreg
|
|
expected = str((root / ".runtime" / "native-host.json").resolve()).casefold()
|
|
removed = 0
|
|
for browser in (r"Google\Chrome", r"Microsoft\Edge", "Chromium"):
|
|
key = rf"Software\{browser}\NativeMessagingHosts\{HOST_NAME}"
|
|
try:
|
|
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, key) as handle:
|
|
current = winreg.QueryValueEx(handle, "")[0]
|
|
if isinstance(current, str) and str(Path(current).resolve()).casefold() == expected:
|
|
winreg.DeleteKey(winreg.HKEY_CURRENT_USER, key)
|
|
removed += 1
|
|
except FileNotFoundError:
|
|
continue
|
|
return {"removed": True, "registrations": removed}
|