From befc7a867f22b4fa11ff31aa109cc35612a4351a Mon Sep 17 00:00:00 2001 From: tretrauit Date: Wed, 2 Feb 2022 14:01:23 +0700 Subject: [PATCH] Add ws-scrcpy-launcher.py also fix pineapple portable launcher not being able to update. --- .../Termux}/install-termux-x11.bash | 0 .../.pinEApple-portable-launcher.sh.kate-swp | Bin 0 -> 1474 bytes .../pinEApple}/pinEApple-portable-launcher.sh | 0 Apps/ws-scrcpy/ws-scrcpy-launcher.py | 106 ++++++++++++++++++ Termux/.gitkeep | 0 pinEApple/.gitkeep | 0 6 files changed, 106 insertions(+) rename {Termux => Apps/Termux}/install-termux-x11.bash (100%) create mode 100644 Apps/pinEApple/.pinEApple-portable-launcher.sh.kate-swp rename {pinEApple => Apps/pinEApple}/pinEApple-portable-launcher.sh (100%) create mode 100644 Apps/ws-scrcpy/ws-scrcpy-launcher.py delete mode 100644 Termux/.gitkeep delete mode 100644 pinEApple/.gitkeep diff --git a/Termux/install-termux-x11.bash b/Apps/Termux/install-termux-x11.bash similarity index 100% rename from Termux/install-termux-x11.bash rename to Apps/Termux/install-termux-x11.bash diff --git a/Apps/pinEApple/.pinEApple-portable-launcher.sh.kate-swp b/Apps/pinEApple/.pinEApple-portable-launcher.sh.kate-swp new file mode 100644 index 0000000000000000000000000000000000000000..aada369a0f37fc85e372fd816f6fb66e8774e138 GIT binary patch literal 1474 zcmZux>rT`_6fT$LjtgA`_6Nzakg#al8e`CyV6s`4xWT}tfW(A^%ywsK!}ek?2qr#- zPvTEs!3R)Z#Q)CMP8)8M%-Q+&eCIl6swj%O#}ZD5Usy=H?vT?9;IlQ zuYP?qoR5EgG){gt{vKLFQxh9Y1yHl2qO1ZeN>B$_kU$5hO3(m!B*8MkyabuIISFde z%u28YFeAYlz_bLJgDD9#XeK3S0aPSd0T{mt#w1vWW>f<8SR9rhY7iM*#AyMd3h@YH z9%2q+7Gefs8e$4!5@G_P0x=FT1~H0Q#mc;mbP6bbtLsn9G>*)k>zh3mJ10_C#bE>h z>@wHp@zMJOYe!2WoRr=DUQ$*E{I%e?xX-G0(RU-#Lo!4@JVJEnsvwmUkVm(;7hJmj zIR(Q$A!!ueh}+X5G05J$}+g+{N*v)SEB27 zf+$64g?lj9U{cPnVIm9t>h<>7_DiGSldiKcbkP-^=k5>@R$DMH-h!G(?6SmmM7$yl z)Y(-R52$AM?^a;KA@nskET7%bCp{MB=B+euv=o%A-15D8mqIO4wo+dYkpf4Q+kY56 zc7aGRY9Lbi^z+m=?hm0xZ|}K*3s~xKQGQBnM@$MmyLylgRvmOzY^(~JV89dpsX$eH zu2%D8K4c?@i^HW9-2`bB>?N_WPILDD!BP7Sbq4tyrD0!uDr341Qu5L`A$u6aJlC;7 zBIY<_z&Z2#6elc7C~@4FVmorfgxEQA{d@`$=oAqjBb-=z{@!-(Orfaz)>O*gqeNKh F?f-Ys3lsnV literal 0 HcmV?d00001 diff --git a/pinEApple/pinEApple-portable-launcher.sh b/Apps/pinEApple/pinEApple-portable-launcher.sh similarity index 100% rename from pinEApple/pinEApple-portable-launcher.sh rename to Apps/pinEApple/pinEApple-portable-launcher.sh diff --git a/Apps/ws-scrcpy/ws-scrcpy-launcher.py b/Apps/ws-scrcpy/ws-scrcpy-launcher.py new file mode 100644 index 0000000..10c948a --- /dev/null +++ b/Apps/ws-scrcpy/ws-scrcpy-launcher.py @@ -0,0 +1,106 @@ +#!/usr/bin/python3 +# poorly written for quick and dirty use +import subprocess +import os +import time +import threading + +def main(): + print("ws-scrcpy launcher for termux (YOU NEED TO HAVE WS-SCRCPY INSTALLED IN ~/ws-scrcpy)") + print("THIS SCRIPT REQUIRES ROOT AND TSU, THANK YOU :(") + print("checking for adb port...") + adb_lsof_output = subprocess.check_output(["sudo", "lsof", "-i", "-P", "-n"]).decode("utf-8") + adb_port = None + try: + for line in adb_lsof_output.split("\n"): + if "adbd" in line and "(LISTEN)" in line: + line = ' '.join(line.split()) + print(line.strip()) + adb_port = line.strip().split(" ")[8].split(":")[1] + break + except: + print("error occured while getting adb port.") + pass + if adb_port == None: + adb_port = input("couldn't find adb port please type manually:") + + device_ip = subprocess.check_output(['ifdata', '-pa', 'wlan0']).decode("utf-8").strip() + + print("adb port:", adb_port) + print("ip:", device_ip) + print("connecting to device through adb...") + connect_result = subprocess.call(["adb", "connect", f"{device_ip}:{adb_port}"]) + if connect_result != 0: + print("connection failed.") + exit() + print("changing directory to home") + os.chdir("/data/data/com.termux/files/home/") + print("starting ws-scrcpy server...") + ws_scrcpy = subprocess.Popen(["npm", "start"], cwd="./ws-scrcpy", stdout=subprocess.PIPE, stderr=subprocess.PIPE) + def print_ws_scrcpy(): + for line in ws_scrcpy.stdout: + if line.decode("utf-8").strip is None: + continue + if "Listening on:" in line.decode("utf-8").strip(): + device_ip = subprocess.check_output(['ifdata', '-pa', 'wlan0']).decode("utf-8").strip() + print("=========================================") + print(f"ws-scrcpy STARTED ON {device_ip}:8000") + print("=========================================") + print("[ws-scrcpy]:", line.decode("utf-8").strip()) + ws_scrcpy_thread = threading.Thread(target=print_ws_scrcpy) + ws_scrcpy_thread.daemon = True + ws_scrcpy_thread.start() + 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(5) + curr_ip = subprocess.check_output(['ifdata', '-pa', 'wlan0']).decode("utf-8").strip() + if curr_ip != device_ip: + print("!!!DEVICE IP ADDRESS CHANGED, PLEASE RESTART SERVER MANUALLY!!!") + print("!!!SCRCPY WILL NOT WORK UNTIL YOU RESTART THE SERVER!!!") + except: # lazy + if ws_scrcpy.poll() == None: + print("stopping ws-scrcpy server...") + ws_scrcpy.terminate() + try: + # if this returns, the process completed + ws_scrcpy.wait(timeout=15) + 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("stopped.") + +if __name__ == '__main__': + main() diff --git a/Termux/.gitkeep b/Termux/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/pinEApple/.gitkeep b/pinEApple/.gitkeep deleted file mode 100644 index e69de29..0000000