Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate an AlertDialog screen when A/C must be applied for some updates to proceed - this is issue #215. #256

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions packages/firmware_updater/lib/firmware_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:firmware_updater/fwupd_mock_service.dart';
import 'package:firmware_updater/fwupd_notifier.dart';
import 'package:firmware_updater/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:fwupd/fwupd.dart';
import 'package:gtk/gtk.dart';
Expand Down Expand Up @@ -39,6 +40,7 @@ class FirmwareApp extends StatefulWidget {
class _FirmwareAppState extends State<FirmwareApp> {
YaruPageController? _controller;
bool _initialized = false;
bool _onBattery = false;

@override
void initState() {
Expand All @@ -60,6 +62,36 @@ class _FirmwareAppState extends State<FirmwareApp> {
});
});
gtkNotifier.addCommandLineListener(_commandLineListener);

SchedulerBinding.instance.addPostFrameCallback((_) async {
final l10n = AppLocalizations.of(context);
if (_onBattery) {
await _showAlertDialog(l10n.acPowerTitle, l10n.acPowerMustBeSupplied);
}
});
}

Future<dynamic> _showAlertDialog(String titleP, String contentP) {
return showDialog(
context: context,
builder: (context) {
final l10n = AppLocalizations.of(context);
// return object of type Dialog
return AlertDialog(
title: Text(titleP),
content: Text(contentP),
actions: <Widget>[
// usually buttons at the bottom of the dialog
TextButton(
child: Text(l10n.ok),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}

@override
Expand Down Expand Up @@ -109,12 +141,10 @@ class _FirmwareAppState extends State<FirmwareApp> {
Widget build(BuildContext context) {
final store = context.watch<DeviceStore>();
final l10n = AppLocalizations.of(context);
_onBattery =
context.select<FwupdNotifier, bool>((notifier) => notifier.onBattery);
return _initialized
? ErrorBanner(
message: context.select<FwupdNotifier, bool>(
(notifier) => notifier.onBattery)
? l10n.batteryWarning
: null,
? Center(
child: YaruMasterDetailPage(
appBar: YaruWindowTitleBar(title: Text(l10n.appTitle)),
controller: _controller,
Expand Down
6 changes: 5 additions & 1 deletion packages/firmware_updater/lib/src/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,9 @@
},
"currentVersion": "Current Version",
"minVersion": "Minimum Version",
"latestVersion": "Latest Version"
"latestVersion": "Latest Version",
"acPowerTitle": "You are currently on battery power",
"acPowerMustBeSupplied": "BIOS and other updates can't commence on battery power.\nPlug into A/C power and restart this app to perform those updates if available.",
"legacyBootTitle": "Legacy Boot Mode is selected in the BIOS",
"legacyBootCantUpdateInThisMode": "BIOS and other updates can't commence in this mode.\nSwitch to UEFI Boot Mode in the BIOS to proceed.\nNote - this may require an OS reinstall."
}
59 changes: 0 additions & 59 deletions packages/firmware_updater/lib/src/widgets/error_banner.dart

This file was deleted.

1 change: 0 additions & 1 deletion packages/firmware_updater/lib/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export 'src/widgets/device_header.dart';
export 'src/widgets/device_icon.dart';
export 'src/widgets/device_panel_list.dart';
export 'src/widgets/dialogs.dart';
export 'src/widgets/error_banner.dart';
export 'src/widgets/option_card.dart';
export 'src/widgets/refresh_button.dart';
export 'src/widgets/release_card.dart';
Expand Down
9 changes: 8 additions & 1 deletion packages/firmware_updater/test/firmware_app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,19 @@ void main() {
registerMockService<FwupdDbusService>(mockService());
registerMockService<GtkApplicationNotifier>(mockGtkApplicationNotifier());

// Check to make sure the AC-power warning dialog is displayed
final store = mockStore(devices: devices);
await tester.pumpApp((_) =>
buildPage(store: store, notifier: mockNotifier(onBattery: true)));
await tester.pumpAndSettle();

expect(find.text(tester.lang.batteryWarning), findsOneWidget);
expect(find.text(tester.lang.acPowerMustBeSupplied), findsOneWidget);

// Make sure the dialog is dismissed by pressing the "OK" button
// (The OK button is the only TextButton on the dialog)
await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle();
expect(find.text(tester.lang.acPowerMustBeSupplied), findsNothing);
});

testWidgets('register callbacks', (tester) async {
Expand Down
Loading