diff --git a/htag/runners/androidapp.py b/htag/runners/androidapp.py index 4ad008b..d77f2aa 100644 --- a/htag/runners/androidapp.py +++ b/htag/runners/androidapp.py @@ -12,7 +12,7 @@ from htag.render import HRenderer from . import commons -import os,json,asyncio +import os,json,asyncio,socket import tornado.ioloop import tornado.web @@ -20,6 +20,11 @@ from threading import Thread +def isFree(ip, port): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(1) + return not (s.connect_ex((ip,port)) == 0) + class WebServer(Thread): # the webserver is ran on a separated thread def __init__(self,instance,port): @@ -88,7 +93,10 @@ def go_exit(self): self._exiter() def run(self): # basically, the same code as guy.runAndroid() - host,port= "127.0.0.1", 12458 + host= "127.0.0.1" + port = 12458 + while not isFree(host,port): + port+=1 urlStartPage = f"http://{host}:{port}" self.server = WebServer(self,port) @@ -146,8 +154,13 @@ def exit_app(*a,**k): @run_on_ui_thread def create_webview(self, *args): webview = webView(activity) - webview.getSettings().setJavaScriptEnabled(True) - webview.getSettings().setDomStorageEnabled(True) + webSettings=webview.getSettings() + webSettings.setJavaScriptEnabled(True) + webSettings.setDomStorageEnabled(True) + try: + webSettings.setMediaPlaybackRequiresUserGesture(False) # SDK_INT > 17 + except: + pass webview.setWebViewClient(webViewClient()) activity.setContentView(webview) webview.loadUrl(urlStartPage) # !important