Skip to content

Commit

Permalink
Fix bug with library callbacks reinitialization
Browse files Browse the repository at this point in the history
  • Loading branch information
cmin764 committed Oct 4, 2023
1 parent 850f335 commit 63a9fe5
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/JABWrapper/jab_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ def __init__(self, ignore_callbacks=False) -> None:

def _init(self) -> None:
logging.debug("Loading WindowsAccessBridge")

if "RC_JAVA_ACCESS_BRIDGE_DLL" not in os.environ:
raise OSError("Environment variable: RC_JAVA_ACCESS_BRIDGE_DLL not found")
if not os.path.isfile(os.path.normpath(os.environ["RC_JAVA_ACCESS_BRIDGE_DLL"])):
raise FileNotFoundError(f"File not found: {os.environ['RC_JAVA_ACCESS_BRIDGE_DLL']}")
self._wab: cdll = cdll.LoadLibrary(os.path.normpath(os.environ["RC_JAVA_ACCESS_BRIDGE_DLL"]))
logging.debug("WindowsAccessBridge loaded succesfully")

# Any reader can register callbacks here that are executed when `AccessBridge` events are seen.
self._context_callbacks: dict[str, List[Callable[[JavaObject], None]]] = dict()
self._define_functions()
if not self.ignore_callbacks:
self._define_callbacks()
Expand All @@ -182,13 +184,10 @@ def _init(self) -> None:
self._vmID = c_long()
self.context = JavaObject()

# Any reader can register callbacks here that are executed when AccessBridge events are seen
self._context_callbacks: dict[str, List[Callable[[JavaObject], None]]] = dict()

def shutdown(self):
self._context_callbacks = dict()
if not self.ignore_callbacks:
self._remove_callbacks()
self._context_callbacks.clear()

def _define_functions(self) -> None:
# void Windows_run()
Expand Down Expand Up @@ -628,7 +627,7 @@ def switch_window_by_title(self, title: str) -> int:
Raises:
Exception: Window not found.
"""
self._context_callbacks = dict()
self._context_callbacks.clear()
self._hwnd: wintypes.HWND = None
self._vmID = c_long()
self.context = JavaObject()
Expand Down Expand Up @@ -673,7 +672,7 @@ def switch_window_by_pid(self, pid: int) -> int:
Raises:
Exception: Window not found.
"""
self._context_callbacks = dict()
self._context_callbacks.clear()
self._hwnd: wintypes.HWND = None
self._vmID = c_long()
self.context = JavaObject()
Expand Down

0 comments on commit 63a9fe5

Please sign in to comment.