From 45ab4949696c2e6f2c41a32f6210f4813126114a Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Mon, 12 Feb 2024 22:30:09 -0500 Subject: [PATCH] things compile --- lib/app.dart | 3 +- lib/router/cubit/router_cubit.dart | 44 +++++++++++++++---- lib/settings/models/preferences.dart | 4 +- lib/theme/views/color_preferences.dart | 2 - lib/tools/widget_helpers.dart | 2 +- .../lib/dht_support/src/dht_record_pool.dart | 2 + 6 files changed, 42 insertions(+), 15 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index 3cb2093..e7569c0 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -59,8 +59,7 @@ class VeilidChatApp extends StatelessWidget { child: BackgroundTicker( builder: (context) => MaterialApp.router( debugShowCheckedModeBanner: false, - routerConfig: - BlocProvider.of(context).router(), + routerConfig: context.watch().router(), title: translate('app.title'), theme: theme, localizationsDelegates: [ diff --git a/lib/router/cubit/router_cubit.dart b/lib/router/cubit/router_cubit.dart index b0ba3eb..aedae69 100644 --- a/lib/router/cubit/router_cubit.dart +++ b/lib/router/cubit/router_cubit.dart @@ -127,6 +127,9 @@ class RouterCubit extends Cubit { if (!state.hasAnyAccount) { return '/new_account'; } + if (!state.hasActiveChat) { xxx stop using hasActiveChat here... we need a pager for the accounts and a way to get the current account state maybe a 'activeAccountCubit' or something, we may have this alraeady but it needs to work even if logged out.`` + return '/home/no_active'; + } if (responsiveVisibility( context: context, tablet: false, @@ -141,6 +144,9 @@ class RouterCubit extends Cubit { if (!state.hasAnyAccount) { return '/new_account'; } + if (!state.hasActiveChat) { + return '/home/no_active'; + } if (responsiveVisibility( context: context, tablet: false, @@ -153,6 +159,21 @@ class RouterCubit extends Cubit { return '/home'; } return null; + case '/home/no_active': + if (state.hasActiveChat) { + return '/home'; + } + return null; + case '/home/account_missing': + if (!state.hasActiveChat) { + return '/home/no_active'; + } + return null; + case '/home/account_locked': + if (!state.hasActiveChat) { + return '/home/no_active'; + } + return null; case '/settings': return null; case '/developer': @@ -163,17 +184,24 @@ class RouterCubit extends Cubit { } /// Make a GoRouter instance that uses this cubit - GoRouter router() => GoRouter( - navigatorKey: _rootNavKey, - refreshListenable: StreamListenable(stream.startWith(state).distinct()), - debugLogDiagnostics: kDebugMode, - initialLocation: '/', - routes: routes, - redirect: redirect, - ); + GoRouter router() { + final r = _router; + if (r != null) { + return r; + } + return _router = GoRouter( + navigatorKey: _rootNavKey, + refreshListenable: StreamListenable(stream.startWith(state).distinct()), + debugLogDiagnostics: kDebugMode, + initialLocation: '/', + routes: routes, + redirect: redirect, + ); + } //////////////// late final StreamSubscription _accountRepositorySubscription; + GoRouter? _router; } diff --git a/lib/settings/models/preferences.dart b/lib/settings/models/preferences.dart index 8ff626f..8dfcb73 100644 --- a/lib/settings/models/preferences.dart +++ b/lib/settings/models/preferences.dart @@ -28,13 +28,13 @@ class LockPreference with _$LockPreference { // Theme supports multiple translations enum LanguagePreference { - englishUS; + englishUs; factory LanguagePreference.fromJson(dynamic j) => LanguagePreference.values.byName((j as String).toCamelCase()); String toJson() => name.toPascalCase(); - static const LanguagePreference defaults = LanguagePreference.englishUS; + static const LanguagePreference defaults = LanguagePreference.englishUs; } // Preferences are stored in a table locally and globally affect all diff --git a/lib/theme/views/color_preferences.dart b/lib/theme/views/color_preferences.dart index 67e91f0..a364e00 100644 --- a/lib/theme/views/color_preferences.dart +++ b/lib/theme/views/color_preferences.dart @@ -49,7 +49,5 @@ Widget buildSettingsPageColorPreferences({required void Function() onChanged}) { await preferencesRepository.set(newPrefs); switcher.changeTheme(theme: newThemePrefs.themeData()); onChanged(); - - onChanged(); })); } diff --git a/lib/tools/widget_helpers.dart b/lib/tools/widget_helpers.dart index c9ffa41..60ef937 100644 --- a/lib/tools/widget_helpers.dart +++ b/lib/tools/widget_helpers.dart @@ -44,7 +44,7 @@ Widget waitingPage({String? text}) => Builder( color: Theme.of(context).scaffoldBackgroundColor, child: Center( child: Column(children: [ - buildProgressIndicator(), + buildProgressIndicator().expanded(), if (text != null) Text(text) ])))); diff --git a/packages/veilid_support/lib/dht_support/src/dht_record_pool.dart b/packages/veilid_support/lib/dht_support/src/dht_record_pool.dart index ee4b426..208ac98 100644 --- a/packages/veilid_support/lib/dht_support/src/dht_record_pool.dart +++ b/packages/veilid_support/lib/dht_support/src/dht_record_pool.dart @@ -230,6 +230,8 @@ class DHTRecordPool with TableDBBacked { final dhtctx = routingContext ?? _routingContext; final recordDescriptor = await dhtctx.createDHTRecord(schema); + await _locks.lockTag(recordDescriptor.key); + final rec = DHTRecord( routingContext: dhtctx, recordDescriptor: recordDescriptor,