Skip to content

Commit

Permalink
Added a macOS build script
Browse files Browse the repository at this point in the history
  • Loading branch information
JCionx committed Jul 8, 2024
1 parent 009764e commit 211e644
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 88 deletions.
Binary file added .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.venv/
__pycache__/
pair_qr.png
build/
dist/
.eggs/
7 changes: 7 additions & 0 deletions build_macos_app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sudo rm -rf build dist
python3 setup.py py2app --emulate-shell-environment --optimize 2 --strip
cd dist
create-dmg "Scrcpy Tools.app"
rm -rf "Scrcpy Tools.app"
cd ..
sudo rm -rf build
Binary file added icon.icns
Binary file not shown.
103 changes: 24 additions & 79 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,6 @@
from PyQt6.QtGui import QIcon, QPixmap
from PyQt6.QtCore import QSize
import subprocess
from zeroconf import ServiceBrowser, Zeroconf
import qrcode
import time

# QR Code Generator variables
TYPE = "_adb-tls-pairing._tcp.local."
NAME = "debug"
PASS = "123456"
FORMAT_QR = "WIFI:T:ADB;S:%s;P:%s;;"
CMD_PAIR = "adb pair %s:%s %s"
PAIRING = False

# QR Code Generator Class
class QRListener:
def remove_service(self, zeroconf, type, name):
global PAIRING
print("Service %s removed." % name)
print("Press enter to exit...\n")
PAIRING = False

def add_service(self, zeroconf, type, name):
info = zeroconf.get_service_info(type, name)
print("Service %s added." % name)
print("service info: %s\n" % info)
self.pair(info)

def pair(self, info):
cmd = CMD_PAIR % (info.server, info.port, PASS)
print(cmd)
subprocess.run(cmd, shell=True)

# MainWindow Class
class MainWindow(QMainWindow):
Expand Down Expand Up @@ -165,28 +135,28 @@ def __init__(self):


def mirror_screen(self):
os.system("SCRCPY_ICON_PATH=\"icons/logo.svg\" scrcpy --window-title='Screen Mirror' --mouse-bind=++++")
subprocess.run("SCRCPY_ICON_PATH=\"icons/logo.svg\" scrcpy --window-title='Screen Mirror' --mouse-bind=++++", shell=True)

def otg_control(self):
os.system("SCRCPY_ICON_PATH=\"icons/logo.svg\" scrcpy --window-title='OTG Control' --otg")
subprocess.run("SCRCPY_ICON_PATH=\"icons/logo.svg\" scrcpy --window-title='OTG Control' --otg", shell=True)

def sound(self):
os.system("SCRCPY_ICON_PATH=\"icons/logo_large.png\" scrcpy --window-title='Sound' --no-video --no-control")
subprocess.run("SCRCPY_ICON_PATH=\"icons/logo_large.png\" scrcpy --window-title='Sound' --no-video --no-control --audio-buffer=200", shell=True)

def send(self):
text, ok = QInputDialog.getText(self, "Send Text", "Enter text to send:")
if ok and text:
# Replace spaces with '%s' for ADB command compatibility
text = text.replace(' ', '%s')
os.system(f"adb shell input text {text}")
subprocess.run(f"adb shell input text {text}", shell=True)

def transfer_file(self):
files, _ = QFileDialog.getOpenFileNames(self, "Select Files", "", "All Files (*)")

if files:
for file_path in files:
adb_command = f"adb push '{file_path}' /sdcard/Download/"
os.system(adb_command)
subprocess.run(adb_command, shell=True)

if len(files) == 1:
file_name = files[0].split('/')[-1] # Extract the file name
Expand All @@ -207,7 +177,7 @@ def transfer_file(self):
elif extension == "zip":
mime_type = "application/zip"

os.system(f"adb shell am start -a android.intent.action.VIEW -d file:///sdcard/Download/{file_name} -t {mime_type}")
subprocess.run(f"adb shell am start -a android.intent.action.VIEW -d file:///sdcard/Download/{file_name} -t {mime_type}", shell=True)

print(f"Transferred {len(files)} files to the phone's download folder.")
QMessageBox.information(self, "File Transfer Successful", f"Transferred {len(files)} {'files' if len(files) > 1 else 'file'} to: /sdcard/Download/")
Expand All @@ -225,7 +195,7 @@ def install_apk(self):
# Construct the adb command to install each APK
adb_command = f"adb install '{file_path}'"
# Execute the adb command
result = os.system(adb_command)
result = subprocess.run(adb_command, shell=True).returncode
if result == 0:
QMessageBox.information(self, "Installation Successful", f"App installed: {file_path.split('/')[-1]}")
else:
Expand All @@ -234,63 +204,38 @@ def install_apk(self):
print("No APK files selected.")

def restartAdb(self):
os.system("adb kill-server")
os.system("adb start-server")
subprocess.run("adb kill-server", shell=True)
subprocess.run("adb start-server", shell=True)
QMessageBox.information(self, "ADB Server", "ADB Server restarted sucessfully")

def showAbout(self):
QMessageBox.about(self, "About", "Scrcpy Tools\n\nVersion: 1.0\nAuthor: JCionx\n\nA simple GUI for scrcpy tools.")

def pairWireless(self):
global PAIRING
PAIRING = True
text = FORMAT_QR % (NAME, PASS)
# Generate QR code
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(text)
qr.make(fit=True)

img = qr.make_image(fill_color="black", back_color="white")
img.save("pair_qr.png") # Display the QR code image

zeroconf = Zeroconf()
listener = QRListener()
browser = ServiceBrowser(zeroconf, TYPE, listener)

try:
dialog = QDialog()
lay = QVBoxLayout(dialog)
label = QLabel()
lay.addWidget(label)
pixmap = QPixmap("pair_qr.png")
label.setPixmap(pixmap)
dialog.exec()
while PAIRING:
time.sleep(0.1)
print(PAIRING)
finally:
zeroconf.close()

ip, ok = QInputDialog.getText(self, "Pair Wireless Device", "Enter the Wireless Debugging IP and Port:")
ip, ok = QInputDialog.getText(self, "Pair Wireless Device", "Enter the Pairing IP and Port:")
if ok and ip:
os.system(f"adb connect {ip}")
QMessageBox.information(self, "Wireless Device Pairing", f"Wireless Device paired successfully")
code, ok = QInputDialog.getText(self, "Pair Wireless Device", "Enter the Pairing Code:")
if ok and ip:
subprocess.run(f"adb pair {ip} {code}", shell=True)
port, ok = QInputDialog.getText(self, "Pair Wireless Device", "Enter the Wireless Debugging Port:")
if ok and ip:
subprocess.run(f"adb connect {ip.strip()}:{port.strip()}", shell=True)
QMessageBox.information(self, "Wireless Device Pairing", f"Wireless Device paired successfully")
else:
QMessageBox.warning(self, "Wireless Device Pairing", "Port not provided")
else:
QMessageBox.warning(self, "Wireless Device Pairing", "Code not provided")
else:
QMessageBox.warning(self, "Wireless Device Pairing", "Port not provided")
QMessageBox.warning(self, "Wireless Device Pairing", "IP not provided")

def open_url(self):
url, ok = QInputDialog.getText(self, "Open URL", "Enter URL to open:")
if ok and url:
# open url with adb
os.system(f"adb shell am start -a android.intent.action.VIEW -d {url}")
subprocess.run(f"adb shell am start -a android.intent.action.VIEW -d {url}", shell=True)

def webcam(self):
os.system("SCRCPY_ICON_PATH=\"icons/logo.svg\" scrcpy --window-title='Webcam' --video-source=camera --no-audio --camera-size=1920x1080")
subprocess.run("SCRCPY_ICON_PATH=\"icons/logo.svg\" scrcpy --window-title='Webcam' --video-source=camera --no-audio --camera-size=1920x1080", shell=True)

app = QApplication(sys.argv)
window = MainWindow()
Expand Down
9 changes: 1 addition & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
ifaddr==0.2.0
pillow==10.4.0
pypng==0.20220715.0
PyQt5-Qt5==5.15.14
PyQt5-sip==12.13.0
PyQt6==6.7.0
PyQt6-Qt6==6.7.2
PyQt6-sip==13.6.0
qrcode==7.4.2
typing_extensions==4.12.2
zeroconf==0.132.2
typing_extensions==4.12.2
20 changes: 20 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""

from setuptools import setup

APP = ['main.py']
DATA_FILES = ['icons']
OPTIONS = {'iconfile': 'icon.icns'}

setup(
name='Scrcpy Tools',
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)

0 comments on commit 211e644

Please sign in to comment.