Skip to content

Commit

Permalink
add debug menu
Browse files Browse the repository at this point in the history
Allows interacting with the app to test different scenarios
  • Loading branch information
Merrit committed Oct 14, 2024
1 parent 4501fb2 commit 60e0213
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/apps_list/cubit/apps_list_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class AppsListCubit extends Cubit<AppsListState> {
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];
Expand Down Expand Up @@ -327,7 +327,10 @@ class AppsListCubit extends Cubit<AppsListState> {
}

/// Refresh the process status and add an [InteractionError].
Future<void> _addInteractionError(
///
/// Visible so it can be used by the debug menu.
@visibleForTesting
Future<void> addInteractionError(
Window window,
InteractionType interaction,
) async {
Expand Down
41 changes: 41 additions & 0 deletions lib/apps_list/widgets/custom_app_bar.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -46,6 +47,7 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
actions: [
updateAvailableButton,
const _WaylandWarningButton(),
const _DebugButton(),
settingsButton,
],
);
Expand Down Expand Up @@ -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<AppsListCubit>();

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,
);
},
),
],
);
}
}

0 comments on commit 60e0213

Please sign in to comment.