-
Notifications
You must be signed in to change notification settings - Fork 2
Fix/network url and body handling #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8dc5813
faccfb1
395ca43
0c519c7
98f0826
9767108
0b4b526
1524c5f
4099ab4
c765a88
12e0ba1
66252d8
fb09b9b
e15ebc8
30deea2
37baf8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; | |||||||||||||||||||||||||||||||
| import 'package:flutter_localizations/flutter_localizations.dart'; | ||||||||||||||||||||||||||||||||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import 'components/viewers/json_viewer.dart'; | ||||||||||||||||||||||||||||||||
| import 'core/providers/locale_provider.dart'; | ||||||||||||||||||||||||||||||||
| import 'core/routes/app_router.dart'; | ||||||||||||||||||||||||||||||||
| import 'core/theme/app_theme.dart'; | ||||||||||||||||||||||||||||||||
|
|
@@ -17,15 +18,27 @@ class DevConnectApp extends ConsumerStatefulWidget { | |||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| class _DevConnectAppState extends ConsumerState<DevConnectApp> { | ||||||||||||||||||||||||||||||||
| /// Device IDs we've already seen, so a freshly-connected device (vs an | ||||||||||||||||||||||||||||||||
| /// existing one re-emitting) is the trigger for cache invalidation. | ||||||||||||||||||||||||||||||||
| Set<String>? _knownDeviceIds; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||
| void initState() { | ||||||||||||||||||||||||||||||||
| super.initState(); | ||||||||||||||||||||||||||||||||
| // Auto-clear the JSON highlight cache after long background sessions. | ||||||||||||||||||||||||||||||||
| HighlightCacheLifecycleObserver.instance.attach(); | ||||||||||||||||||||||||||||||||
| // Auto-start WebSocket server on app launch | ||||||||||||||||||||||||||||||||
| WidgetsBinding.instance.addPostFrameCallback((_) { | ||||||||||||||||||||||||||||||||
| _autoStartServer(); | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||
| void dispose() { | ||||||||||||||||||||||||||||||||
| HighlightCacheLifecycleObserver.instance.detach(); | ||||||||||||||||||||||||||||||||
| super.dispose(); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Future<void> _autoStartServer() async { | ||||||||||||||||||||||||||||||||
| final server = ref.read(wsServerProvider); | ||||||||||||||||||||||||||||||||
| if (!server.isRunning) { | ||||||||||||||||||||||||||||||||
|
|
@@ -63,6 +76,23 @@ class _DevConnectAppState extends ConsumerState<DevConnectApp> { | |||||||||||||||||||||||||||||||
| // events are recorded even when no Settings page is open. | ||||||||||||||||||||||||||||||||
| ref.watch(deviceHistoryMirrorProvider); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // A. Invalidate the JSON highlight cache when the user picks a | ||||||||||||||||||||||||||||||||
| // different device — data is filtered per-device, so old highlights | ||||||||||||||||||||||||||||||||
| // belong to a different payload. | ||||||||||||||||||||||||||||||||
| ref.listen<String?>(selectedDeviceProvider, (_, next) { | ||||||||||||||||||||||||||||||||
| HighlightCacheLifecycleObserver.instance.clearCache(); | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // B. Invalidate the JSON highlight cache when a NEW device connects. | ||||||||||||||||||||||||||||||||
| // A reconnect of an already-known device (e.g. hot reload) does NOT | ||||||||||||||||||||||||||||||||
| // trigger this — only an addition to the device list. | ||||||||||||||||||||||||||||||||
| final devices = ref.watch(connectedDevicesProvider); | ||||||||||||||||||||||||||||||||
| final ids = devices.map((d) => d.deviceId).toSet(); | ||||||||||||||||||||||||||||||||
| if (_knownDeviceIds != null && ids.any((id) => !_knownDeviceIds!.contains(id))) { | ||||||||||||||||||||||||||||||||
| HighlightCacheLifecycleObserver.instance.clearCache(); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| _knownDeviceIds = ids; | ||||||||||||||||||||||||||||||||
|
Comment on lines
+89
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mutating state variables (like Instead, use
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| final locale = ref.watch(localeProvider); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return MaterialApp.router( | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check
typeof headers === 'object'evaluates totruefor arrays. Ifheadersis passed as an array of key-value pairs (e.g.,string[][]), it will incorrectly enter this block and be wrapped in aProxydesigned for a flat record. This will corrupt the headers when they are spread or read.Adding
!Array.isArray(headers)ensures that array-based headers are correctly handled by the fallback block, which is already supported byreadFinalHeaders.