diff --git a/lib/account_manager/cubits/account_info_cubit.dart b/lib/account_manager/cubits/account_info_cubit.dart index d9d93fc..a5eab11 100644 --- a/lib/account_manager/cubits/account_info_cubit.dart +++ b/lib/account_manager/cubits/account_info_cubit.dart @@ -23,7 +23,6 @@ class AccountInfoCubit extends Cubit { if (acctInfo != null) { emit(acctInfo); } - break; } }); } diff --git a/lib/account_manager/cubits/local_accounts_cubit.dart b/lib/account_manager/cubits/local_accounts_cubit.dart index 704d8c5..3781297 100644 --- a/lib/account_manager/cubits/local_accounts_cubit.dart +++ b/lib/account_manager/cubits/local_accounts_cubit.dart @@ -20,7 +20,6 @@ class LocalAccountsCubit extends Cubit switch (change) { case AccountRepositoryChange.localAccounts: emit(_accountRepository.getLocalAccounts()); - break; // Ignore these case AccountRepositoryChange.userLogins: case AccountRepositoryChange.activeLocalAccount: diff --git a/lib/account_manager/cubits/per_account_collection_cubit.dart b/lib/account_manager/cubits/per_account_collection_cubit.dart index 089443a..fc2d447 100644 --- a/lib/account_manager/cubits/per_account_collection_cubit.dart +++ b/lib/account_manager/cubits/per_account_collection_cubit.dart @@ -15,6 +15,9 @@ import '../../notifications/notifications.dart'; import '../../proto/proto.dart' as proto; import '../account_manager.dart'; +const _kAccountRecordSubscriptionListenKey = + 'accountRecordSubscriptionListenKey'; + class PerAccountCollectionCubit extends Cubit { PerAccountCollectionCubit({ required Locator locator, @@ -32,6 +35,7 @@ class PerAccountCollectionCubit extends Cubit { await _processor.close(); await accountInfoCubit.close(); await _accountRecordSubscription?.cancel(); + await serialFutureClose((this, _kAccountRecordSubscriptionListenKey)); await accountRecordCubit?.close(); await activeSingleContactChatBlocMapCubitUpdater.close(); @@ -83,7 +87,7 @@ class PerAccountCollectionCubit extends Cubit { accountRecordCubit = null; // Update state to 'loading' - nextState = _updateAccountRecordState(nextState, null); + nextState = await _updateAccountRecordState(nextState, null); emit(nextState); } else { ///////////////// Logged in /////////////////// @@ -95,20 +99,22 @@ class PerAccountCollectionCubit extends Cubit { // Update state to value nextState = - _updateAccountRecordState(nextState, accountRecordCubit!.state); + await _updateAccountRecordState(nextState, accountRecordCubit!.state); emit(nextState); // Subscribe AccountRecordCubit _accountRecordSubscription ??= accountRecordCubit!.stream.listen((avAccountRecordState) { - emit(_updateAccountRecordState(state, avAccountRecordState)); + serialFuture((this, _kAccountRecordSubscriptionListenKey), () async { + emit(await _updateAccountRecordState(state, avAccountRecordState)); + }); }); } } - PerAccountCollectionState _updateAccountRecordState( + Future _updateAccountRecordState( PerAccountCollectionState prevState, - AsyncValue? avAccountRecordState) { + AsyncValue? avAccountRecordState) async { // Get next state final nextState = prevState.copyWith(avAccountRecordState: avAccountRecordState); @@ -121,8 +127,8 @@ class PerAccountCollectionCubit extends Cubit { .avAccountRecordState?.asData?.value.contactInvitationRecords .toVeilid(); - final contactInvitationListCubit = contactInvitationListCubitUpdater.update( - accountInfo.userLogin == null || + final contactInvitationListCubit = await contactInvitationListCubitUpdater + .update(accountInfo.userLogin == null || contactInvitationListRecordPointer == null ? null : (accountInfo, contactInvitationListRecordPointer)); @@ -131,34 +137,35 @@ class PerAccountCollectionCubit extends Cubit { final contactListRecordPointer = nextState.avAccountRecordState?.asData?.value.contactList.toVeilid(); - final contactListCubit = contactListCubitUpdater.update( + final contactListCubit = await contactListCubitUpdater.update( accountInfo.userLogin == null || contactListRecordPointer == null ? null : (accountInfo, contactListRecordPointer)); // WaitingInvitationsBlocMapCubit - final waitingInvitationsBlocMapCubit = waitingInvitationsBlocMapCubitUpdater - .update(accountInfo.userLogin == null || - contactInvitationListCubit == null || - contactListCubit == null - ? null - : ( - accountInfo, - accountRecordCubit!, - contactInvitationListCubit, - contactListCubit, - _locator(), - )); + final waitingInvitationsBlocMapCubit = + await waitingInvitationsBlocMapCubitUpdater.update( + accountInfo.userLogin == null || + contactInvitationListCubit == null || + contactListCubit == null + ? null + : ( + accountInfo, + accountRecordCubit!, + contactInvitationListCubit, + contactListCubit, + _locator(), + )); // ActiveChatCubit - final activeChatCubit = activeChatCubitUpdater + final activeChatCubit = await activeChatCubitUpdater .update((accountInfo.userLogin == null) ? null : true); // ChatListCubit final chatListRecordPointer = nextState.avAccountRecordState?.asData?.value.chatList.toVeilid(); - final chatListCubit = chatListCubitUpdater.update( + final chatListCubit = await chatListCubitUpdater.update( accountInfo.userLogin == null || chatListRecordPointer == null || activeChatCubit == null @@ -167,7 +174,7 @@ class PerAccountCollectionCubit extends Cubit { // ActiveConversationsBlocMapCubit final activeConversationsBlocMapCubit = - activeConversationsBlocMapCubitUpdater.update( + await activeConversationsBlocMapCubitUpdater.update( accountRecordCubit == null || chatListCubit == null || contactListCubit == null @@ -181,7 +188,7 @@ class PerAccountCollectionCubit extends Cubit { // ActiveSingleContactChatBlocMapCubit final activeSingleContactChatBlocMapCubit = - activeSingleContactChatBlocMapCubitUpdater.update( + await activeSingleContactChatBlocMapCubitUpdater.update( accountInfo.userLogin == null || activeConversationsBlocMapCubit == null ? null diff --git a/lib/account_manager/cubits/user_logins_cubit.dart b/lib/account_manager/cubits/user_logins_cubit.dart index 734ced3..5623a34 100644 --- a/lib/account_manager/cubits/user_logins_cubit.dart +++ b/lib/account_manager/cubits/user_logins_cubit.dart @@ -17,7 +17,6 @@ class UserLoginsCubit extends Cubit { switch (change) { case AccountRepositoryChange.userLogins: emit(_accountRepository.getUserLogins()); - break; // Ignore these case AccountRepositoryChange.localAccounts: case AccountRepositoryChange.activeLocalAccount: diff --git a/lib/account_manager/views/edit_account_page.dart b/lib/account_manager/views/edit_account_page.dart index 81b67eb..bd18967 100644 --- a/lib/account_manager/views/edit_account_page.dart +++ b/lib/account_manager/views/edit_account_page.dart @@ -61,6 +61,13 @@ class _EditAccountPageState extends WindowSetupState { ); Future _onRemoveAccount() async { + // dismiss the keyboard by unfocusing the textfield + FocusScope.of(context).unfocus(); + await asyncSleep(const Duration(milliseconds: 250)); + if (!mounted) { + return; + } + final confirmed = await StyledDialog.show( context: context, title: translate('edit_account_page.remove_account_confirm'), @@ -87,10 +94,7 @@ class _EditAccountPageState extends WindowSetupState { ])) ]).paddingAll(24) ])); - if (confirmed != null && confirmed && mounted) { - // dismiss the keyboard by unfocusing the textfield - FocusScope.of(context).unfocus(); - + if (confirmed != null && confirmed) { try { setState(() { _isInAsyncCall = true; @@ -125,6 +129,13 @@ class _EditAccountPageState extends WindowSetupState { } Future _onDestroyAccount() async { + // dismiss the keyboard by unfocusing the textfield + FocusScope.of(context).unfocus(); + await asyncSleep(const Duration(milliseconds: 250)); + if (!mounted) { + return; + } + final confirmed = await StyledDialog.show( context: context, title: translate('edit_account_page.destroy_account_confirm'), @@ -154,10 +165,7 @@ class _EditAccountPageState extends WindowSetupState { ])) ]).paddingAll(24) ])); - if (confirmed != null && confirmed && mounted) { - // dismiss the keyboard by unfocusing the textfield - FocusScope.of(context).unfocus(); - + if (confirmed != null && confirmed) { try { setState(() { _isInAsyncCall = true; diff --git a/lib/account_manager/views/edit_profile_form.dart b/lib/account_manager/views/edit_profile_form.dart index d6bb504..80bd2b3 100644 --- a/lib/account_manager/views/edit_profile_form.dart +++ b/lib/account_manager/views/edit_profile_form.dart @@ -282,9 +282,6 @@ class _EditProfileFormState extends State { FormBuilderCheckbox( name: EditProfileForm.formFieldAutoAway, initialValue: _savedValue.autoAway, - side: BorderSide(color: scale.primaryScale.border, width: 2), - checkColor: scale.primaryScale.borderText, - activeColor: scale.primaryScale.border, title: Text(translate('account.form_auto_away'), style: textTheme.labelMedium), onChanged: (v) { diff --git a/lib/app.dart b/lib/app.dart index 519f2bb..f8241da 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -47,7 +47,7 @@ class VeilidChatApp extends StatelessWidget { final ThemeData initialThemeData; - void _reloadTheme(BuildContext context) { + void reloadTheme(BuildContext context) { singleFuture(this, () async { log.info('Reloading theme'); @@ -95,7 +95,7 @@ class VeilidChatApp extends StatelessWidget { }, child: Actions(actions: >{ ReloadThemeIntent: CallbackAction( - onInvoke: (intent) => _reloadTheme(context)), + onInvoke: (intent) => reloadTheme(context)), AttachDetachIntent: CallbackAction( onInvoke: (intent) => _attachDetach(context)), }, child: Focus(autofocus: true, child: builder(context))))); diff --git a/lib/chat/views/chat_component_widget.dart b/lib/chat/views/chat_component_widget.dart index f41ba47..1646772 100644 --- a/lib/chat/views/chat_component_widget.dart +++ b/lib/chat/views/chat_component_widget.dart @@ -120,7 +120,7 @@ class ChatComponentWidget extends StatelessWidget { return Column( children: [ Container( - height: 40, + height: 48, decoration: BoxDecoration( color: scale.border, ), diff --git a/lib/chat_list/cubits/chat_list_cubit.dart b/lib/chat_list/cubits/chat_list_cubit.dart index 6bb88c1..3ae3db1 100644 --- a/lib/chat_list/cubits/chat_list_cubit.dart +++ b/lib/chat_list/cubits/chat_list_cubit.dart @@ -86,14 +86,12 @@ class ChatListCubit extends DHTShortArrayCubit // Nothing to do here return; } - break; case proto.Chat_Kind.group: if (c.group.localConversationRecordKey == contact.localConversationRecordKey) { throw StateError('direct conversation record key should' ' not be used for group chats!'); } - break; case proto.Chat_Kind.notSet: throw StateError('unknown chat kind'); } diff --git a/lib/contact_invitation/views/create_invitation_dialog.dart b/lib/contact_invitation/views/create_invitation_dialog.dart index d835de8..581e8d6 100644 --- a/lib/contact_invitation/views/create_invitation_dialog.dart +++ b/lib/contact_invitation/views/create_invitation_dialog.dart @@ -191,6 +191,7 @@ class _CreateInvitationDialogState extends State { mainAxisSize: MainAxisSize.min, children: [ TextField( + autofocus: true, controller: _recipientTextController, onChanged: (value) { setState(() {}); diff --git a/lib/contact_invitation/views/scan_invitation_dialog.dart b/lib/contact_invitation/views/scan_invitation_dialog.dart index 645640e..fa8bba9 100644 --- a/lib/contact_invitation/views/scan_invitation_dialog.dart +++ b/lib/contact_invitation/views/scan_invitation_dialog.dart @@ -86,7 +86,7 @@ class ScannerOverlay extends CustomPainter { final cutoutPath = Path()..addRect(scanWindow); final backgroundPaint = Paint() - ..color = Colors.black.withOpacity(0.5) + ..color = Colors.black.withAlpha(127) ..style = PaintingStyle.fill ..blendMode = BlendMode.dstOut; @@ -188,7 +188,7 @@ class ScanInvitationDialogState extends State { child: Container( alignment: Alignment.bottomCenter, height: 100, - color: Colors.black.withOpacity(0.4), + color: Colors.black.withAlpha(127), child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ diff --git a/lib/contacts/cubits/contact_list_cubit.dart b/lib/contacts/cubits/contact_list_cubit.dart index df70cc0..a0591ad 100644 --- a/lib/contacts/cubits/contact_list_cubit.dart +++ b/lib/contacts/cubits/contact_list_cubit.dart @@ -149,10 +149,14 @@ class ContactListCubit extends DHTShortArrayCubit { // Mark the conversation records for deletion await DHTRecordPool.instance .deleteRecord(deletedItem.localConversationRecordKey.toVeilid()); + } on Exception catch (e) { + log.debug('error deleting local conversation record: $e', e); + } + try { await DHTRecordPool.instance .deleteRecord(deletedItem.remoteConversationRecordKey.toVeilid()); } on Exception catch (e) { - log.debug('error deleting conversation records: $e', e); + log.debug('error deleting remote conversation record: $e', e); } } } diff --git a/lib/contacts/views/edit_contact_form.dart b/lib/contacts/views/edit_contact_form.dart index 5477c60..514f019 100644 --- a/lib/contacts/views/edit_contact_form.dart +++ b/lib/contacts/views/edit_contact_form.dart @@ -195,9 +195,6 @@ class _EditContactFormState extends State { FormBuilderCheckbox( name: EditContactForm.formFieldShowAvailability, initialValue: _savedValue.showAvailability, - side: BorderSide(color: scale.primaryScale.border, width: 2), - checkColor: scale.primaryScale.borderText, - activeColor: scale.primaryScale.border, title: Text(translate('contact_form.form_show_availability'), style: textTheme.labelMedium), ), diff --git a/lib/contacts/views/empty_contact_list_widget.dart b/lib/contacts/views/empty_contact_list_widget.dart index 2563a1d..e6912fd 100644 --- a/lib/contacts/views/empty_contact_list_widget.dart +++ b/lib/contacts/views/empty_contact_list_widget.dart @@ -15,8 +15,7 @@ class EmptyContactListWidget extends StatelessWidget { final textTheme = theme.textTheme; final scale = theme.extension()!; - return Expanded( - child: Column( + return Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisAlignment: MainAxisAlignment.center, @@ -35,6 +34,6 @@ class EmptyContactListWidget extends StatelessWidget { ), ), ], - )); + ); } } diff --git a/lib/conversation/cubits/active_conversations_bloc_map_cubit.dart b/lib/conversation/cubits/active_conversations_bloc_map_cubit.dart index fbf0e80..08a249f 100644 --- a/lib/conversation/cubits/active_conversations_bloc_map_cubit.dart +++ b/lib/conversation/cubits/active_conversations_bloc_map_cubit.dart @@ -50,7 +50,7 @@ typedef ActiveConversationsBlocMapState // We currently only build the cubits for the chats that are active, not // archived chats or contacts that are not actively in a chat. // -// TODO: Polling contacts for new inactive chats is yet to be done +// TODO(crioux): Polling contacts for new inactive chats is yet to be done // class ActiveConversationsBlocMapCubit extends BlocMapCubit, ActiveConversationCubit> @@ -166,7 +166,6 @@ class ActiveConversationsBlocMapCubit extends BlocMapCubit { // ? grayColorFilter // : null) // .paddingLTRB(0, 0, 16, 0), - SvgPicture.asset( - height: 48, - 'assets/images/title.svg', - colorFilter: scaleConfig.useVisualIndicators - ? grayColorFilter - : src96StencilFilter), + GestureDetector( + onLongPress: () async { + context + .findAncestorWidgetOfExactType()! + .reloadTheme(context); + }, + child: SvgPicture.asset( + height: 48, + 'assets/images/title.svg', + colorFilter: scaleConfig.useVisualIndicators + ? grayColorFilter + : src96StencilFilter)), ]))), Text(translate('menu.accounts'), style: theme.textTheme.titleMedium!.copyWith( diff --git a/lib/layout/home/home_screen.dart b/lib/layout/home/home_screen.dart index a534415..3d1b14f 100644 --- a/lib/layout/home/home_screen.dart +++ b/lib/layout/home/home_screen.dart @@ -66,10 +66,11 @@ class HomeScreenState extends State final scale = theme.extension()!; final scaleConfig = theme.extension()!; - await showWarningWidgetModal( + await showAlertWidgetModal( context: context, title: translate('splash.beta_title'), child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [ + const Icon(Icons.warning, size: 64), RichText( textAlign: TextAlign.center, text: TextSpan( diff --git a/lib/notifications/views/notifications_preferences.dart b/lib/notifications/views/notifications_preferences.dart index 95d4a1e..82f3555 100644 --- a/lib/notifications/views/notifications_preferences.dart +++ b/lib/notifications/views/notifications_preferences.dart @@ -129,9 +129,6 @@ Widget buildSettingsPageNotificationPreferences( // Display Beta Warning FormBuilderCheckbox( name: formFieldDisplayBetaWarning, - side: BorderSide(color: scale.primaryScale.border, width: 2), - checkColor: scale.primaryScale.borderText, - activeColor: scale.primaryScale.border, title: Text(translate('settings_page.display_beta_warning'), style: textTheme.labelMedium), initialValue: notificationsPreference.displayBetaWarning, @@ -147,9 +144,6 @@ Widget buildSettingsPageNotificationPreferences( // Enable Badge FormBuilderCheckbox( name: formFieldEnableBadge, - side: BorderSide(color: scale.primaryScale.border, width: 2), - checkColor: scale.primaryScale.borderText, - activeColor: scale.primaryScale.border, title: Text(translate('settings_page.enable_badge'), style: textTheme.labelMedium), initialValue: notificationsPreference.enableBadge, @@ -164,9 +158,6 @@ Widget buildSettingsPageNotificationPreferences( // Enable Notifications FormBuilderCheckbox( name: formFieldEnableNotifications, - side: BorderSide(color: scale.primaryScale.border, width: 2), - checkColor: scale.primaryScale.borderText, - activeColor: scale.primaryScale.border, title: Text(translate('settings_page.enable_notifications'), style: textTheme.labelMedium), initialValue: notificationsPreference.enableNotifications, diff --git a/lib/theme/models/radix_generator.dart b/lib/theme/models/radix_generator.dart index 3e3b0e6..ce05769 100644 --- a/lib/theme/models/radix_generator.dart +++ b/lib/theme/models/radix_generator.dart @@ -638,7 +638,7 @@ ThemeData radixGenerator(Brightness brightness, RadixThemeColor themeColor) { useVisualIndicators: false, preferBorders: false, borderRadiusScale: 1, - wallpaperAlpha: wallpaperAlpha(brightness, themeColor), + wallpaperOpacity: wallpaperAlpha(brightness, themeColor), ); final scaleTheme = ScaleTheme( diff --git a/lib/theme/models/scale_theme/scale_color.dart b/lib/theme/models/scale_theme/scale_color.dart index e50a01b..d79d878 100644 --- a/lib/theme/models/scale_theme/scale_color.dart +++ b/lib/theme/models/scale_theme/scale_color.dart @@ -50,11 +50,11 @@ class ScaleColor { Color? subtleBorder, Color? border, Color? hoverBorder, - Color? background, - Color? hoverBackground, + Color? primary, + Color? hoverPrimary, Color? subtleText, Color? appText, - Color? foregroundText, + Color? primaryText, Color? borderText, Color? dialogBorder, Color? dialogBorderText, @@ -72,11 +72,11 @@ class ScaleColor { subtleBorder: subtleBorder ?? this.subtleBorder, border: border ?? this.border, hoverBorder: hoverBorder ?? this.hoverBorder, - primary: background ?? this.primary, - hoverPrimary: hoverBackground ?? this.hoverPrimary, + primary: primary ?? this.primary, + hoverPrimary: hoverPrimary ?? this.hoverPrimary, subtleText: subtleText ?? this.subtleText, appText: appText ?? this.appText, - primaryText: foregroundText ?? this.primaryText, + primaryText: primaryText ?? this.primaryText, borderText: borderText ?? this.borderText, dialogBorder: dialogBorder ?? this.dialogBorder, dialogBorderText: dialogBorderText ?? this.dialogBorderText, diff --git a/lib/theme/models/scale_theme/scale_custom_dropdown_theme.dart b/lib/theme/models/scale_theme/scale_custom_dropdown_theme.dart index 692ec85..2c5eb1c 100644 --- a/lib/theme/models/scale_theme/scale_custom_dropdown_theme.dart +++ b/lib/theme/models/scale_theme/scale_custom_dropdown_theme.dart @@ -68,7 +68,7 @@ extension ScaleCustomDropdownThemeExt on ScaleTheme { listItemDecoration: null, ); - final disabledDecoration = CustomDropdownDisabledDecoration( + const disabledDecoration = CustomDropdownDisabledDecoration( fillColor: null, shadow: null, suffixIcon: null, diff --git a/lib/theme/models/scale_theme/scale_scheme.dart b/lib/theme/models/scale_theme/scale_scheme.dart index dd88b4f..8363476 100644 --- a/lib/theme/models/scale_theme/scale_scheme.dart +++ b/lib/theme/models/scale_theme/scale_scheme.dart @@ -111,27 +111,27 @@ class ScaleConfig extends ThemeExtension { required this.useVisualIndicators, required this.preferBorders, required this.borderRadiusScale, - required double wallpaperAlpha, - }) : _wallpaperAlpha = wallpaperAlpha; + required this.wallpaperOpacity, + }); final bool useVisualIndicators; final bool preferBorders; final double borderRadiusScale; - final double _wallpaperAlpha; + final double wallpaperOpacity; - int get wallpaperAlpha => _wallpaperAlpha.toInt(); + int get wallpaperAlpha => wallpaperOpacity.toInt(); @override ScaleConfig copyWith( {bool? useVisualIndicators, bool? preferBorders, double? borderRadiusScale, - double? wallpaperAlpha}) => + double? wallpaperOpacity}) => ScaleConfig( useVisualIndicators: useVisualIndicators ?? this.useVisualIndicators, preferBorders: preferBorders ?? this.preferBorders, borderRadiusScale: borderRadiusScale ?? this.borderRadiusScale, - wallpaperAlpha: wallpaperAlpha ?? this._wallpaperAlpha, + wallpaperOpacity: wallpaperOpacity ?? this.wallpaperOpacity, ); @override @@ -145,7 +145,7 @@ class ScaleConfig extends ThemeExtension { preferBorders: t < .5 ? preferBorders : other.preferBorders, borderRadiusScale: lerpDouble(borderRadiusScale, other.borderRadiusScale, t) ?? 1, - wallpaperAlpha: - lerpDouble(_wallpaperAlpha, other._wallpaperAlpha, t) ?? 1); + wallpaperOpacity: + lerpDouble(wallpaperOpacity, other.wallpaperOpacity, t) ?? 1); } } diff --git a/lib/theme/models/scale_theme/scale_theme.dart b/lib/theme/models/scale_theme/scale_theme.dart index 43ca641..ef430d2 100644 --- a/lib/theme/models/scale_theme/scale_theme.dart +++ b/lib/theme/models/scale_theme/scale_theme.dart @@ -84,6 +84,24 @@ class ScaleTheme extends ThemeExtension { scheme.primaryScale.borderText, scheme.primaryScale.primary, 0.25); }); + WidgetStateProperty checkboxFillColorWidgetStateProperty() => + WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.selected)) { + if (states.contains(WidgetState.disabled)) { + return scheme.grayScale.primary.withAlpha(0x7F); + } else if (states.contains(WidgetState.pressed)) { + return scheme.primaryScale.hoverBorder; + } else if (states.contains(WidgetState.hovered)) { + return scheme.primaryScale.hoverBorder; + } else if (states.contains(WidgetState.focused)) { + return scheme.primaryScale.border; + } + return scheme.primaryScale.border; + } else { + return Colors.transparent; + } + }); + // WidgetStateProperty elementBackgroundWidgetStateProperty() { // return null; // } @@ -140,7 +158,7 @@ class ScaleTheme extends ThemeExtension { appBarTheme: baseThemeData.appBarTheme.copyWith( backgroundColor: scheme.primaryScale.border, foregroundColor: scheme.primaryScale.borderText, - toolbarHeight: 40, + toolbarHeight: 48, ), bottomSheetTheme: baseThemeData.bottomSheetTheme.copyWith( elevation: 0, @@ -150,6 +168,11 @@ class ScaleTheme extends ThemeExtension { topLeft: Radius.circular(16 * config.borderRadiusScale), topRight: Radius.circular(16 * config.borderRadiusScale)))), canvasColor: scheme.primaryScale.subtleBackground, + checkboxTheme: baseThemeData.checkboxTheme.copyWith( + side: BorderSide(color: scheme.primaryScale.border, width: 2), + checkColor: elementColorWidgetStateProperty(), + fillColor: checkboxFillColorWidgetStateProperty(), + ), chipTheme: baseThemeData.chipTheme.copyWith( backgroundColor: scheme.primaryScale.elementBackground, selectedColor: scheme.primaryScale.activeElementBackground, diff --git a/lib/theme/models/theme_preference.dart b/lib/theme/models/theme_preference.dart index dc2e082..4be6b4e 100644 --- a/lib/theme/models/theme_preference.dart +++ b/lib/theme/models/theme_preference.dart @@ -1,6 +1,5 @@ import 'package:change_case/change_case.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_svg/svg.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -103,7 +102,7 @@ extension ThemePreferencesExt on ThemePreferences { useVisualIndicators: true, preferBorders: false, borderRadiusScale: 1, - wallpaperAlpha: 255), + wallpaperOpacity: 255), primaryFront: Colors.black, primaryBack: Colors.white, secondaryFront: Colors.black, @@ -123,7 +122,7 @@ extension ThemePreferencesExt on ThemePreferences { useVisualIndicators: true, preferBorders: true, borderRadiusScale: 0.2, - wallpaperAlpha: 208), + wallpaperOpacity: 208), primaryFront: const Color(0xFF000000), primaryBack: const Color(0xFF00FF00), secondaryFront: const Color(0xFF000000), @@ -141,7 +140,7 @@ extension ThemePreferencesExt on ThemePreferences { useVisualIndicators: true, preferBorders: true, borderRadiusScale: 0.2, - wallpaperAlpha: 192), + wallpaperOpacity: 192), primaryFront: const Color(0xFF000000), primaryBack: const Color(0xFF00FF00), secondaryFront: const Color(0xFF000000), diff --git a/lib/theme/views/scanner_error_widget.dart b/lib/theme/views/scanner_error_widget.dart index 0926128..d5463f4 100644 --- a/lib/theme/views/scanner_error_widget.dart +++ b/lib/theme/views/scanner_error_widget.dart @@ -14,16 +14,12 @@ class ScannerErrorWidget extends StatelessWidget { switch (error.errorCode) { case MobileScannerErrorCode.controllerUninitialized: errorMessage = 'Controller not ready.'; - break; case MobileScannerErrorCode.permissionDenied: errorMessage = 'Permission denied'; - break; case MobileScannerErrorCode.unsupported: errorMessage = 'Scanning is unsupported on this device'; - break; default: errorMessage = 'Generic Error'; - break; } return ColoredBox( diff --git a/lib/theme/views/styled_alert.dart b/lib/theme/views/styled_alert.dart index 82218e8..8602c22 100644 --- a/lib/theme/views/styled_alert.dart +++ b/lib/theme/views/styled_alert.dart @@ -11,6 +11,7 @@ AlertStyle _alertStyle(BuildContext context) { return AlertStyle( animationType: AnimationType.grow, + isCloseButton: false, //animationDuration: const Duration(milliseconds: 200), alertBorder: RoundedRectangleBorder( side: !scaleConfig.useVisualIndicators @@ -131,7 +132,7 @@ Future showErrorStacktraceModal( ); } -Future showWarningModal( +Future showAlertModal( {required BuildContext context, required String title, required String text}) async { @@ -139,7 +140,7 @@ Future showWarningModal( context: context, style: _alertStyle(context), useRootNavigator: false, - type: AlertType.warning, + type: AlertType.none, title: title, desc: text, buttons: [ @@ -161,7 +162,7 @@ Future showWarningModal( ).show(); } -Future showWarningWidgetModal( +Future showAlertWidgetModal( {required BuildContext context, required String title, required Widget child}) async { @@ -169,7 +170,7 @@ Future showWarningWidgetModal( context: context, style: _alertStyle(context), useRootNavigator: false, - type: AlertType.warning, + type: AlertType.none, title: title, content: child, buttons: [ diff --git a/lib/theme/views/wallpaper_preferences.dart b/lib/theme/views/wallpaper_preferences.dart index e90022c..f9ae94c 100644 --- a/lib/theme/views/wallpaper_preferences.dart +++ b/lib/theme/views/wallpaper_preferences.dart @@ -15,7 +15,6 @@ Widget buildSettingsPageWallpaperPreferences( final preferencesRepository = PreferencesRepository.instance; final themePreferences = preferencesRepository.value.themePreference; final theme = Theme.of(context); - final scale = theme.extension()!; final textTheme = theme.textTheme; return FormBuilderCheckbox( @@ -23,9 +22,6 @@ Widget buildSettingsPageWallpaperPreferences( title: Text(translate('settings_page.enable_wallpaper'), style: textTheme.labelMedium), initialValue: themePreferences.enableWallpaper, - side: BorderSide(color: scale.primaryScale.border, width: 2), - checkColor: scale.primaryScale.borderText, - activeColor: scale.primaryScale.border, onChanged: (value) async { if (value != null) { final newThemePrefs = diff --git a/lib/veilid_processor/repository/processor_repository.dart b/lib/veilid_processor/repository/processor_repository.dart index 3622219..7ff2482 100644 --- a/lib/veilid_processor/repository/processor_repository.dart +++ b/lib/veilid_processor/repository/processor_repository.dart @@ -44,13 +44,6 @@ class ProcessorRepository { log.info('Veilid version: $veilidVersion'); - // HACK: In case of hot restart shut down first - try { - await Veilid.instance.shutdownVeilidCore(); - } on Exception { - // Do nothing on failure here - } - final updateStream = await Veilid.instance .startupVeilidCore(await getVeilidConfig(kIsWeb, VeilidChatApp.name)); _updateSubscription = updateStream.listen((update) { diff --git a/packages/veilid_support/example/test/widget_test.dart b/packages/veilid_support/example/test/widget_test.dart index 092d222..d5cfa06 100644 --- a/packages/veilid_support/example/test/widget_test.dart +++ b/packages/veilid_support/example/test/widget_test.dart @@ -5,13 +5,12 @@ // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. +import 'package:example/main.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:example/main.dart'; - void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { + testWidgets('Counter increments smoke test', (tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const MyApp()); diff --git a/packages/veilid_support/lib/dht_support/src/dht_log/dht_log.dart b/packages/veilid_support/lib/dht_support/src/dht_log/dht_log.dart index bba3306..8f88ce1 100644 --- a/packages/veilid_support/lib/dht_support/src/dht_log/dht_log.dart +++ b/packages/veilid_support/lib/dht_support/src/dht_log/dht_log.dart @@ -171,32 +171,31 @@ class DHTLog implements DHTDeleteable { /// Add a reference to this log @override - Future ref() async => _mutex.protect(() async { - _openCount++; - }); + void ref() { + _openCount++; + } /// Free all resources for the DHTLog @override - Future close() async => _mutex.protect(() async { - if (_openCount == 0) { - throw StateError('already closed'); - } - _openCount--; - if (_openCount != 0) { - return false; - } - await _watchController?.close(); - _watchController = null; - await _spine.close(); - return true; - }); + Future close() async { + if (_openCount == 0) { + throw StateError('already closed'); + } + _openCount--; + if (_openCount != 0) { + return false; + } + // + await _watchController?.close(); + _watchController = null; + await _spine.close(); + return true; + } /// Free all resources for the DHTLog and delete it from the DHT /// Will wait until the short array is closed to delete it @override - Future delete() async { - await _spine.delete(); - } + Future delete() => _spine.delete(); //////////////////////////////////////////////////////////////////////////// // Public API @@ -306,7 +305,6 @@ class DHTLog implements DHTDeleteable { // Openable int _openCount; - final _mutex = Mutex(debugLockTimeout: kIsDebugMode ? 60 : null); // Watch mutex to ensure we keep the representation valid final Mutex _listenMutex = Mutex(debugLockTimeout: kIsDebugMode ? 60 : null); diff --git a/packages/veilid_support/lib/dht_support/src/dht_log/dht_log_spine.dart b/packages/veilid_support/lib/dht_support/src/dht_log/dht_log_spine.dart index 1ea48be..8eff1b6 100644 --- a/packages/veilid_support/lib/dht_support/src/dht_log/dht_log_spine.dart +++ b/packages/veilid_support/lib/dht_support/src/dht_log/dht_log_spine.dart @@ -24,13 +24,11 @@ class _DHTLogPosition extends DHTCloseable { /// Add a reference to this log @override - Future ref() async { - await shortArray.ref(); - } + void ref() => shortArray.ref(); /// Free all resources for the DHTLogPosition @override - Future close() async => _dhtLogSpine._segmentClosed(_segmentNumber); + Future close() => _dhtLogSpine._segmentClosed(_segmentNumber); } class _DHTLogSegmentLookup extends Equatable { @@ -124,12 +122,8 @@ class _DHTLogSpine { }); } - Future delete() async { - await _spineMutex.protect(() async { - // Will deep delete all segment records as they are children - await _spineRecord.delete(); - }); - } + // Will deep delete all segment records as they are children + Future delete() async => _spineMutex.protect(_spineRecord.delete); Future operate(Future Function(_DHTLogSpine) closure) async => // ignore: prefer_expression_function_bodies @@ -431,7 +425,7 @@ class _DHTLogSpine { late DHTShortArray shortArray; if (openedSegment != null) { // If so, return a ref - await openedSegment.ref(); + openedSegment.ref(); shortArray = openedSegment; } else { // Otherwise open a segment @@ -453,7 +447,7 @@ class _DHTLogSpine { // LRU cache the segment number if (!_openCache.remove(segmentNumber)) { // If this is new to the cache ref it when it goes in - await shortArray.ref(); + shortArray.ref(); } _openCache.add(segmentNumber); if (_openCache.length > _openCacheSize) { diff --git a/packages/veilid_support/lib/dht_support/src/dht_record/dht_record.dart b/packages/veilid_support/lib/dht_support/src/dht_record/dht_record.dart index bddb4e7..0a51ba1 100644 --- a/packages/veilid_support/lib/dht_support/src/dht_record/dht_record.dart +++ b/packages/veilid_support/lib/dht_support/src/dht_record/dht_record.dart @@ -64,34 +64,35 @@ class DHTRecord implements DHTDeleteable { /// Add a reference to this DHTRecord @override - Future ref() async => _mutex.protect(() async { - _openCount++; - }); + void ref() { + _openCount++; + } /// Free all resources for the DHTRecord @override - Future close() async => _mutex.protect(() async { - if (_openCount == 0) { - throw StateError('already closed'); - } - _openCount--; - if (_openCount != 0) { - return false; - } + Future close() async { + if (_openCount == 0) { + throw StateError('already closed'); + } + _openCount--; + if (_openCount != 0) { + return false; + } - await serialFutureClose((this, _sfListen)); - await _watchController?.close(); - _watchController = null; - await DHTRecordPool.instance._recordClosed(this); - return true; - }); + await _watchController?.close(); + _watchController = null; + await serialFutureClose((this, _sfListen)); + + await DHTRecordPool.instance._recordClosed(this); + + return true; + } /// Free all resources for the DHTRecord and delete it from the DHT - /// Will wait until the record is closed to delete it + /// Returns true if the deletion was processed immediately + /// Returns false if the deletion was marked for later @override - Future delete() async => _mutex.protect(() async { - await DHTRecordPool.instance.deleteRecord(key); - }); + Future delete() async => DHTRecordPool.instance.deleteRecord(key); //////////////////////////////////////////////////////////////////////////// // Public API @@ -562,7 +563,6 @@ class DHTRecord implements DHTDeleteable { final KeyPair? _writer; final VeilidCrypto _crypto; final String debugName; - final _mutex = Mutex(debugLockTimeout: kIsDebugMode ? 60 : null); int _openCount; StreamController? _watchController; _WatchState? _watchState; diff --git a/packages/veilid_support/lib/dht_support/src/dht_record/dht_record_pool.dart b/packages/veilid_support/lib/dht_support/src/dht_record/dht_record_pool.dart index 3f55687..15c955d 100644 --- a/packages/veilid_support/lib/dht_support/src/dht_record/dht_record_pool.dart +++ b/packages/veilid_support/lib/dht_support/src/dht_record/dht_record_pool.dart @@ -479,25 +479,29 @@ class DHTRecordPool with TableDBBackedJson { // Called when a DHTRecord is closed // Cleans up the opened record housekeeping and processes any late deletions Future _recordClosed(DHTRecord record) async { - await _recordTagLock.protect(record.key, - closure: () => _mutex.protect(() async { - final key = record.key; + final key = record.key; + await _recordTagLock.protect(key, closure: () async { + await _mutex.protect(() async { + log('closeDHTRecord: debugName=${record.debugName} key=$key'); - log('closeDHTRecord: debugName=${record.debugName} key=$key'); + final openedRecordInfo = _opened[key]; + if (openedRecordInfo == null || + !openedRecordInfo.records.remove(record)) { + throw StateError('record already closed'); + } + if (openedRecordInfo.records.isNotEmpty) { + return; + } + _opened.remove(key); + await _routingContext.closeDHTRecord(key); + await _checkForLateDeletesInner(key); + }); - final openedRecordInfo = _opened[key]; - if (openedRecordInfo == null || - !openedRecordInfo.records.remove(record)) { - throw StateError('record already closed'); - } - if (openedRecordInfo.records.isEmpty) { - await _watchStateProcessors.remove(key); - await _routingContext.closeDHTRecord(key); - _opened.remove(key); - - await _checkForLateDeletesInner(key); - } - })); + // This happens after the mutex is released + // because the record has already been removed from _opened + // which means that updates to the state processor won't happen + await _watchStateProcessors.remove(key); + }); } // Check to see if this key can finally be deleted @@ -929,40 +933,37 @@ class DHTRecordPool with TableDBBackedJson { } /// Ticker to check watch state change requests - Future tick() async { - final now = veilid.now(); + Future tick() async => _mutex.protect(() async { + // See if any opened records need watch state changes + final now = veilid.now(); + for (final kv in _opened.entries) { + final openedRecordKey = kv.key; + final openedRecordInfo = kv.value; - await _mutex.protect(() async { - // See if any opened records need watch state changes - for (final kv in _opened.entries) { - final openedRecordKey = kv.key; - final openedRecordInfo = kv.value; + var wantsWatchStateUpdate = + openedRecordInfo.shared.needsWatchStateUpdate; - var wantsWatchStateUpdate = - openedRecordInfo.shared.needsWatchStateUpdate; + // Check if we have reached renewal time for the watch + if (openedRecordInfo.shared.unionWatchState != null && + openedRecordInfo.shared.unionWatchState!.renewalTime != null && + now.value > + openedRecordInfo.shared.unionWatchState!.renewalTime!.value) { + wantsWatchStateUpdate = true; + } - // Check if we have reached renewal time for the watch - if (openedRecordInfo.shared.unionWatchState != null && - openedRecordInfo.shared.unionWatchState!.renewalTime != null && - now.value > - openedRecordInfo.shared.unionWatchState!.renewalTime!.value) { - wantsWatchStateUpdate = true; + if (wantsWatchStateUpdate) { + // Update union watch state + final unionWatchState = + _collectUnionWatchState(openedRecordInfo.records); + + _watchStateProcessors.updateState( + openedRecordKey, + unionWatchState, + (newState) => + _watchStateChange(openedRecordKey, unionWatchState)); + } } - - if (wantsWatchStateUpdate) { - // Update union watch state - final unionWatchState = - _collectUnionWatchState(openedRecordInfo.records); - - _watchStateProcessors.updateState( - openedRecordKey, - unionWatchState, - (newState) => - _watchStateChange(openedRecordKey, unionWatchState)); - } - } - }); - } + }); ////////////////////////////////////////////////////////////// // AsyncTableDBBacked diff --git a/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array.dart b/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array.dart index c0ec901..8101a7a 100644 --- a/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array.dart +++ b/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array.dart @@ -148,33 +148,32 @@ class DHTShortArray implements DHTDeleteable { /// Add a reference to this shortarray @override - Future ref() async => _mutex.protect(() async { - _openCount++; - }); + void ref() { + _openCount++; + } /// Free all resources for the DHTShortArray @override - Future close() async => _mutex.protect(() async { - if (_openCount == 0) { - throw StateError('already closed'); - } - _openCount--; - if (_openCount != 0) { - return false; - } + Future close() async { + if (_openCount == 0) { + throw StateError('already closed'); + } + _openCount--; + if (_openCount != 0) { + return false; + } - await _watchController?.close(); - _watchController = null; - await _head.close(); - return true; - }); + await _watchController?.close(); + _watchController = null; + await _head.close(); + return true; + } /// Free all resources for the DHTShortArray and delete it from the DHT - /// Will wait until the short array is closed to delete it + /// Returns true if the deletion was processed immediately + /// Returns false if the deletion was marked for later @override - Future delete() async { - await _head.delete(); - } + Future delete() async => _head.delete(); //////////////////////////////////////////////////////////////////////////// // Public API @@ -289,7 +288,6 @@ class DHTShortArray implements DHTDeleteable { // Openable int _openCount; - final _mutex = Mutex(debugLockTimeout: kIsDebugMode ? 60 : null); // Watch mutex to ensure we keep the representation valid final Mutex _listenMutex = Mutex(debugLockTimeout: kIsDebugMode ? 60 : null); diff --git a/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array_cubit.dart b/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array_cubit.dart index 8bdda7c..ab56c77 100644 --- a/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array_cubit.dart +++ b/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array_cubit.dart @@ -8,7 +8,6 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:meta/meta.dart'; import '../../../veilid_support.dart'; -import '../interfaces/refreshable_cubit.dart'; @immutable class DHTShortArrayElementState extends Equatable { diff --git a/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array_head.dart b/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array_head.dart index 4a2c79a..0aaed19 100644 --- a/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array_head.dart +++ b/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array_head.dart @@ -65,12 +65,9 @@ class _DHTShortArrayHead { }); } - Future delete() async { - await _headMutex.protect(() async { - // Will deep delete all linked records as they are children - await _headRecord.delete(); - }); - } + /// Returns true if the deletion was processed immediately + /// Returns false if the deletion was marked for later + Future delete() => _headMutex.protect(_headRecord.delete); Future operate(Future Function(_DHTShortArrayHead) closure) async => // ignore: prefer_expression_function_bodies diff --git a/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array_write.dart b/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array_write.dart index c52a7b2..f3e1ac3 100644 --- a/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array_write.dart +++ b/packages/veilid_support/lib/dht_support/src/dht_short_array/dht_short_array_write.dart @@ -40,7 +40,7 @@ class _DHTShortArrayWrite extends _DHTShortArrayRead } } if (!success) { - throw DHTExceptionOutdated(); + throw const DHTExceptionOutdated(); } } @@ -97,7 +97,7 @@ class _DHTShortArrayWrite extends _DHTShortArrayRead } } if (!success) { - throw DHTExceptionOutdated(); + throw const DHTExceptionOutdated(); } } diff --git a/packages/veilid_support/lib/dht_support/src/interfaces/dht_closeable.dart b/packages/veilid_support/lib/dht_support/src/interfaces/dht_closeable.dart index c913340..0fb10ab 100644 --- a/packages/veilid_support/lib/dht_support/src/interfaces/dht_closeable.dart +++ b/packages/veilid_support/lib/dht_support/src/interfaces/dht_closeable.dart @@ -4,7 +4,7 @@ import 'package:meta/meta.dart'; abstract class DHTCloseable { // Public interface - Future ref(); + void ref(); Future close(); // Internal implementation @@ -15,7 +15,9 @@ abstract class DHTCloseable { } abstract class DHTDeleteable extends DHTCloseable { - Future delete(); + /// Returns true if the deletion was processed immediately + /// Returns false if the deletion was marked for later + Future delete(); } extension DHTCloseableExt on DHTCloseable { diff --git a/pubspec.lock b/pubspec.lock index fa60f63..b4df49f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -156,10 +156,9 @@ packages: bloc_advanced_tools: dependency: "direct main" description: - name: bloc_advanced_tools - sha256: "977f3c7e3f9a19aec2f2c734ae99c8f0799c1b78f9fd7e4dce91a2dbf773e11b" - url: "https://pub.dev" - source: hosted + path: "../bloc_advanced_tools" + relative: true + source: path version: "0.1.9" blurry_modal_progress_hud: dependency: "direct main" diff --git a/pubspec.yaml b/pubspec.yaml index a37a8ab..b909a16 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -111,11 +111,11 @@ dependencies: xterm: ^4.0.0 zxing2: ^0.2.3 -# dependency_overrides: +dependency_overrides: # async_tools: # path: ../dart_async_tools -# bloc_advanced_tools: -# path: ../bloc_advanced_tools + bloc_advanced_tools: + path: ../bloc_advanced_tools # searchable_listview: # path: ../Searchable-Listview # flutter_chat_ui: