Skip to content

Commit

Permalink
Hopefully, fix intermittend disconnets on lock screen
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonarddeR committed Jul 25, 2023
1 parent 84b3b30 commit 6983419
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
16 changes: 9 additions & 7 deletions addon/globalPlugins/rdAccess/handlers/_remoteHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ def __new__(cls, *args, **kwargs):
obj.decide_remoteDisconnect = AccumulatingDecider(defaultDecision=False)
return obj

def __init__(
self,
ioThread: IoThread,
pipeName: str,
isNamedPipeClient: bool = True,
):
super().__init__()
def initializeIo(self, ioThread: IoThread, pipeName: str, isNamedPipeClient: bool):
try:
IO = namedPipe.NamedPipeClient if isNamedPipeClient else namedPipe.NamedPipeServer
self._dev = IO(
Expand All @@ -55,6 +49,14 @@ def __init__(
except EnvironmentError:
raise

def __init__(
self,
ioThread: IoThread,
pipeName: str,
isNamedPipeClient: bool = True,
):
super().__init__()
self.initializeIo(ioThread=ioThread, pipeName=pipeName, isNamedPipeClient=isNamedPipeClient)
self._handleDriverChanged(self._driver)

def event_gainFocus(self, obj):
Expand Down
9 changes: 5 additions & 4 deletions addon/lib/driver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import sys
from baseObject import AutoPropertyObject
import time
from utils.security import post_sessionLockStateChanged
from utils.security import post_sessionLockStateChanged, isRunningOnSecureDesktop

ERROR_INVALID_HANDLE = 0x6
ERROR_PIPE_NOT_CONNECTED = 0xe9
Expand Down Expand Up @@ -97,11 +97,12 @@ def __init__(self, port="auto"):
self._dev.close()
else:
raise RuntimeError("No remote device found")

post_sessionLockStateChanged.register(self._handleLockStateChanged)
if not isRunningOnSecureDesktop():
post_sessionLockStateChanged.register(self._handleLockStateChanged)

def terminate(self):
post_sessionLockStateChanged.unregister(self._handleLockStateChanged)
if not isRunningOnSecureDesktop():
post_sessionLockStateChanged.unregister(self._handleLockStateChanged)
super().terminate()

def __getattribute__(self, name: str) -> Any:
Expand Down
7 changes: 5 additions & 2 deletions addon/lib/protocol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ def __new__(cls, *args, **kwargs):
self._attributeValueProcessor.register(getattr(self, k))
return self

def terminateIo(self):
# Make sure the device gets closed.
self._dev.close()

def __init__(self):
super().__init__()
self._bgExecutor = ThreadPoolExecutor(4, thread_name_prefix=self.__class__.__name__)
Expand All @@ -336,8 +340,7 @@ def terminate(self):
if superTerminate:
superTerminate()
finally:
# Make sure the device gets closed.
self._dev.close()
self.terminateIo()
self._attributeValueProcessor.clearCache()
self._bgExecutor.shutdown(False)

Expand Down

0 comments on commit 6983419

Please sign in to comment.