def _connect_adb(args): from connector.ADBConnector import ADBConnector, ensure_adb_alive ensure_adb_alive() global device if len(args) == 0: try: device = ADBConnector.auto_connect() except IndexError: print("检测到多台设备") devices = ADBConnector.available_devices() for i, (serial, status) in enumerate(devices): print("%2d. %s\t[%s]" % (i, serial, status)) num = 0 while True: try: num = int(input("请输入序号选择设备: ")) if not 0 <= num < len(devices): raise ValueError() break except ValueError: print("输入不合法,请重新输入") device_name = devices[num][0] device = ADBConnector(device_name) else: serial = args[0] device = ADBConnector(serial)
def run(self): print("starting worker thread") loghandler = WebHandler(self.output) loghandler.setLevel(logging.INFO) logging.root.addHandler(loghandler) version = config.version if config.get_instance_id() != 0: version += f" (instance {config.get_instance_id()})" self.notify("web:version", version) ensure_adb_alive() devices = ADBConnector.available_devices() devices = ["adb:" + x[0] for x in devices] self.notify("web:availiable-devices", devices) self.helper = Arknights.helper.ArknightsHelper(frontend=self) while True: self.notify("worker:idle") command: dict = self.input.get(block=True) if command.get('type', None) == "call": self.interrupt_event.clear() self.notify('worker:busy') tag = command.get('tag', None) action = command.get('action', None) return_value = None exc = None try: func = self.allowed_calls[action] args = command.get('args', []) return_value = func(*args) except: exc = sys.exc_info() if exc is None: result = dict(type='call-result', status='resolved', tag=tag, return_value=return_value) else: result = dict(type='call-result', status='exception', tag=tag, exception=format_exception(*exc)) if tag is not None: self.output.put_nowait(result)
def _connect_adb(args): from connector.ADBConnector import ADBConnector, ensure_adb_alive ensure_adb_alive() global device if len(args) == 0: try: device = ADBConnector.auto_connect() except IndexError: print("检测到多台设备") devices = ADBConnector.available_devices() for i, (serial, status) in enumerate(devices): print("%2d. %s\t[%s]" % (i, serial, status)) num = 0 while True: try: num = int(input("请输入序号选择设备: ")) if not 0 <= num < len(devices): raise ValueError() break except ValueError: print("输入不合法,请重新输入") device_name = devices[num][0] device = ADBConnector(device_name) else: serial = args[0] try: device = ADBConnector(serial) except RuntimeError as e: if e.args and isinstance(e.args[0], bytes) and b'not found' in e.args[0]: if ':' in serial and serial.split(':')[-1].isdigit(): print('adb connect', serial) ADBConnector.paranoid_connect(serial) device = ADBConnector(serial) return raise