summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/vpn/process.py
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2017-10-25 01:52:11 +0200
committerKali Kaneko <kali@leap.se>2017-11-01 01:40:18 +0100
commitb0e1bd223368f09e49f13b9ecf04fb0570e04dc0 (patch)
treed409be680d4e7ed80080c48d1f80df915e8036a8 /src/leap/bitmask/vpn/process.py
parent4e11a6550e11fb2b8682816dfbc98be1581e5402 (diff)
[feature] display vpn status on systray
Diffstat (limited to 'src/leap/bitmask/vpn/process.py')
-rw-r--r--src/leap/bitmask/vpn/process.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/leap/bitmask/vpn/process.py b/src/leap/bitmask/vpn/process.py
index 7f33e83a..862215f8 100644
--- a/src/leap/bitmask/vpn/process.py
+++ b/src/leap/bitmask/vpn/process.py
@@ -50,7 +50,7 @@ class VPNStateListener(object):
# and make VPNProcess the implementer itself - or the service.
def change_state(self, state):
- emit_async(catalog.VPN_STATUS_CHANGED)
+ emit_async(catalog.VPN_STATUS_CHANGED, state.simple)
class _VPNProcess(protocol.ProcessProtocol):
@@ -109,6 +109,7 @@ class _VPNProcess(protocol.ProcessProtocol):
self.errmsg = None
self.proto = None
self._remotes = remotes
+ self._listener = VPNStateListener()
# processProtocol methods
@@ -120,8 +121,7 @@ class _VPNProcess(protocol.ProcessProtocol):
@defer.inlineCallbacks
def _got_management_protocol(self, proto):
self.proto = proto
- listener = VPNStateListener()
- proto.addStateListener(listener)
+ proto.addStateListener(self._listener)
try:
yield proto.logOn()
@@ -134,7 +134,7 @@ class _VPNProcess(protocol.ProcessProtocol):
def _connect_to_management(self, retries=30):
if retries == 0:
- self.log.error('Timeout whilte connecting to management')
+ self.log.error('Timeout while connecting to management')
self.failed = True
return
@@ -213,8 +213,23 @@ class _VPNProcess(protocol.ProcessProtocol):
def status(self):
if self.failed:
return {'status': 'failed', 'error': self.errmsg}
+
+ # FIXME - hack, doesn't belong here ----------------------------------
+ # needs to go with implementing the history within the VPNProcess.
+ # this only will work before the UI is pulling the state and therefore
+ # checking this condition as a side-effect of reading the property.
+
+ # TODO trigger off transition when proto dissapears (at processExited)
if not self.proto:
- return {'status': 'off', 'error': None}
+ OFF = 'off'
+ if self._status != OFF:
+ self._status = OFF
+ class _state(object):
+ simple = 'OFF'
+ off = _state()
+ self._listener.change_state(off)
+ return {'status': OFF, 'error': None}
+ # --------------------------------------------------------------------
try:
self._status = self.proto.state.simple.lower()