diff --git a/README.md b/README.md index c46b06d..672120d 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,7 @@ While it runs, refryt answers device discovery on the local network (UDP port 19 If the computer doesn't show up in the phone's Cast menu, a firewall is usually the reason. Both ports have to be let in: - **Linux** with ufw: `sudo ufw allow from 192.168.0.0/16 to any port 1900 proto udp` and `sudo ufw allow from 192.168.0.0/16 to any port 47023 proto tcp`, with your own network's range if it isn't `192.168.x.x`. With firewalld: `sudo firewall-cmd --permanent --add-port=1900/udp --add-port=47023/tcp` and `sudo firewall-cmd --reload`. The ? next to the setting has these ready to copy, for your network and port. -- **Windows** asks once, the first time the setting is on, whether refryt may use the network. Allow it on private networks. +- **Windows** Firewall needs a rule for refryt, including on a network Windows calls Public, and its own "allow access" prompt doesn't always leave one. The ? next to the setting has PowerShell commands ready to copy, for this copy of refryt and your network's range, to run as administrator. - **macOS** may ask whether refryt may accept incoming connections. Allow it. ### Signing in diff --git a/crates/refryt/src/ui/settings.rs b/crates/refryt/src/ui/settings.rs index 82d1e61..a703527 100644 --- a/crates/refryt/src/ui/settings.rs +++ b/crates/refryt/src/ui/settings.rs @@ -1128,13 +1128,35 @@ fn cast_help(ui: &mut egui::Ui, p: &theme::Palette, port: u16) { ), ); } + // Windows' own "allow access" prompt is not enough: it may never come up, it covers only + // the profiles ticked in it, and a network Windows calls Public is the default. So the + // rule is spelled out, for this exe and this network's range. The range is written out + // rather than `LocalSubnet`: with that keyword the phone's discovery searches were still + // dropped in testing, and with the range they came in. #[cfg(target_os = "windows")] - line( - ui, - "The first time this is on, Windows asks whether refryt may use the network. Allow \ - it on private networks. If you said no, allow refryt under Windows Security, \ - Firewall & network protection, Allow an app through firewall.", - ); + { + let exe = std::env::current_exe() + .map(|p| p.display().to_string()) + .unwrap_or_else(|_| r"C:\Program Files\refryt\refryt.exe".to_owned()); + let from = local_range().map_or(String::new(), |r| format!(" -RemoteAddress {r}")); + ui.add_space(4.0); + line( + ui, + "Windows Firewall lets neither in until a rule allows it, on a Public network \ + too. In PowerShell run as administrator:", + ); + command( + ui, + p, + "cast-windows", + &format!( + "New-NetFirewallRule -DisplayName \"refryt cast discovery\" -Direction Inbound \ + -Action Allow -Program \"{exe}\" -Protocol UDP -LocalPort 1900{from}\n\ + New-NetFirewallRule -DisplayName \"refryt cast pairing\" -Direction Inbound \ + -Action Allow -Program \"{exe}\" -Protocol TCP -LocalPort {port}{from}" + ), + ); + } #[cfg(target_os = "macos")] line( ui, @@ -1146,7 +1168,7 @@ fn cast_help(ui: &mut egui::Ui, p: &theme::Palette, port: u16) { } /// Commands to paste into a terminal, in a box with a Copy button. -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "linux", target_os = "windows"))] fn command(ui: &mut egui::Ui, p: &theme::Palette, id: &str, text: &str) { let copied_id = ui.id().with((id, "copied")); let copied_at: Option = ui.data(|d| d.get_temp(copied_id)); @@ -1196,7 +1218,7 @@ fn command(ui: &mut egui::Ui, p: &theme::Palette, id: &str, text: &str) { /// The private range this computer's network address is in, for a firewall rule that lets in /// only this network. Asks the system which address it would send from, without sending. -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "linux", target_os = "windows"))] fn local_range() -> Option<&'static str> { let socket = std::net::UdpSocket::bind(("0.0.0.0", 0)).ok()?; socket.connect(("239.255.255.250", 1900)).ok()?;