mirror of
https://github.com/block/buzz.git
synced 2026-11-24 02:02:07 +00:00
fix(mobile): name the screen the person is on, from an app-owned list
The screen table moves out of shared/diagnostics to lib/diagnostic_screens.dart and reaches the observers through diagnosticScreenClassifierProvider, which the root scope overrides. The shared conversation pane no longer imports every feature page. A route hosting a navigator with a page open past its first, such as a phone conversation over the channel list, is named by that page, so closing a cover over an open channel records the channel. A screen equal to the last one is skipped, which removes the doubled crumbs from pane hosts and wide section changes while keeping the pane placeholder's crumb after sign-in. Adding a community is named addCommunity, the hosted setup route is named onboarding, and the Duo channel sheet route leaves no crumb. Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost> Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
@@ -46,7 +46,7 @@ A build that is given a [reporting destination](../CONTEXT.md#reporting-destinat
|
||||
- **Networking measurements.** Every request through the app's shared HTTP client and every relay connection event (connected, disconnected, reconnect attempt, request timed out, subscription closed by the relay) is counted with four attributes: backend, endpoint, outcome and kind of failure. The backend is the host name of the server the app was talking to. Endpoints are names from a fixed list, never raw paths. Durations are recorded for requests and for time to connect. HTTP is measured where the app's shared HTTP client already classifies transport failures; relay connections are measured by hand in the relay session, since the SDK documents no WebSocket instrumentation.
|
||||
- **Counts are handed to the SDK as they happen**, including while the network is down. The app does no buffering of its own, and the SDK's default limit on unsent data is kept. Accepted consequence: in a long outage the oldest unsent reports can be dropped.
|
||||
- **No log lines in step one.** The counts carry the member and the time. The first implementation task confirms that the destination can filter counts by member; if it cannot, the fallback is one log line per outage, sent after it ends.
|
||||
- **Breadcrumbs come from a fixed list:** networking events and screen names, written by the app, and the app moving to the foreground or background, written by the SDK. A screen name comes from the app's own list of screens (such as the channel list, a channel, a thread or settings), with any other page called "other". It is never a channel or community name, an ID, a route's settings or anything a screen shows, so a report shows which screens the person was on and not what they were looking at. A breadcrumb is left when the person moves to a page or back to one. Dialogs, sheets and menus leave none. The SDK's other automatic breadcrumbs, which could carry content or addresses, are turned off or filtered.
|
||||
- **Breadcrumbs come from a fixed list:** networking events and screen names, written by the app, and the app moving to the foreground or background, written by the SDK. A screen name comes from the app's own list of screens (such as the channel list, a channel, a thread or settings), with any other page called "other". It is never a channel or community name, an ID, a route's settings or anything a screen shows, so a report shows which screens the person was on and not what they were looking at. A breadcrumb is left when the person moves to a page or back to one, unless it names the same screen as the one before. Dialogs, sheets and menus leave none. The SDK's other automatic breadcrumbs, which could carry content or addresses, are turned off or filtered.
|
||||
- **Who a report is about.** The member's public key is set as the report's user when a session starts and cleared when it ends. When the session is a Builderlab account, the Builderlab's origin and the account's subject identifier are added, never its email address. Every report also carries the app's own random per-install identifier, created on first launch and kept in a file that device backups and transfers skip, so a phone restored from another gets its own, as a separate field, signed in or not, so reports from one device can be matched to the members who used it, and a member's reports to the devices they used. With no member set, for example before sign-in, the SDK fills the report's user with its own random per-install identifier, on Dart and native reports alike. On iOS, native crash and hang reports also carry the SDK's device app hash: a hash of the identifier iOS gives the app's vendor, the hardware model and the bundle identifier, stable across launches and across a reinstall while another app from the same vendor stays installed. The Dart filter drops it, so Dart reports don't carry it. The SDK also sends session records, so the destination can show a crash-free rate. A session begins each time the app starts or returns after 30 seconds or more in the background. The SDK sends a record when it begins, an update each time an error is counted, and a last record when it ends. Together they carry when the session started, how many errors it had, how it ended (normally, crashed or abnormally), the time from start to end (not time in active use), the release, the environment and the SDK's identifier.
|
||||
- **One filter before anything leaves.** Errors, breadcrumbs and counts from Dart all pass through a single filter that removes URL query strings and fragments, drops any attribute not on the allowed list, replaces every error's own text with fixed wording, drops what the SDK adds about the failing widget or platform call, and keeps only the app, operating system, device and runtime details among the report's contexts, so the SDK's accessibility settings, locale and the device's own name stay on the device. An error keeps its type and stack trace. The SDK's options for sending personal data, screenshots, view hierarchies and session recordings stay off.
|
||||
- **Main-thread hangs** are captured by the SDK's own hang detection, at the SDK's default thresholds. The app's Dart code runs on the platform's main thread, so Dart work that blocks it shows up here. On iOS, the SDK reports the main thread being blocked, fully or mostly, for 2 seconds or more while the app is active, with the main thread's stack taken during the hang, including freezes the app recovers from. A hang that is still going when the app is killed, for example by the system watchdog, is sent on the next launch as a fatal hang. The SDK's separate watchdog-termination tracking also reports, on the next launch, a run that ended while the app was in the foreground with nothing else to explain it; it never reports on simulators or for kills in the background. App hang detection is off while a debugger is attached ([sentry-cocoa 9.35.0](https://github.com/getsentry/sentry-cocoa/blob/9.35.0/Sources/Swift/Integrations/AppHangTracking/SentryHangTrackingIntegration.swift)). On Android the SDK reports only freezes the system itself declared "app not responding". On Android 11 and later it reports only one that ended the process, read from the system's exit records on the next launch: the most recent unreported one, and only when the system kept a usable thread dump. Before Android 11 it reports when the main thread has been blocked for 5 seconds and the system has marked the app not responding, never with a debugger attached ([sentry-java 8.64.0](https://github.com/getsentry/sentry-java/blob/8.64.0/sentry-android-core/src/main/java/io/sentry/android/core/AnrIntegrationFactory.java)). So with these defaults, a freeze the app recovers from is reported on iOS, and on Android only before Android 11 and only once the system has marked the app not responding. Dart frames in a hang's stack are readable only with the Dart code's debug symbols at the destination, the same as for crashes.
|
||||
|
||||
@@ -55,7 +55,6 @@ import 'shared/deeplink/pending_deep_link_provider.dart';
|
||||
import 'shared/emoji/emoji_burst.dart';
|
||||
import 'shared/relay/relay.dart';
|
||||
import 'shared/diagnostics/diagnostic_navigation_observer.dart';
|
||||
import 'shared/diagnostics/diagnostic_reporter.dart';
|
||||
import 'shared/theme/theme.dart';
|
||||
import 'shared/widgets/buzz_loading_indicator.dart';
|
||||
import 'shared/read_state/failed_clear_notice.dart';
|
||||
@@ -479,8 +478,9 @@ class App extends HookConsumerWidget {
|
||||
);
|
||||
final latestHome = useRef<Widget?>(null)..value = home;
|
||||
final screenObserver = useMemoized(
|
||||
() => DiagnosticNavigationObserver(ref.read(diagnosticReporterProvider)),
|
||||
ref.read(diagnosticScreenTrailProvider).observer,
|
||||
);
|
||||
useEffect(() => screenObserver.dispose, [screenObserver]);
|
||||
|
||||
return MaterialApp(
|
||||
navigatorKey: _mobileRootNavigatorKey,
|
||||
|
||||
50
mobile/lib/diagnostic_screens.dart
Normal file
50
mobile/lib/diagnostic_screens.dart
Normal file
@@ -0,0 +1,50 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'features/activity/activity_page.dart';
|
||||
import 'features/agents/agents_page.dart';
|
||||
import 'features/channels/channel_actions_sheet.dart';
|
||||
import 'features/channels/channel_detail_page.dart';
|
||||
import 'features/channels/channels_page.dart';
|
||||
import 'features/channels/media_viewer_page.dart';
|
||||
import 'features/channels/thread_detail_page.dart';
|
||||
import 'features/forum/forum_thread_page.dart';
|
||||
import 'features/home/home_page.dart';
|
||||
import 'features/invites/invite_create_page.dart';
|
||||
import 'features/onboarding/hosted_connect_page.dart';
|
||||
import 'features/pairing/pairing_page.dart';
|
||||
import 'features/profile/profile_edit_page.dart';
|
||||
import 'features/search/search_page.dart';
|
||||
import 'features/settings/settings_page.dart';
|
||||
import 'features/settings/theme_picker_page.dart';
|
||||
import 'onboarding_app_entry.dart';
|
||||
import 'organization_app_entry.dart';
|
||||
import 'shared/diagnostics/diagnostic_reporter.dart';
|
||||
|
||||
/// The app's pages that have a name in a report's trail of screens, for
|
||||
/// `diagnosticScreenClassifierProvider`. Add a page here to name it. A route is
|
||||
/// named by the first page below it that this names, so a page that wraps
|
||||
/// another listed page names both.
|
||||
DiagnosticScreen? diagnosticScreenOf(Widget page) => switch (page) {
|
||||
HomePage() => DiagnosticScreen.channelList,
|
||||
ChannelDetailPage() => DiagnosticScreen.channel,
|
||||
ThreadDetailPage() => DiagnosticScreen.thread,
|
||||
ForumThreadPage() => DiagnosticScreen.forumPost,
|
||||
ChannelDetailsPage() => DiagnosticScreen.channelDetails,
|
||||
SearchPage() => DiagnosticScreen.search,
|
||||
ActivityPage() => DiagnosticScreen.activity,
|
||||
SettingsPage() => DiagnosticScreen.settings,
|
||||
ThemePickerPage() => DiagnosticScreen.appearance,
|
||||
ProfileEditPage() => DiagnosticScreen.profile,
|
||||
AgentsPage() => DiagnosticScreen.agents,
|
||||
CommunityInvitePage() => DiagnosticScreen.invites,
|
||||
CommunitySwitcherPage() => DiagnosticScreen.communitySwitcher,
|
||||
OnboardingAppEntry(addingCommunity: true) ||
|
||||
PairingPage(addingCommunity: true) => DiagnosticScreen.addCommunity,
|
||||
MediaImageViewerPage() ||
|
||||
MediaVideoViewerPage() => DiagnosticScreen.mediaViewer,
|
||||
OnboardingAppEntry() ||
|
||||
OrganizationAppEntry() ||
|
||||
PairingPage() ||
|
||||
HostedSetupSteps() => DiagnosticScreen.onboarding,
|
||||
_ => null,
|
||||
};
|
||||
@@ -11,6 +11,7 @@ import 'package:flutter/services.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:buzz/shared/theme/buzz_icons.dart';
|
||||
|
||||
import '../../shared/diagnostics/diagnostic_navigation_observer.dart';
|
||||
import '../../shared/clipboard_utils.dart';
|
||||
import '../../shared/relay/relay.dart';
|
||||
import '../../shared/identity_archives/identity_archives.dart';
|
||||
@@ -82,7 +83,8 @@ bool _usesNativeChannelSheet(BuildContext context) {
|
||||
}
|
||||
|
||||
// Keep the result alive after retiring the invisible route for relay work.
|
||||
class _NativeChannelSheetRoute extends PageRouteBuilder<bool> {
|
||||
class _NativeChannelSheetRoute extends PageRouteBuilder<bool>
|
||||
with DiagnosticSheetRoute<bool> {
|
||||
_NativeChannelSheetRoute(WidgetBuilder builder)
|
||||
: super(
|
||||
opaque: false,
|
||||
|
||||
@@ -40,7 +40,7 @@ class HostedConnectPage extends HookConsumerWidget {
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop) stepsNavigator.currentState?.maybePop();
|
||||
},
|
||||
child: _HostedSteps(
|
||||
child: HostedSetupSteps(
|
||||
navigatorKey: stepsNavigator,
|
||||
flow: flow,
|
||||
onAddCommunity: onAddCommunity,
|
||||
@@ -73,8 +73,10 @@ class HostedConnectPage extends HookConsumerWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _HostedSteps extends HookWidget {
|
||||
const _HostedSteps({
|
||||
/// The hosted setup steps, pushed as one screen above [HostedConnectPage].
|
||||
class HostedSetupSteps extends HookWidget {
|
||||
const HostedSetupSteps({
|
||||
super.key,
|
||||
required this.navigatorKey,
|
||||
required this.flow,
|
||||
this.onAddCommunity,
|
||||
|
||||
@@ -7,11 +7,13 @@ import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'app.dart';
|
||||
import 'diagnostic_screens.dart';
|
||||
import 'features/age_gate/age_signal_push_bootstrap.dart';
|
||||
import 'features/agents/agents_page.dart';
|
||||
import 'features/invites/invite_join_provider.dart';
|
||||
import 'shared/agents/agents_surface.dart';
|
||||
import 'shared/diagnostics/diagnostic_member_binding.dart';
|
||||
import 'shared/diagnostics/diagnostic_navigation_observer.dart';
|
||||
import 'shared/diagnostics/diagnostic_reporter.dart';
|
||||
import 'shared/diagnostics/diagnostic_startup.dart';
|
||||
import 'shared/push/push_bridge.dart';
|
||||
@@ -79,6 +81,7 @@ ProviderScope buildRootProviderScope({
|
||||
(context, link) async => unawaited(showAgents(context, draft: link)),
|
||||
),
|
||||
diagnosticReporterProvider.overrideWithValue(reporter),
|
||||
diagnosticScreenClassifierProvider.overrideWithValue(diagnosticScreenOf),
|
||||
savedPrefsProvider.overrideWithValue(prefs),
|
||||
if (mediaCacheRoot != null)
|
||||
mediaCacheRootProvider.overrideWith((ref) => mediaCacheRoot()),
|
||||
|
||||
@@ -1,45 +1,57 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
import 'diagnostic_reporter.dart';
|
||||
import 'diagnostic_screens.dart';
|
||||
|
||||
/// Names the screen a page widget is, or null for a widget that is not a
|
||||
/// listed page. The app supplies its list of pages
|
||||
/// ([diagnosticScreenClassifierProvider]); an unlisted page is reported as
|
||||
/// [DiagnosticScreen.other], never by its own type name, which release builds
|
||||
/// can obfuscate.
|
||||
typedef DiagnosticScreenClassifier = DiagnosticScreen? Function(Widget page);
|
||||
|
||||
/// The app's list of named pages. The root scope overrides it, so the list
|
||||
/// lives with the app rather than below the features it names.
|
||||
final diagnosticScreenClassifierProvider = Provider<DiagnosticScreenClassifier>(
|
||||
(ref) => throw UnimplementedError('The app supplies its list of screens.'),
|
||||
);
|
||||
|
||||
/// The trail shared by every navigator that holds screens.
|
||||
final diagnosticScreenTrailProvider = Provider<DiagnosticScreenTrail>(
|
||||
(ref) => DiagnosticScreenTrail(
|
||||
ref.watch(diagnosticReporterProvider),
|
||||
() => ref.read(diagnosticScreenClassifierProvider),
|
||||
),
|
||||
);
|
||||
|
||||
/// Leaves a breadcrumb for each screen the person moves to or back to, so a
|
||||
/// report shows which screens they were on.
|
||||
///
|
||||
/// Attach one to each navigator that holds screens: the app's root navigator
|
||||
/// and the pane navigator that holds an open conversation. Only pages
|
||||
/// ([PageRoute]) count. Dialogs, sheets and menus are popup routes with no
|
||||
/// screen of their own, so opening or closing one leaves nothing. A build
|
||||
/// Give an [observer] to each navigator that holds screens: the app's root
|
||||
/// navigator and the pane navigator that holds an open conversation. Only
|
||||
/// pages ([PageRoute]) count. Dialogs, sheets and menus are popup routes or
|
||||
/// [DiagnosticSheetRoute]s with no screen of their own, so opening or closing
|
||||
/// one leaves nothing. A screen equal to the last one left is skipped. A build
|
||||
/// without a reporting destination does nothing, not even looking at routes.
|
||||
class DiagnosticNavigationObserver extends NavigatorObserver {
|
||||
DiagnosticNavigationObserver(this._reporter);
|
||||
class DiagnosticScreenTrail {
|
||||
DiagnosticScreenTrail(this._reporter, this._classifier);
|
||||
|
||||
final DiagnosticReporter _reporter;
|
||||
final DiagnosticScreenClassifier Function() _classifier;
|
||||
final _observers = <DiagnosticNavigationObserver>{};
|
||||
DiagnosticScreen? _last;
|
||||
|
||||
@override
|
||||
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) =>
|
||||
_arrived(route);
|
||||
/// How many elements a search below a route may look at. A page sits near
|
||||
/// the top of its route; this keeps an unlisted page from costing a walk of
|
||||
/// everything it shows.
|
||||
static const _searchBudget = 3000;
|
||||
|
||||
@override
|
||||
void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) =>
|
||||
_arrived(newRoute);
|
||||
|
||||
@override
|
||||
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) =>
|
||||
_revealed(route, previousRoute);
|
||||
|
||||
@override
|
||||
void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) =>
|
||||
_revealed(route, previousRoute);
|
||||
|
||||
void _arrived(Route<dynamic>? route) {
|
||||
if (route is PageRoute<dynamic>) _announce(route);
|
||||
}
|
||||
|
||||
void _revealed(Route<dynamic> left, Route<dynamic>? revealed) {
|
||||
if (left is PageRoute<dynamic> && revealed is PageRoute<dynamic>) {
|
||||
_announce(revealed);
|
||||
}
|
||||
/// A new observer for one navigator. [DiagnosticNavigationObserver.dispose]
|
||||
/// it with its navigator.
|
||||
DiagnosticNavigationObserver observer() {
|
||||
final observer = DiagnosticNavigationObserver._(this);
|
||||
_observers.add(observer);
|
||||
return observer;
|
||||
}
|
||||
|
||||
/// Names [route] once the frame has built it, if it is then what the person
|
||||
@@ -49,12 +61,64 @@ class DiagnosticNavigationObserver extends NavigatorObserver {
|
||||
if (!_reporter.reporting) return;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!_shown(route)) return;
|
||||
_reporter.leaveBreadcrumb(
|
||||
DiagnosticBreadcrumb.screen(DiagnosticScreens.of(route)),
|
||||
);
|
||||
final screen = screenOf(route);
|
||||
if (screen == _last) return;
|
||||
_last = screen;
|
||||
_reporter.leaveBreadcrumb(DiagnosticBreadcrumb.screen(screen));
|
||||
});
|
||||
}
|
||||
|
||||
/// The screen [route] shows, once it has been built.
|
||||
///
|
||||
/// A route has no name of its own here: the app pushes page widgets without
|
||||
/// route settings, and where settings exist they can carry IDs. So a route
|
||||
/// that hosts a navigator with a page open past its first, such as a
|
||||
/// conversation over a list, shows that page. Otherwise it is named by the
|
||||
/// first listed page widget below it, and a route showing none is
|
||||
/// [DiagnosticScreen.other]. Nothing is read from a route's settings, its
|
||||
/// arguments or what the page shows.
|
||||
@visibleForTesting
|
||||
DiagnosticScreen screenOf(ModalRoute<dynamic> route) {
|
||||
if (_openPage(route) case final ModalRoute<dynamic> page) {
|
||||
return screenOf(page);
|
||||
}
|
||||
if (route.subtreeContext case final BuildContext context) {
|
||||
final classify = _classifier();
|
||||
var budget = _searchBudget;
|
||||
DiagnosticScreen? found;
|
||||
void visit(Element element) {
|
||||
if (found != null || budget-- <= 0) return;
|
||||
found = classify(element.widget);
|
||||
if (found == null) element.visitChildElements(visit);
|
||||
}
|
||||
|
||||
(context as Element).visitChildElements(visit);
|
||||
if (found != null) return found!;
|
||||
}
|
||||
// The first route of a nested navigator is its container, such as the
|
||||
// empty list side of a pane, and shows whatever hosts that navigator.
|
||||
// After sign-in this is what names Home.
|
||||
if (route.isFirst) {
|
||||
final navigator = route.navigator;
|
||||
final host = navigator == null ? null : ModalRoute.of(navigator.context);
|
||||
if (host != null) return screenOf(host);
|
||||
}
|
||||
return DiagnosticScreen.other;
|
||||
}
|
||||
|
||||
/// The page open past the first in a navigator that [route] hosts.
|
||||
ModalRoute<dynamic>? _openPage(ModalRoute<dynamic> route) {
|
||||
for (final observer in _observers) {
|
||||
final navigator = observer.navigator;
|
||||
if (navigator == null || ModalRoute.of(navigator.context) != route) {
|
||||
continue;
|
||||
}
|
||||
final page = observer._currentPage;
|
||||
if (page != null && !page.isFirst) return page;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Whether [route] is current on its navigator and every navigator hosting
|
||||
/// it.
|
||||
static bool _shown(Route<dynamic> route) {
|
||||
@@ -65,3 +129,63 @@ class DiagnosticNavigationObserver extends NavigatorObserver {
|
||||
return host == null || _shown(host);
|
||||
}
|
||||
}
|
||||
|
||||
/// A page route that presents a sheet rather than a screen, so it leaves no
|
||||
/// breadcrumb opening or closing.
|
||||
mixin DiagnosticSheetRoute<T> on PageRoute<T> {}
|
||||
|
||||
/// Reports one navigator's pages to a [DiagnosticScreenTrail].
|
||||
class DiagnosticNavigationObserver extends NavigatorObserver {
|
||||
DiagnosticNavigationObserver._(this._trail);
|
||||
|
||||
final DiagnosticScreenTrail _trail;
|
||||
|
||||
/// This navigator's screens, bottom first. Kept only while reporting.
|
||||
final _pages = <PageRoute<dynamic>>[];
|
||||
|
||||
PageRoute<dynamic>? get _currentPage {
|
||||
_pages.removeWhere((page) => !page.isActive);
|
||||
for (final page in _pages.reversed) {
|
||||
if (page.isCurrent) return page;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Stops reporting this navigator.
|
||||
void dispose() => _trail._observers.remove(this);
|
||||
|
||||
static bool _isScreen(Route<dynamic>? route) =>
|
||||
route is PageRoute<dynamic> && route is! DiagnosticSheetRoute<dynamic>;
|
||||
|
||||
@override
|
||||
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) =>
|
||||
_arrived(route);
|
||||
|
||||
@override
|
||||
void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
|
||||
_pages.remove(oldRoute);
|
||||
_arrived(newRoute);
|
||||
}
|
||||
|
||||
@override
|
||||
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) =>
|
||||
_revealed(route, previousRoute);
|
||||
|
||||
@override
|
||||
void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) =>
|
||||
_revealed(route, previousRoute);
|
||||
|
||||
void _arrived(Route<dynamic>? route) {
|
||||
if (!_trail._reporter.reporting || !_isScreen(route)) return;
|
||||
final page = route! as PageRoute<dynamic>;
|
||||
_pages.add(page);
|
||||
_trail._announce(page);
|
||||
}
|
||||
|
||||
void _revealed(Route<dynamic> left, Route<dynamic>? revealed) {
|
||||
_pages.remove(left);
|
||||
if (_isScreen(left) && _isScreen(revealed)) {
|
||||
_trail._announce(revealed! as PageRoute<dynamic>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../features/activity/activity_page.dart';
|
||||
import '../../features/agents/agents_page.dart';
|
||||
import '../../features/channels/channel_actions_sheet.dart';
|
||||
import '../../features/channels/channel_detail_page.dart';
|
||||
import '../../features/channels/channels_page.dart';
|
||||
import '../../features/channels/media_viewer_page.dart';
|
||||
import '../../features/channels/thread_detail_page.dart';
|
||||
import '../../features/forum/forum_thread_page.dart';
|
||||
import '../../features/home/home_page.dart';
|
||||
import '../../features/invites/invite_create_page.dart';
|
||||
import '../../features/onboarding/hosted_connect_page.dart';
|
||||
import '../../features/pairing/add_community_page.dart';
|
||||
import '../../features/pairing/pairing_page.dart';
|
||||
import '../../features/profile/profile_edit_page.dart';
|
||||
import '../../features/search/search_page.dart';
|
||||
import '../../features/settings/settings_page.dart';
|
||||
import '../../features/settings/theme_picker_page.dart';
|
||||
import '../../onboarding_app_entry.dart';
|
||||
import '../../organization_app_entry.dart';
|
||||
import 'diagnostic_reporter.dart';
|
||||
|
||||
/// Names the screen a route shows, for the trail of screens in a report.
|
||||
///
|
||||
/// A route has no name of its own here: the app pushes page widgets without
|
||||
/// route settings, and where settings exist they can carry IDs. So a route is
|
||||
/// named by the first page widget below it that is on this list, and a route
|
||||
/// showing none is [DiagnosticScreen.other]. Nothing is read from a route's
|
||||
/// settings, its arguments or what the page shows.
|
||||
abstract final class DiagnosticScreens {
|
||||
/// The app's pages that have a name. Add a page here to name it; an unlisted
|
||||
/// page is reported as [DiagnosticScreen.other], never by its own type name,
|
||||
/// which release builds can obfuscate.
|
||||
static const pages = <Type, DiagnosticScreen>{
|
||||
HomePage: DiagnosticScreen.channelList,
|
||||
ChannelDetailPage: DiagnosticScreen.channel,
|
||||
ThreadDetailPage: DiagnosticScreen.thread,
|
||||
ForumThreadPage: DiagnosticScreen.forumPost,
|
||||
ChannelDetailsPage: DiagnosticScreen.channelDetails,
|
||||
SearchPage: DiagnosticScreen.search,
|
||||
ActivityPage: DiagnosticScreen.activity,
|
||||
SettingsPage: DiagnosticScreen.settings,
|
||||
ThemePickerPage: DiagnosticScreen.appearance,
|
||||
ProfileEditPage: DiagnosticScreen.profile,
|
||||
AgentsPage: DiagnosticScreen.agents,
|
||||
CommunityInvitePage: DiagnosticScreen.invites,
|
||||
CommunitySwitcherPage: DiagnosticScreen.communitySwitcher,
|
||||
AddCommunityPage: DiagnosticScreen.addCommunity,
|
||||
MediaImageViewerPage: DiagnosticScreen.mediaViewer,
|
||||
MediaVideoViewerPage: DiagnosticScreen.mediaViewer,
|
||||
OnboardingAppEntry: DiagnosticScreen.onboarding,
|
||||
OrganizationAppEntry: DiagnosticScreen.onboarding,
|
||||
PairingPage: DiagnosticScreen.onboarding,
|
||||
HostedConnectPage: DiagnosticScreen.onboarding,
|
||||
};
|
||||
|
||||
/// How many elements a search below a route may look at. A page sits near
|
||||
/// the top of its route; this keeps an unlisted page from costing a walk of
|
||||
/// everything it shows.
|
||||
static const _searchBudget = 3000;
|
||||
|
||||
/// The screen [route] shows, once it has been built.
|
||||
static DiagnosticScreen of(ModalRoute<dynamic> route) {
|
||||
if (route.subtreeContext case final BuildContext context) {
|
||||
var budget = _searchBudget;
|
||||
DiagnosticScreen? found;
|
||||
void visit(Element element) {
|
||||
if (found != null || budget-- <= 0) return;
|
||||
found = pages[element.widget.runtimeType];
|
||||
if (found == null) element.visitChildElements(visit);
|
||||
}
|
||||
|
||||
(context as Element).visitChildElements(visit);
|
||||
if (found != null) return found!;
|
||||
}
|
||||
// The first route of a nested navigator is its container, such as the
|
||||
// empty list side of a pane, and shows whatever hosts that navigator.
|
||||
if (route.isFirst) {
|
||||
final navigator = route.navigator;
|
||||
final host = navigator == null ? null : ModalRoute.of(navigator.context);
|
||||
if (host != null) return of(host);
|
||||
}
|
||||
return DiagnosticScreen.other;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:duo_kit/duo_kit.dart';
|
||||
|
||||
import '../diagnostics/diagnostic_navigation_observer.dart';
|
||||
import '../diagnostics/diagnostic_reporter.dart';
|
||||
import 'duo_toolbar.dart';
|
||||
import 'app_route_observer.dart';
|
||||
import 'covered_route_keyboard_insets.dart';
|
||||
@@ -209,8 +208,9 @@ class AdaptiveConversationPane extends HookConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final routeObserver = useMemoized(appRouteObserver.createNestedObserver);
|
||||
final screenObserver = useMemoized(
|
||||
() => DiagnosticNavigationObserver(ref.read(diagnosticReporterProvider)),
|
||||
ref.read(diagnosticScreenTrailProvider).observer,
|
||||
);
|
||||
useEffect(() => screenObserver.dispose, [screenObserver]);
|
||||
final navigator = useMemoized(() => GlobalKey<NavigatorState>());
|
||||
final ownerRoute = ModalRoute.of(context);
|
||||
useEffect(() {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:buzz/diagnostic_screens.dart';
|
||||
import 'package:buzz/features/settings/settings_page.dart';
|
||||
import 'package:buzz/shared/community/community_membership_provider.dart';
|
||||
import 'package:buzz/shared/diagnostics/diagnostic_navigation_observer.dart';
|
||||
import 'package:buzz/shared/diagnostics/diagnostic_reporter.dart';
|
||||
import 'package:buzz/shared/theme/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -33,6 +35,9 @@ void main() {
|
||||
const AsyncData<CommunityMemberRole?>(CommunityMemberRole.member),
|
||||
),
|
||||
diagnosticReporterProvider.overrideWithValue(reporter),
|
||||
diagnosticScreenClassifierProvider.overrideWithValue(
|
||||
diagnosticScreenOf,
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: AppTheme.light(),
|
||||
|
||||
@@ -1,32 +1,30 @@
|
||||
import 'package:buzz/features/channels/channel_detail_page.dart';
|
||||
import 'package:buzz/features/channels/thread_detail_page.dart';
|
||||
import 'package:buzz/features/home/home_page.dart';
|
||||
import 'package:buzz/features/settings/settings_page.dart';
|
||||
import 'package:buzz/diagnostic_screens.dart';
|
||||
import 'package:buzz/features/pairing/pairing_page.dart';
|
||||
import 'package:buzz/features/settings/theme_picker_page.dart';
|
||||
import 'package:buzz/onboarding_app_entry.dart';
|
||||
import 'package:buzz/shared/diagnostics/diagnostic_navigation_observer.dart';
|
||||
import 'package:buzz/shared/diagnostics/diagnostic_reporter.dart';
|
||||
import 'package:buzz/shared/diagnostics/diagnostic_screens.dart';
|
||||
import 'package:buzz/shared/hosted/known_community_sync_provider.dart';
|
||||
import 'package:buzz/shared/theme/theme.dart';
|
||||
import 'package:buzz/shared/widgets/adaptive_conversation_pane.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
void main() {
|
||||
group('the screen a page is named', () {
|
||||
final rows = <(Type, DiagnosticScreen)>[
|
||||
(HomePage, DiagnosticScreen.channelList),
|
||||
(ChannelDetailPage, DiagnosticScreen.channel),
|
||||
(ThreadDetailPage, DiagnosticScreen.thread),
|
||||
(SettingsPage, DiagnosticScreen.settings),
|
||||
(ThemePickerPage, DiagnosticScreen.appearance),
|
||||
final rows = <(Widget, DiagnosticScreen?)>[
|
||||
(const ThemePickerPage(), DiagnosticScreen.appearance),
|
||||
(const OnboardingAppEntry(), DiagnosticScreen.onboarding),
|
||||
(
|
||||
const OnboardingAppEntry(addingCommunity: true),
|
||||
DiagnosticScreen.addCommunity,
|
||||
),
|
||||
(const PairingPage(addingCommunity: true), DiagnosticScreen.addCommunity),
|
||||
// Not on the list: never named by its own type.
|
||||
(Text, DiagnosticScreen.other),
|
||||
(const Text('unlisted'), null),
|
||||
];
|
||||
for (final (page, screen) in rows) {
|
||||
test('$screen for $page', () {
|
||||
expect(DiagnosticScreens.pages[page] ?? DiagnosticScreen.other, screen);
|
||||
expect(diagnosticScreenOf(page), screen);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -34,30 +32,39 @@ void main() {
|
||||
group('screen breadcrumbs', () {
|
||||
const channelId = 'c0ffee-secret-channel-id';
|
||||
late _RecordingReporter reporter;
|
||||
late GlobalKey<NavigatorState> root;
|
||||
|
||||
Future<void> pumpApp(WidgetTester tester, {bool reporting = true}) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
Future<void> pumpApp(
|
||||
WidgetTester tester, {
|
||||
bool reporting = true,
|
||||
Widget home = const _Page(DiagnosticScreen.channelList),
|
||||
}) async {
|
||||
reporter = _RecordingReporter(reporting: reporting);
|
||||
root = GlobalKey<NavigatorState>();
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
diagnosticReporterProvider.overrideWithValue(reporter),
|
||||
diagnosticScreenClassifierProvider.overrideWithValue(
|
||||
(page) => page is _Page ? page.screen : null,
|
||||
),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
final observer = container.read(diagnosticScreenTrailProvider).observer();
|
||||
addTearDown(observer.dispose);
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
knownCommunitySyncProvider.overrideWithValue(null),
|
||||
savedPrefsProvider.overrideWithValue(prefs),
|
||||
],
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
theme: AppTheme.light(),
|
||||
navigatorObservers: [DiagnosticNavigationObserver(reporter)],
|
||||
home: const Scaffold(body: Text('start')),
|
||||
navigatorKey: root,
|
||||
navigatorObservers: [observer],
|
||||
home: home,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
NavigatorState navigator(WidgetTester tester) =>
|
||||
tester.state<NavigatorState>(find.byType(Navigator));
|
||||
|
||||
List<String> trail() => [
|
||||
for (final screen in reporter.screens) screen.name,
|
||||
];
|
||||
@@ -68,15 +75,15 @@ void main() {
|
||||
await pumpApp(tester);
|
||||
|
||||
// A route whose settings carry an ID is still named by its page.
|
||||
navigator(tester).push(
|
||||
root.currentState!.push(
|
||||
MaterialPageRoute<void>(
|
||||
settings: const RouteSettings(name: '/channels/$channelId'),
|
||||
builder: (_) => const ThemePickerPage(),
|
||||
builder: (_) => const _Page(DiagnosticScreen.appearance),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
// An unlisted page is "other", whatever its settings say.
|
||||
navigator(tester).push(
|
||||
root.currentState!.push(
|
||||
MaterialPageRoute<void>(
|
||||
settings: const RouteSettings(name: '/channels/$channelId'),
|
||||
builder: (_) => const Scaffold(body: Text('unlisted')),
|
||||
@@ -85,33 +92,151 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
// A dialog is not a screen: opening and closing it leaves nothing.
|
||||
final dialog = showDialog<void>(
|
||||
context: navigator(tester).context,
|
||||
context: root.currentContext!,
|
||||
builder: (_) => const AlertDialog(content: Text('dialog')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
navigator(tester).pop();
|
||||
root.currentState!.pop();
|
||||
await dialog;
|
||||
await tester.pumpAndSettle();
|
||||
// Nor is a sheet presented as a page route.
|
||||
root.currentState!.push(_SheetRoute());
|
||||
await tester.pumpAndSettle();
|
||||
root.currentState!.pop();
|
||||
await tester.pumpAndSettle();
|
||||
// Two pops at once leave only the screen they end on.
|
||||
navigator(tester).popUntil((route) => route.isFirst);
|
||||
root.currentState!.popUntil((route) => route.isFirst);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(trail(), ['other', 'appearance', 'other', 'other']);
|
||||
expect(trail(), ['channelList', 'appearance', 'other', 'channelList']);
|
||||
expect(
|
||||
reporter.crumbs.map((crumb) => crumb.toString()).join(),
|
||||
isNot(contains(channelId)),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a phone pane names the screen the person is on', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
addTearDown(tester.view.reset);
|
||||
final controller = ConversationPaneController();
|
||||
addTearDown(controller.dispose);
|
||||
final search = ConversationPaneController();
|
||||
addTearDown(search.dispose);
|
||||
await pumpApp(
|
||||
tester,
|
||||
home: _Page(
|
||||
DiagnosticScreen.channelList,
|
||||
child: AdaptiveConversationPane(
|
||||
controller: controller,
|
||||
list: const Text('list'),
|
||||
),
|
||||
),
|
||||
);
|
||||
NavigatorState pane() =>
|
||||
Navigator.of(tester.element(find.text('channel')));
|
||||
|
||||
// The pane's empty first page shows its host, Home, once.
|
||||
expect(trail(), ['channelList']);
|
||||
|
||||
controller.open('one', (_) => const _Page(DiagnosticScreen.channel));
|
||||
await tester.pumpAndSettle();
|
||||
pane().push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => const _Page(DiagnosticScreen.thread),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
Navigator.of(tester.element(find.text('thread'))).pop();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// A full-screen cover, such as a huddle, closes back onto the open
|
||||
// channel rather than the list under it.
|
||||
root.currentState!.push(
|
||||
MaterialPageRoute<void>(builder: (_) => const Text('huddle')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
root.currentState!.pop();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
pane().pop();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// A page that hosts its own pane is named once.
|
||||
root.currentState!.push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => _Page(
|
||||
DiagnosticScreen.search,
|
||||
child: AdaptiveConversationPane(
|
||||
controller: search,
|
||||
list: const Text('results'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
root.currentState!.pop();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(trail(), [
|
||||
'channelList',
|
||||
'channel',
|
||||
'thread',
|
||||
'channel',
|
||||
'other',
|
||||
'channel',
|
||||
'channelList',
|
||||
'search',
|
||||
'channelList',
|
||||
]);
|
||||
});
|
||||
|
||||
testWidgets('a wide section change stays on its screen', (tester) async {
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.view.physicalSize = const Size(1000, 800);
|
||||
addTearDown(tester.view.reset);
|
||||
final controller = ConversationPaneController();
|
||||
addTearDown(controller.dispose);
|
||||
await pumpApp(tester);
|
||||
root.currentState!.push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => _Page(
|
||||
DiagnosticScreen.settings,
|
||||
child: AdaptiveConversationPane(
|
||||
controller: controller,
|
||||
persistentSelection: true,
|
||||
list: const Text('sections'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
controller.open('status', (_) => const Text('status'));
|
||||
await tester.pumpAndSettle();
|
||||
controller.open('profile', (_) => const Text('profile'));
|
||||
await tester.pumpAndSettle();
|
||||
controller.open(
|
||||
'appearance',
|
||||
(_) => const _Page(DiagnosticScreen.appearance),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(trail(), ['channelList', 'settings', 'appearance']);
|
||||
});
|
||||
|
||||
testWidgets('a build without a destination looks at nothing', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpApp(tester, reporting: false);
|
||||
navigator(
|
||||
tester,
|
||||
).push(MaterialPageRoute<void>(builder: (_) => const ThemePickerPage()));
|
||||
root.currentState!.push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => const _Page(DiagnosticScreen.appearance),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
navigator(tester).pop();
|
||||
root.currentState!.pop();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(reporter.crumbs, isEmpty);
|
||||
@@ -119,6 +244,27 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
/// A page the test's list names [screen].
|
||||
class _Page extends StatelessWidget {
|
||||
const _Page(this.screen, {this.child});
|
||||
|
||||
final DiagnosticScreen screen;
|
||||
final Widget? child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
Scaffold(body: child ?? Text(screen.name));
|
||||
}
|
||||
|
||||
class _SheetRoute extends PageRouteBuilder<void>
|
||||
with DiagnosticSheetRoute<void> {
|
||||
_SheetRoute()
|
||||
: super(
|
||||
opaque: false,
|
||||
pageBuilder: (_, _, _) => const _Page(DiagnosticScreen.channelDetails),
|
||||
);
|
||||
}
|
||||
|
||||
class _RecordingReporter extends NoopDiagnosticReporter {
|
||||
_RecordingReporter({required this.reporting});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user