Skip to content

Commit

Permalink
Merge branch 'master' of github.com:WPO-Foundation/wptagent
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Meenan committed Sep 25, 2018
2 parents b43ab65 + b261c47 commit 113a711
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/ios_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, serial=None):
self.video_file = None
self.last_video_data = None
self.video_size = 0
self.last_restart = monotonic.monotonic()

def check_install(self):
"""Check to make sure usbmux is installed and the device is available"""
Expand Down Expand Up @@ -184,6 +185,8 @@ def portrait(self):
def connect(self):
"""Connect to the device with the matching serial number"""
self.startup()
connecting = False
needs_restart = False
try:
if self.socket is None:
self.disconnect()
Expand All @@ -195,13 +198,22 @@ def connect(self):
logging.debug("Connecting to device %s", device.serial)
self.serial = device.serial
self.must_disconnect = False
connecting = True
self.socket = self.mux.connect(device, 19222)
self.message_thread = threading.Thread(target=self.pump_messages)
self.message_thread.daemon = True
self.message_thread.start()
break
except Exception:
pass
# If the app isn't running restart the device (no more than every 10 minutes)
if connecting and monotonic.monotonic() - self.last_restart > 600:
needs_restart = True
if needs_restart:
self.last_restart = monotonic.monotonic()
try:
subprocess.call(['idevicediagnostics', 'restart'])
except Exception:
pass
return self.socket is not None

def disconnect(self):
Expand Down

0 comments on commit 113a711

Please sign in to comment.