diff --git a/__main__.py b/__main__.py index 7545b22..4aaa90e 100644 --- a/__main__.py +++ b/__main__.py @@ -6,8 +6,10 @@ import nvda_voicemeeter logging.basicConfig(level=logging.DEBUG) +nvda_voicemeeter.launch() + KIND_ID = "potato" with voicemeeterlib.api(KIND_ID) as vm: - with nvda_voicemeeter.build(f"Voicemeeter {KIND_ID.capitalize()} NVDA", vm) as window: + with nvda_voicemeeter.draw(f"Voicemeeter {KIND_ID.capitalize()} NVDA", vm) as window: window.run() diff --git a/src/nvda_voicemeeter/__init__.py b/src/nvda_voicemeeter/__init__.py index 9f2b740..863ba16 100644 --- a/src/nvda_voicemeeter/__init__.py +++ b/src/nvda_voicemeeter/__init__.py @@ -1 +1,12 @@ -from .window import request_window_object as build +import subprocess as sp + +from .cdll import NVDA_PATH +from .window import request_window_object as draw + + +def launch(): + if NVDA_PATH: + sp.Popen([NVDA_PATH], shell=True) + + +__ALL__ = ["launch", "draw"] diff --git a/src/nvda_voicemeeter/cdll.py b/src/nvda_voicemeeter/cdll.py index d5dffe5..72efc47 100644 --- a/src/nvda_voicemeeter/cdll.py +++ b/src/nvda_voicemeeter/cdll.py @@ -1,8 +1,41 @@ import ctypes as ct +import platform +import winreg from pathlib import Path +from .errors import NVDAVMError + bits = 64 if ct.sizeof(ct.c_voidp) == 8 else 32 +if platform.system() != "Windows": + raise NVDAVMError("Only Windows OS supported") + +REG_KEY = "\\".join( + filter( + None, + ( + "SOFTWARE", + "WOW6432Node" if bits == 64 else "", + "Microsoft", + "Windows", + "CurrentVersion", + "Uninstall", + "NVDA", + ), + ) +) + + +def get_nvdapath(): + with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"{}".format(REG_KEY)) as nvda_key: + return winreg.QueryValueEx(nvda_key, r"UninstallDirectory")[0] + + +try: + NVDA_PATH = Path(get_nvdapath()) / "nvda.exe" +except FileNotFoundError as e: + NVDA_PATH = "" + controller_path = Path(__file__).parents[2].resolve() / "controllerClient" if not controller_path.exists(): controller_path = Path(__file__).parents[3].resolve() / "controllerClient"