Use ifdata as IP backend
Because Termux-wifi-connectioninfo is unstable
This commit is contained in:
parent
8776a31c64
commit
93e735f260
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/python3
|
||||
# Rewrite
|
||||
import subprocess
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import threading
|
||||
import random
|
||||
@ -55,7 +55,7 @@ def get_wifi_name():
|
||||
return get_wifi()["ssid"]
|
||||
|
||||
def get_device_private_ip():
|
||||
return get_wifi()["ip"]
|
||||
return subprocess.check_output(['ifdata', '-pa', 'wlan0']).decode("utf-8").strip()
|
||||
|
||||
def get_port_from_process_name(name: str, state: str="LISTEN"):
|
||||
lsof_output = subprocess.check_output(["sudo", "lsof", "-i", "-P", "-n"]).decode("utf-8")
|
||||
@ -153,8 +153,16 @@ def main():
|
||||
ws_scrcpy_thread = threading.Thread(target=print_ws_scrcpy)
|
||||
ws_scrcpy_thread.daemon = True
|
||||
ws_scrcpy_thread.start()
|
||||
|
||||
print("PLEASE WAIT UNTIL WS-SCRCPY FULLY STARTED (ABOUT 5 MINS), IT TAKES A WHILE TO START THE SERVER.")
|
||||
# print("starting scrcpy server on local device...")
|
||||
# scrcpy = subprocess.Popen("adb shell su -c 'CLASSPATH=/data/data/com.termux/files/home/ws-scrcpy/vendor/Genymobile/scrcpy/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 1.19-ws2 web ERROR 8886'",
|
||||
# shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
# def print_scrcpy():
|
||||
# for line in scrcpy.stdout:
|
||||
# print("[scrcpy patch]:", line.decode("utf-8").strip())
|
||||
# scrcpy_thread = threading.Thread(target=print_scrcpy)
|
||||
# scrcpy_thread.daemon = True
|
||||
# scrcpy_thread.start()
|
||||
print("PLEASE WAIT UNTIL WS-SCRCPY FULLY STARTS (ABOUT 5 MINS), IT TAKES A WHILE TO START THE SERVER.")
|
||||
try:
|
||||
while True:
|
||||
time.sleep(2.5)
|
||||
@ -198,7 +206,29 @@ def main():
|
||||
except subprocess.TimeoutExpired:
|
||||
print("ws_scrcpy doesn't exit after 15 seconds, killing process...")
|
||||
ws_scrcpy.kill()
|
||||
|
||||
|
||||
# print("stopping scrcpy server...")
|
||||
# if scrcpy.poll() == None:
|
||||
# scrcpy.terminate()
|
||||
# try:
|
||||
# # if this returns, the process completed
|
||||
# scrcpy.wait(timeout=15)
|
||||
# except subprocess.TimeoutExpired:
|
||||
# print("scrcpy doesn't exit after 15 seconds, killing process...")
|
||||
# scrcpy.kill()
|
||||
|
||||
# # kill old scrcpy-server to ensure we can start a new one after this.
|
||||
# try:
|
||||
# lsof_output = subprocess.check_output(["sudo", "lsof", "-i", "-P", "-n"]).decode("utf-8")
|
||||
# for line in lsof_output.split("\n"):
|
||||
# if "8886" in line and "(LISTEN)" in line:
|
||||
# line = ' '.join(line.split())
|
||||
# print(line.strip())
|
||||
# pid = line.strip().split(" ")[1]
|
||||
# subprocess.call(["sudo", "kill", "-9", pid])
|
||||
# break
|
||||
# except:
|
||||
# print("failed to stop scrcpy server")
|
||||
print("ws-scrcpy has been stopped.")
|
||||
show_notification("ws-scrcpy has been stopped.", ongoing=False)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user