Repository navigation
feat(android): opt-in LAN web host for phone library sharing - #10
Conversation
Allow Android Local mode to bind the existing Axum server on 0.0.0.0 with required token auth and a dedicated foreground service, so other devices can open the same LAN web UI on Wi-Fi. Co-authored-by: Cursor <cursoragent@cursor.com>
Reviewer's GuideData structuresAdd the persisted Android migration flag and expose it in the TypeScript settings type so older loopback settings can be distinguished from an explicit LAN-sharing opt-in.
APIAllow the Tauri stop-LAN command to await shutdown and make the frontend LAN commands available to mobile runtimes as well as desktop.
Uses of the APIExpose LAN hosting capability for Android Local or standalone mode, and update settings consumers and coverage to reflect that capability.
ImplementationMake Android startup select LAN or loopback hosting based on the opt-in setting, and clear stale Android LAN flags once during migration.
Implement LAN-host switching, Android token enforcement, foreground-service lifecycle, and restoration of the loopback media server when sharing stops.
Add the Android foreground service and plugin commands that keep LAN sharing alive independently of download notifications, with Rust bridge helpers to invoke them.
UIPresent Android LAN sharing instructions, required-token messaging, and host-specific controls in Settings while retaining desktop behavior.
ConfigurationInstall and validate the Android LAN foreground service and register it in the generated Android manifest.
DocumentationDocument Android hosting, setup, URLs, authentication, client use, and platform-specific constraints alongside the existing LAN guide.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
| } | ||
|
|
||
| private fun buildNotification(title: String, text: String): Notification { | ||
| val launch = packageManager.getLaunchIntentForPackage(packageName) |
There was a problem hiding this comment.
WARNING: getLaunchIntentForPackage can return null
packageManager.getLaunchIntentForPackage(packageName) returns null if the app doesn't have a launchable activity (e.g., if the manifest lacks a MAIN/LAUNCHER intent filter). This would make pending null, causing the notification's setContentIntent(pending) to crash or produce a notification that doesn't open the app when tapped.
| val launch = packageManager.getLaunchIntentForPackage(packageName) | |
| val launch = packageManager.getLaunchIntentForPackage(packageName) ?: return buildNotification(title, text) |
| lanServer: | ||
| runtime === "desktop-tauri" || | ||
| (runtime === "mobile-tauri" && | ||
| isAndroidTauri() && |
There was a problem hiding this comment.
WARNING: lanServer capability includes retired standalone engine mode
The lanServer capability check at lines 36-40 includes settings.engine_mode === "standalone". However, the PR description and bootstrap_mobile_settings in lib.rs (lines 102-107) state that "Standalone" is retired and migrated to "local". Keeping this check could incorrectly enable LAN hosting for users who have stale standalone values in their settings before migration runs.
| isAndroidTauri() && | |
| (runtime === "mobile-tauri" && | |
| isAndroidTauri() && | |
| settings.engine_mode === "local"), |
| #[cfg(target_os = "android")] | ||
| { | ||
| use serde_json::json; | ||
| let _ = with_plugin_state(app, |state| { |
There was a problem hiding this comment.
WARNING: Silent error suppression in LAN share keep-alive functions
Both start_lan_share_keep_alive (lines 410-426) and stop_lan_share_keep_alive (lines 428-443) use let _ = with_plugin_state(...) which silently discards any errors from the Kotlin plugin. If the foreground service fails to start/stop (e.g., due to missing manifest registration, permission issues, or plugin not initialized), the Rust side has no visibility and the UI shows no feedback.
| *self.lan_server.lock() = Some(server); | ||
| settings.lan_enabled = true; | ||
| settings.lan_port = port; | ||
| if force_auth { |
There was a problem hiding this comment.
CRITICAL: Force-enabling lan_auth_enabled on Android without ensuring a valid token exists
When force_auth is true (Android), the code sets settings.lan_auth_enabled = true at line 1338. However, the token is generated at lines 1320-1323 and could theoretically be empty if generate_token() fails or returns empty. At lines 1340-1344, if the token is empty, settings.lan_token is set to None. This creates an inconsistent state: lan_auth_enabled = true but lan_token = None. The Axum server would then require auth but have no token to validate against, causing all requests to fail.
| if force_auth { | |
| if force_auth { | |
| settings.lan_auth_enabled = true; | |
| // Ensure token is never empty when auth is forced | |
| if token.is_empty() { | |
| token = crate::server::generate_token(); | |
| } | |
| } |
| /// Site adapters need this to append `?token=` to the proxy URLs they hand | ||
| /// to the WebView. | ||
| /// to the WebView (which still hits 127.0.0.1). | ||
| pub fn loopback_token(&self) -> Option<String> { |
There was a problem hiding this comment.
SUGGESTION: Misleading function name loopback_token now returns token for LAN host too
The function loopback_token() at lines 1388-1393 was changed to return the token regardless of whether the server is loopback or LAN (the old code had server.is_loopback().then(...)). The comment says "Token of the RUNNING on-device media server (loopback or Android LAN host)" but the name loopback_token suggests it only returns loopback tokens. Consider renaming to device_server_token() or active_media_token() for clarity.
Code Review SummaryStatus: 5 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)CRITICAL
WARNING
SUGGESTION
Files Reviewed (19 files)
Fix these issues in Kilo Cloud Reviewed by free · Input: 237.3K · Output: 11.2K · Cached: 1.4M |
Summary
0.0.0.0), with token auth always required and a one-shot migration so old loopbacklan_enabledflags do not suddenly expose the network.LanShareForegroundService(separate from download keep-alive) plus Settings UI/docs so phones can share a copy-link/QR web UI while a notification keeps the process alive.Test plan
http://<phone-ip>:8787/?token=...bun run lint,bun run format:check, andcargo check/cargo testas availableSummary by Sourcery
Enable opt-in, authenticated LAN library sharing from Android Local mode while preserving secure defaults and loopback playback when sharing is disabled.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: