From 5368285bcc946f3865b83a36750394400d7d7244 Mon Sep 17 00:00:00 2001 From: justjoseorg <207286469+justjoseorg@users.noreply.github.com> Date: Fri, 9 Oct 2026 19:02:51 -0600 Subject: [PATCH] Sign in with PIN numpad; tell online from not signed in Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 5 +++ README.md | 5 ++- VERSION | 2 +- main.py | 60 +++++++++++++++++++------ py_modules/wol.py | 20 +++++++-- src/index.tsx | 109 ++++++++++++++++++++++++++++++++++++++++------ 6 files changed, 168 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0eaa0d2..9391b8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ Minor releases (`X.Y.0`) get a written entry here, which becomes their release notes. Patch releases (`X.Y.Z`) are listed on the [Releases](https://github.com/justjoseorg/SpoutRemotePlay/releases) page with the change that produced them. Each entry covers everything since the previous minor release. +## 0.3 + +- **Sign in with PIN** (not yet tested on a device): when a PC is on but nobody is signed in, a **Sign in with PIN** button opens a numpad. The PIN goes once to the host's optional Spout Sign-In service (Windows, host 0.5), which types it at the sign-in screen. It is never stored. +- **The PC's status tells "online" from "not signed in".** The online check used to count Windows file sharing and Remote Desktop, which answer at the sign-in screen too, so a PC that Steam couldn't stream from yet showed as online. Now only Steam or the host count as online, and Wake waits for them. + ## 0.2 - **PyroWave can be forced on or off** in the Advanced tab, even when Steam greys out its own PyroWave toggle (for example when the x86 streaming client runs under box64 on an ARM handheld). Turn it off before streaming over a slow connection such as a VPN, and back on at home. Steam picks the codec when a stream connects, so change it before starting. AV1 and HEVC stay greyed out when Steam reports no decoder. diff --git a/README.md b/README.md index 2d5348f..71cbd43 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ On Windows, Steam's client beta now creates that virtual display itself, so the | Step | | |---|---| -| 1️⃣ **Wake the PC** | Open the plugin, tap your PC, and it sends Wake-on-LAN and waits until it's up. | +| 1️⃣ **Wake the PC** | Open the plugin, tap your PC, and it sends Wake-on-LAN and waits until Steam is up. If the PC is on but nobody is signed in (Windows), tap **Sign in with PIN** and type your Windows PIN on the numpad. This needs the host's optional [Spout Sign-In](https://github.com/justjoseorg/SpoutRemotePlayHost#-sign-in-after-wake-on-lan-windows); the PIN is sent once and never stored. | | 2️⃣ **Pair once** | Enter the PC's IP, type the 4-digit PIN shown on the PC, and you're done. The plugin also learns the PC's MAC address and tells the host what your device can decode (HEVC/AV1) and its screen size. | | 3️⃣ **Press play in Steam** | As usual. The plugin notices Steam's Remote Play session and tells the PC you're streaming from (and only that one). On Windows, Steam creates a virtual display for your device and the host turns your other displays off; on Linux, the host creates the virtual display with your device's resolution and refresh rate. When you quit, everything goes back. | @@ -73,7 +73,8 @@ Requires [Decky Loader](https://decky.xyz/). No native code, so it runs on both | 🔐 **Pairing** with a PIN, and **per-device stream settings** (resolution, refresh) pushed to the host | Verified end to end against the real host on Linux. | | 📡 **Session signal:** Remote Play start/stop reported to your paired PCs | Verified on an AYN Odin 2 Portal streaming Celeste to a Linux PC: the host received both the start and the stop. | | 🖥️ **Virtual display on a real stream** | Windows (host 0.3, Steam client beta): verified with an AYN Odin 2 Portal. Steam's display was used, the other displays turned off during the stream and came back afterwards. Linux: verified with the same handheld; the host created a virtual display for the stream and removed it afterwards. | -| ⏰ **Wake-on-LAN** with an online check | Not yet run on the Portal. | +| ⏰ **Wake-on-LAN** with an online check | Not yet run on the Portal. The check tells "online" (Steam or the host answers) from "not signed in" (only Windows answers); that check was run from the Portal against two signed-in PCs. | +| 🔑 **Sign in with PIN** numpad for a PC at the Windows sign-in screen | Not yet tested on a device. | | 🧩 **Apps tab:** lists the programs the host added to its Steam library (read-only, via the paired token) | Untested on the Portal. | | 🌊 **Force PyroWave** on or off (Advanced), even when Steam greys out its toggle | On an AYN Odin 2 Portal: turning it off and on saves to Steam's streaming config. A stream with it off has not been run yet. | | 🔎 **Network scan**, **Steam client decoder toggles** (HEVC/AV1), tabbed UI with L1/R1 switching, Spout icon | Ran on the device earlier; the latest UI changes have not been visually confirmed. | diff --git a/VERSION b/VERSION index 3b04cfb..be58634 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2 +0.3 diff --git a/main.py b/main.py index fbd72ee..e301d5d 100644 --- a/main.py +++ b/main.py @@ -15,11 +15,13 @@ import decky import steamcfg -from wol import is_port_open, normalize_mac, send_magic_packet, wait_until_online +from wol import is_port_open, normalize_mac, probe_state, send_magic_packet, wait_until_ready -# Steam Remote Play / In-Home Streaming listens on 27036 (TCP); RDP and SMB as fallbacks. -PROBE_PORTS = (27036, 3389, 445) HOST_API_PORT = 47995 +# Steam (27036) and Spout Host only listen once someone is signed in; RDP and SMB answer at the sign-in screen too. +SIGNIN_PORT = 47994 # optional Spout Sign-In service on Windows; answers at the sign-in screen +READY_PORTS = (27036, HOST_API_PORT) +ON_PORTS = (SIGNIN_PORT, 3389, 445, 22) SETTINGS_FILE = os.path.join(decky.DECKY_PLUGIN_SETTINGS_DIR, "hosts.json") STREAMING_LOG = "/tmp/streaming_client.log" STREAM_TARGET_TRIES = 10 @@ -78,9 +80,9 @@ async def wake_host(self, host_id: str) -> dict: return {"ok": False, "error": str(e)} decky.logger.info(f"Sent magic packet to {host['name']} ({host['mac']})") if not host["address"]: - return {"ok": True, "online": None} - online = await asyncio.to_thread(wait_until_online, host["address"], PROBE_PORTS, 90) - return {"ok": True, "online": online} + return {"ok": True, "state": None} + state = await asyncio.to_thread(wait_until_ready, host["address"], READY_PORTS, ON_PORTS, 90) + return {"ok": True, "state": state} def _host_request(self, host: dict, method: str, body: dict | None = None, path: str = "/api/config") -> dict: if not host.get("address"): @@ -281,15 +283,47 @@ async def cancel_pairing(self) -> bool: self._pairing = None return True - async def host_status(self, host_id: str) -> bool: + async def sign_in(self, host_id: str, pin: str) -> dict: + """Send the PIN to the PC's Spout Sign-In service once. It is never stored or logged.""" host = next((h for h in self._load() if h["id"] == host_id), None) - if not host or not host["address"]: - return False - - def probe(): - return any(is_port_open(host["address"], p, 0.7) for p in PROBE_PORTS) + if not host or not host.get("address"): + return {"ok": False, "error": "Unknown host"} + if not host.get("token"): + return {"ok": False, "error": "Pair this PC first"} + if not (isinstance(pin, str) and pin.isascii() and pin.isdigit() and 4 <= len(pin) <= 32): + return {"ok": False, "error": "The PIN must be 4 to 32 digits"} + req = urllib.request.Request( + f"http://{host['address']}:{SIGNIN_PORT}/api/signin", data=json.dumps({"pin": pin}).encode(), + headers={"Content-Type": "application/json", "Authorization": f"Bearer {host['token']}"}, + method="POST") + pin = "" - return await asyncio.to_thread(probe) + def send(): + try: + with urllib.request.urlopen(req, timeout=40): + return None + except urllib.error.HTTPError as e: + try: + return str(json.load(e).get("error", e.reason)) + except ValueError: + return str(e.reason) + except (urllib.error.URLError, OSError): + return "Spout Sign-In isn't reachable on this PC. Install it with the host's Setup." + + err = await asyncio.to_thread(send) + req.data = None + if err: + decky.logger.info(f"sign-in on {host['name']} failed: {err}") + return {"ok": False, "error": err} + decky.logger.info(f"sign-in PIN sent to {host['name']}") + state = await asyncio.to_thread(wait_until_ready, host["address"], READY_PORTS, ON_PORTS, 60) + return {"ok": True, "state": state} + + async def host_status(self, host_id: str) -> str: + host = next((h for h in self._load() if h["id"] == host_id), None) + if not host or not host["address"]: + return "off" + return await asyncio.to_thread(probe_state, host["address"], READY_PORTS, ON_PORTS) def _send_session(self, host: dict, state: str) -> bool: req = urllib.request.Request( diff --git a/py_modules/wol.py b/py_modules/wol.py index e4db3d0..dcbf70b 100644 --- a/py_modules/wol.py +++ b/py_modules/wol.py @@ -35,10 +35,22 @@ def is_port_open(host: str, port: int, timeout: float = 1.0) -> bool: return False -def wait_until_online(host: str, ports, timeout: float) -> bool: +def probe_state(host: str, ready_ports, on_ports, timeout: float = 0.7) -> str: + """"ready" when something that needs a signed-in user answers, "on" when only the OS does, else "off".""" + if any(is_port_open(host, p, timeout) for p in ready_ports): + return "ready" + if any(is_port_open(host, p, timeout) for p in on_ports): + return "on" + return "off" + + +def wait_until_ready(host: str, ready_ports, on_ports, timeout: float) -> str: + """Wait for "ready"; returns the last state seen when time runs out.""" deadline = time.monotonic() + timeout + state = "off" while time.monotonic() < deadline: - if any(is_port_open(host, p) for p in ports): - return True + state = probe_state(host, ready_ports, on_ports, 1.0) + if state == "ready": + break time.sleep(2) - return False + return state diff --git a/src/index.tsx b/src/index.tsx index 935eb2a..1899cb4 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -43,7 +43,7 @@ const addHost = callable< const removeHost = callable<[hostId: string], boolean>("remove_host"); const wakeHost = callable< [hostId: string], - { ok: boolean; online?: boolean | null; error?: string } + { ok: boolean; state?: HostState | null; error?: string } >("wake_host"); const getHostSettings = callable< [hostId: string], @@ -92,7 +92,12 @@ const scanHosts = callable< { ok: boolean; hosts?: Found[]; error?: string } >("scan_hosts"); const cancelPairing = callable<[], boolean>("cancel_pairing"); -const hostStatus = callable<[hostId: string], boolean>("host_status"); +type HostState = "ready" | "on" | "off"; +const hostStatus = callable<[hostId: string], HostState>("host_status"); +const signIn = callable< + [hostId: string, pin: string], + { ok: boolean; state?: HostState; error?: string } +>("sign_in"); const RESOLUTIONS = [ "1280x720", @@ -269,12 +274,87 @@ function StreamSettings({ host }: { host: Host }) { ); } +const STATE_LABEL: Record = { + ready: "online", + on: "not signed in", + off: "offline", +}; +const STATE_TOAST: Record = { + ready: "PC is online", + on: "PC is on but nobody is signed in, so Steam can't stream yet", + off: "Packet sent, PC did not come online", +}; + +const PAD_KEYS = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "⌫", "0", "OK"]; + +// The PIN only lives in this component's state and is cleared as soon as it is sent. +function PinPad({ + busy, + onSubmit, +}: { + busy: boolean; + onSubmit: (pin: string) => void; +}) { + const [pin, setPin] = useState(""); + const press = (k: string) => { + if (k === "⌫") setPin((p) => p.slice(0, -1)); + else if (k === "OK") { + if (pin.length >= 4) { + onSubmit(pin); + setPin(""); + } + } else if (pin.length < 32) setPin((p) => p + k); + }; + return ( + +
+ {busy ? "Signing in…" : "•".repeat(pin.length) || "Windows PIN"} +
+ + {PAD_KEYS.map((k) => ( + press(k)} + > + {k} + + ))} + +
+ ); +} + function HostRow({ host }: { host: Host }) { const [busy, setBusy] = useState(false); - const [online, setOnline] = useState(null); + const [state, setState] = useState(null); + const [padOpen, setPadOpen] = useState(false); + const [signingIn, setSigningIn] = useState(false); + + const submitPin = async (pin: string) => { + setSigningIn(true); + const res = await signIn(host.id, pin); + setSigningIn(false); + if (!res.ok) { + toaster.toast({ title: "Sign-in failed", body: res.error ?? "Unknown error" }); + return; + } + setPadOpen(false); + if (res.state) setState(res.state); + toaster.toast({ + title: host.name, + body: + res.state === "ready" + ? "Signed in, ready to stream" + : "PIN sent, but Steam isn't up yet. Check the PIN and try again.", + }); + }; useEffect(() => { - if (host.address) hostStatus(host.id).then(setOnline); + if (host.address) hostStatus(host.id).then(setState); }, [host.id]); const wake = async () => { @@ -288,20 +368,15 @@ function HostRow({ host }: { host: Host }) { }); return; } - if (res.online === null) { + if (!res.state) { toaster.toast({ title: host.name, body: "Magic packet sent" }); } else { - setOnline(!!res.online); - toaster.toast({ - title: host.name, - body: res.online - ? "PC is online" - : "Packet sent, PC did not come online", - }); + setState(res.state); + toaster.toast({ title: host.name, body: STATE_TOAST[res.state] }); } }; - const status = online === null ? "" : online ? " • online" : " • offline"; + const status = state ? ` • ${STATE_LABEL[state]}` : ""; return ( <> @@ -315,6 +390,14 @@ function HostRow({ host }: { host: Host }) { {busy ? "Waking…" : `Wake ${host.name}${status}`} + {state === "on" && host.token && ( + + setPadOpen((o) => !o)}> + {padOpen ? "Hide numpad" : "Sign in with PIN"} + + + )} + {state === "on" && padOpen && } ); }