| 1 | #!/usr/bin/python3 |
| 2 | import os |
| 3 | from pathlib import Path |
| 4 | import sys |
| 5 | from urllib.parse import urlsplit |
| 6 | |
| 7 | def launch(): |
| 8 | if len(sys.argv) != 2 or os.environ.get('DISPLAY') != ':79' or os.environ.get('XDG_RUNTIME_DIR') != '/run/cage-phone-desktop': |
| 9 | return 1 |
| 10 | value = sys.argv[1] |
| 11 | if not value or len(value) > 8192 or any(ord(c) < 32 for c in value): |
| 12 | return 1 |
| 13 | parsed = urlsplit(value) |
| 14 | if parsed.scheme == 'claude': |
| 15 | os.execv('/usr/bin/claude-desktop', ['claude-desktop', '--user-data-dir=' + str(Path.home() / 'DesktopProfile'), value]) |
| 16 | host = parsed.hostname or '' |
| 17 | if parsed.scheme != 'https' or parsed.username or parsed.password or parsed.port not in (443, None): |
| 18 | return 1 |
| 19 | if not any(host == d or host.endswith('.' + d) for d in ('anthropic.com', 'claude.ai', 'claude.com')): |
| 20 | return 1 |
| 21 | port = (Path(os.environ['XDG_RUNTIME_DIR']) / 'proxy').read_text() |
| 22 | os.execv('/usr/bin/chromium', ['chromium', '--user-data-dir=' + str(Path.home() / 'LoginProfile'), |
| 23 | '--class=CagePhoneLogin', '--no-first-run', '--no-default-browser-check', '--disable-extensions', |
| 24 | '--disable-quic', '--force-webrtc-ip-handling-policy=disable_non_proxied_udp', |
| 25 | '--proxy-server=socks5://127.0.0.1:' + str(int(port)), '--proxy-bypass-list=<-loopback>', |
| 26 | '--disable-dev-shm-usage', '--lang=' + os.environ.get('CAGE_LANGUAGE', 'en-US'), '--app=' + value]) |
| 27 | |
| 28 | try: |
| 29 | sys.exit(launch()) |
| 30 | except Exception: |
| 31 | sys.exit(1) |