feat: show connection method (Local/VPN/Remote/Discovered) in app bar and settings
| .. | .. |
|---|
| 62 | 62 | StateProvider<ConnectionStatus>((ref) => ConnectionStatus.disconnected); |
|---|
| 63 | 63 | |
|---|
| 64 | 64 | final connectionDetailProvider = StateProvider<String>((ref) => ''); |
|---|
| 65 | +final connectedViaProvider = StateProvider<String>((ref) => ''); |
|---|
| 65 | 66 | |
|---|
| 66 | 67 | // --- Sessions --- |
|---|
| 67 | 68 | |
|---|
| .. | .. |
|---|
| 196 | 196 | ref.read(wsStatusProvider.notifier).state = status; |
|---|
| 197 | 197 | if (status == ConnectionStatus.connected) { |
|---|
| 198 | 198 | ref.read(connectionDetailProvider.notifier).state = ''; |
|---|
| 199 | + ref.read(connectedViaProvider.notifier).state = _ws?.connectedVia ?? ''; |
|---|
| 200 | + } else { |
|---|
| 201 | + ref.read(connectedViaProvider.notifier).state = ''; |
|---|
| 199 | 202 | } |
|---|
| 200 | 203 | } |
|---|
| 201 | 204 | }; |
|---|
| .. | .. |
|---|
| 1417 | 1420 | connectionDetail, |
|---|
| 1418 | 1421 | style: TextStyle(fontSize: 11, color: Colors.grey.shade400), |
|---|
| 1419 | 1422 | ), |
|---|
| 1423 | + if (wsStatus == ConnectionStatus.connected && ref.watch(connectedViaProvider).isNotEmpty) |
|---|
| 1424 | + Text( |
|---|
| 1425 | + 'via ${ref.watch(connectedViaProvider)}', |
|---|
| 1426 | + style: TextStyle(fontSize: 11, color: Colors.grey.shade500), |
|---|
| 1427 | + ), |
|---|
| 1420 | 1428 | ], |
|---|
| 1421 | 1429 | ), |
|---|
| 1422 | 1430 | actions: [ |
|---|
| .. | .. |
|---|
| 138 | 138 | children: [ |
|---|
| 139 | 139 | StatusDot(status: wsStatus), |
|---|
| 140 | 140 | const SizedBox(width: 12), |
|---|
| 141 | | - Text( |
|---|
| 142 | | - _statusText(wsStatus), |
|---|
| 143 | | - style: Theme.of(context).textTheme.bodyLarge, |
|---|
| 141 | + Expanded( |
|---|
| 142 | + child: Column( |
|---|
| 143 | + crossAxisAlignment: CrossAxisAlignment.start, |
|---|
| 144 | + children: [ |
|---|
| 145 | + Text( |
|---|
| 146 | + _statusText(wsStatus), |
|---|
| 147 | + style: Theme.of(context).textTheme.bodyLarge, |
|---|
| 148 | + ), |
|---|
| 149 | + if (ref.watch(connectedViaProvider).isNotEmpty) |
|---|
| 150 | + Text( |
|---|
| 151 | + 'via ${ref.watch(connectedViaProvider)}', |
|---|
| 152 | + style: TextStyle( |
|---|
| 153 | + fontSize: 12, |
|---|
| 154 | + color: Colors.grey.shade500, |
|---|
| 155 | + ), |
|---|
| 156 | + ), |
|---|
| 157 | + ], |
|---|
| 158 | + ), |
|---|
| 144 | 159 | ), |
|---|
| 145 | 160 | ], |
|---|
| 146 | 161 | ), |
|---|
| .. | .. |
|---|
| 60 | 60 | // Callbacks |
|---|
| 61 | 61 | void Function(ConnectionStatus status)? onStatusChanged; |
|---|
| 62 | 62 | void Function(String detail)? onStatusDetail; // "Probing local...", "Scanning network..." |
|---|
| 63 | + String? connectedHost; // The host we're currently connected to |
|---|
| 64 | + String? connectedVia; // "Local", "VPN", "Remote", "Bonjour", "Scan" |
|---|
| 63 | 65 | void Function(Map<String, dynamic> message)? onMessage; |
|---|
| 64 | 66 | void Function()? onOpen; |
|---|
| 65 | 67 | void Function()? onClose; |
|---|
| .. | .. |
|---|
| 158 | 160 | } |
|---|
| 159 | 161 | |
|---|
| 160 | 162 | if (winner != null && !_intentionalClose) { |
|---|
| 161 | | - _mqttLog('MQTT: winner: $winner, connecting...'); |
|---|
| 162 | | - onStatusDetail?.call('Connecting to $winner...'); |
|---|
| 163 | + // Determine connection method label |
|---|
| 164 | + if (winner == config.localHost) { |
|---|
| 165 | + connectedVia = 'Local'; |
|---|
| 166 | + } else if (winner == config.vpnHost) { |
|---|
| 167 | + connectedVia = 'VPN'; |
|---|
| 168 | + } else if (winner == config.host) { |
|---|
| 169 | + connectedVia = 'Remote'; |
|---|
| 170 | + } else if (winner == _lastDiscoveredHost) { |
|---|
| 171 | + connectedVia = 'Discovered'; |
|---|
| 172 | + } else { |
|---|
| 173 | + connectedVia = winner; |
|---|
| 174 | + } |
|---|
| 175 | + connectedHost = winner; |
|---|
| 176 | + _mqttLog('MQTT: winner: $winner ($connectedVia), connecting...'); |
|---|
| 177 | + onStatusDetail?.call('Connecting via $connectedVia...'); |
|---|
| 163 | 178 | try { |
|---|
| 164 | 179 | if (await _tryConnect(winner, clientId, timeout: 5000)) return; |
|---|
| 165 | 180 | } catch (e) { |
|---|
| 166 | 181 | _mqttLog('MQTT: connect to $winner failed: $e'); |
|---|
| 182 | + connectedHost = null; |
|---|
| 183 | + connectedVia = null; |
|---|
| 167 | 184 | } |
|---|
| 168 | 185 | } |
|---|
| 169 | 186 | |
|---|