diff --git a/lib/apps_list/cubit/apps_list_cubit.dart b/lib/apps_list/cubit/apps_list_cubit.dart index 178341d..04a7aaf 100644 --- a/lib/apps_list/cubit/apps_list_cubit.dart +++ b/lib/apps_list/cubit/apps_list_cubit.dart @@ -184,7 +184,7 @@ class AppsListCubit extends Cubit { window = await _refreshWindowProcess(window); log.i('Window after interaction: $window'); - if (!successful) await _addInteractionError(window, interaction); + if (!successful) await addInteractionError(window, interaction); // Create a copy of the state of windows, with this window's info refreshed. final windows = [...state.windows]; @@ -327,7 +327,10 @@ class AppsListCubit extends Cubit { } /// Refresh the process status and add an [InteractionError]. - Future _addInteractionError( + /// + /// Visible so it can be used by the debug menu. + @visibleForTesting + Future addInteractionError( Window window, InteractionType interaction, ) async { diff --git a/lib/apps_list/widgets/custom_app_bar.dart b/lib/apps_list/widgets/custom_app_bar.dart index 1116be3..a3658b8 100644 --- a/lib/apps_list/widgets/custom_app_bar.dart +++ b/lib/apps_list/widgets/custom_app_bar.dart @@ -1,3 +1,4 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -46,6 +47,7 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { actions: [ updateAvailableButton, const _WaylandWarningButton(), + const _DebugButton(), settingsButton, ], ); @@ -208,3 +210,42 @@ class _WaylandWarningButton extends StatelessWidget { ); } } + +/// A button that shows the debug menu. +class _DebugButton extends StatelessWidget { + const _DebugButton(); + + @override + Widget build(BuildContext context) { + if (!kDebugMode) return const SizedBox(); + + final appsListCubit = context.read(); + + return MenuAnchor( + builder: (context, controller, child) { + return IconButton( + onPressed: () { + if (controller.isOpen) { + controller.close(); + } else { + controller.open(); + } + }, + icon: const Icon(Icons.bug_report), + ); + }, + menuChildren: [ + MenuItemButton( + child: const Text('Add Interaction Error'), + onPressed: () async { + // ignore: invalid_use_of_visible_for_testing_member + await appsListCubit.addInteractionError( + appsListCubit.state.windows.first, + InteractionType.suspend, + ); + }, + ), + ], + ); + } +}