Adapt mesh views to phone rotation and toggle the exit from Quick Settings
Use the available width for the Android device table, keeping individual peers expandable and their full details reachable in both orientations. Show network selection and settings side by side in landscape and reuse the VIP editor with a compact toolbar and width-aware backend columns. Retain the selected network, expanded peer, traffic unit and VIP draft across rotation. Show data-channel readiness consistently in the tray and on Android. Distinguish an establishing channel, a disabled data plane, an offline peer and a transport failure. Use an animated arc for visible waiting peers. Explain Phosphor controls on hover, focus and long press, and provide a masked-by-default reveal button in the shared secret field. Store the last confirmed exit network and endpoint in Android's private preferences. A Quick Settings tap disconnects that selection or restores the exact peer through the existing agent. First use opens the chooser. On a cold start, wait for an authenticated exit offer outside the command loop. Check the current selection again before changing the route. Only changed exit offers wake roster subscribers. Wire formats, software version and mesh identity storage remain compatible. On macOS arm64, cargo fmt and strict workspace Clippy passed. The locked workspace suite passed 598 tests with four opt-in tests ignored. Built the tray, the ARM64 debug APK and its test APK. All three instrumentation tests passed on an Android API 37 emulator. Opened the chooser from the actual Quick Settings tile, rotated the activity and inspected rendered device lists with ready, waiting, failed and offline peers. Physical phones and native Linux and Windows builds were not exercised.
This commit is contained in:
1 parent
50c0ecea45
commit
e3e6089d0b
29 files changed
+1688
-324
No files matched your search
@@ -25,6 +25,13 @@ pub enum Request {
|
||||
/// Endpoint id captured at the same time.
|
||||
peer: String,
|
||||
},
|
||||
/// Restore a remembered network/peer pair only while no other exit is selected.
|
||||
RestoreExit {
|
||||
/// Network saved at the last successful selection.
|
||||
network: String,
|
||||
/// Peer used in that network.
|
||||
peer: String,
|
||||
},
|
||||
}
|
||||
|
||||
/// A configured default route stays visible if its remote peer goes offline.
|
||||
@@ -72,6 +79,66 @@ pub async fn disconnect_exit(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn restore_exit(agent: &Agent, network: &str, peer: &str) -> Result<Outcome, String> {
|
||||
let network = network.parse().map_err(|_| "Invalid saved network ID")?;
|
||||
let peer = peer.parse().map_err(|_| "Invalid saved peer ID")?;
|
||||
let status = agent.status().await.map_err(|e| e.to_string())?;
|
||||
for n in &status.networks {
|
||||
if n.state == tsunagi::agent::NetworkState::Active
|
||||
&& let Some(current) = n.exit_via
|
||||
{
|
||||
return if n.network_id == network && current == peer {
|
||||
Ok(Outcome::Applied)
|
||||
} else {
|
||||
Err("Another exit is already selected".into())
|
||||
};
|
||||
}
|
||||
}
|
||||
agent
|
||||
.set_exit_via(network, Some(peer))
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
Ok(Outcome::Applied)
|
||||
}
|
||||
|
||||
// On cold start the first snapshot often precedes peer discovery. Wait on the
|
||||
// service's roster notifications, outside the command loop, then let the usual
|
||||
// serialized command validate the selection again before touching the route.
|
||||
#[cfg(any(target_os = "android", test))]
|
||||
pub(crate) async fn wait_for_exit_offer(
|
||||
state: &mut watch::Receiver<State>,
|
||||
network: &str,
|
||||
peer: &str,
|
||||
) -> Result<(), String> {
|
||||
tokio::time::timeout(std::time::Duration::from_secs(15), async {
|
||||
loop {
|
||||
match &*state.borrow_and_update() {
|
||||
State::Ready(report, _) => {
|
||||
let n = report
|
||||
.networks
|
||||
.iter()
|
||||
.find(|n| n.network_id == network && n.active)
|
||||
.ok_or("The saved exit network is no longer active")?;
|
||||
if report
|
||||
.networks
|
||||
.iter()
|
||||
.any(|n| n.active && n.exit.via.is_some())
|
||||
|| n.peers.iter().any(|p| p.endpoint_id == peer && p.exit_node)
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
State::Off => return Err("Tsunagi Agent stopped".into()),
|
||||
State::Error(error) => return Err(error.clone()),
|
||||
State::Starting => {}
|
||||
}
|
||||
state.changed().await.map_err(|_| "Tsunagi Agent stopped")?;
|
||||
}
|
||||
})
|
||||
.await
|
||||
.map_err(|_| "The saved peer is offline or no longer offers an exit")?
|
||||
}
|
||||
|
||||
/// Private reply delivered only to the UI that requested the action.
|
||||
pub enum Outcome {
|
||||
/// The agent has applied the action.
|
||||
@@ -256,6 +323,7 @@ pub async fn serve(
|
||||
}
|
||||
Request::DisconnectExit {network, peer} => disconnect_exit(&agent, &network, &peer).await
|
||||
.map(|()| Outcome::Applied).map_err(|e| e.to_string()),
|
||||
Request::RestoreExit {network, peer} => restore_exit(&agent, &network, &peer).await,
|
||||
};
|
||||
(Some((reply, result)), refresh_zones)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user