From 468e642a25690641fa75f0fa1274b8baf9ee92fa Mon Sep 17 00:00:00 2001 From: Aleksandrs Vinarskis Date: Sun, 18 Feb 2024 21:48:17 +0100 Subject: [PATCH] fix: UI: distinguish CCTK requests by id --- lib/classes/api_cctk.dart | 6 +++-- lib/classes/cctk_state.dart | 3 ++- .../notification_bios_protection.dart | 12 ++++++---- pubspec.lock | 24 +++++++++++++++++++ pubspec.yaml | 1 + 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/classes/api_cctk.dart b/lib/classes/api_cctk.dart index 9f917a2..4ef30b0 100644 --- a/lib/classes/api_cctk.dart +++ b/lib/classes/api_cctk.dart @@ -4,6 +4,7 @@ import 'dart:io'; import 'package:dell_powermanager/classes/bios_protection_manager.dart'; import 'package:process_run/shell.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:uuid/uuid.dart'; import '../configs/constants.dart'; import '../classes/dependencies_manager.dart'; @@ -39,6 +40,7 @@ class ApiCCTK { static Shell _shell = Shell(); static SharedPreferences? _prefs; + static const _uuid = Uuid(); static final CCTKState cctkState = CCTKState(); @@ -186,7 +188,7 @@ class ApiCCTK { return true; } - static Future request(String cctkType, String mode) async { + static Future request(String cctkType, String mode, {String? requestCode}) async { /* Query, process, and respond */ late String cmd; if (Platform.isLinux) { @@ -196,7 +198,7 @@ class ApiCCTK { } ProcessResult pr = await _runCctk(cmd); bool success = _processResponse(pr); - cctkState.exitStateWrite = ExitState(pr.exitCode, cctkType, mode); + cctkState.exitStateWrite = ExitState(pr.exitCode, cctkType, mode, requestCode?? _uuid.v4()); _callStateChanged(cctkState); return success; } diff --git a/lib/classes/cctk_state.dart b/lib/classes/cctk_state.dart index 58293ad..94600a6 100644 --- a/lib/classes/cctk_state.dart +++ b/lib/classes/cctk_state.dart @@ -11,8 +11,9 @@ class ExitState { int exitCode; String cctkType; String mode; + String requestCode; - ExitState(this.exitCode, this.cctkType, this.mode); + ExitState(this.exitCode, this.cctkType, this.mode, this.requestCode); } class CCTKState { diff --git a/lib/components/notification_bios_protection.dart b/lib/components/notification_bios_protection.dart index 9ee36f9..0e8bf26 100644 --- a/lib/components/notification_bios_protection.dart +++ b/lib/components/notification_bios_protection.dart @@ -46,6 +46,7 @@ class NotificationBiosProtectionState extends State final FocusNode modalButtonFocusNode = FocusNode(); final TextEditingController modalPwdController = TextEditingController(); bool _savingPwd = false; + String _lastRequestCode = ""; @override void initState() { @@ -65,6 +66,10 @@ class NotificationBiosProtectionState extends State if (cctkState.exitStateWrite == null) { return; } + if (cctkState.exitStateWrite!.requestCode == _lastRequestCode) { + return; + } + _lastRequestCode = cctkState.exitStateWrite!.requestCode; /* Once succeeded, exit */ if (cctkState.exitStateWrite!.exitCode == CCTK.exitCodes.ok) { @@ -90,11 +95,8 @@ class NotificationBiosProtectionState extends State /* Ignore state, if issue was already detected */ if ( - _biosProtectionState == BiosProtectionState.unlockingSucceeded || - _biosProtectionState == BiosProtectionState.unlockingSysPwdFailed || - _biosProtectionState == BiosProtectionState.unlockingSetupPwdFailed || - _biosProtectionState == BiosProtectionState.missingSetupPwd || - _biosProtectionState == BiosProtectionState.missingSysPwd + _biosProtectionState != BiosProtectionState.hidden && + _biosProtectionState != BiosProtectionState.unlocking ) { return; } diff --git a/pubspec.lock b/pubspec.lock index ebc31c1..2a934f0 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -89,6 +89,14 @@ packages: url: "https://pub.dev" source: hosted version: "7.0.0" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" + url: "https://pub.dev" + source: hosted + version: "1.1.0" flutter: dependency: "direct main" description: flutter @@ -466,6 +474,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.10.0" + sprintf: + dependency: transitive + description: + name: sprintf + sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" + url: "https://pub.dev" + source: hosted + version: "7.0.0" stack_trace: dependency: transitive description: @@ -594,6 +610,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.0" + uuid: + dependency: "direct main" + description: + name: uuid + sha256: cd210a09f7c18cbe5a02511718e0334de6559871052c90a90c0cca46a4aa81c8 + url: "https://pub.dev" + source: hosted + version: "4.3.3" vector_graphics: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 400acac..a6a2c9a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -48,6 +48,7 @@ dependencies: shared_preferences: ^2.2.2 flutter_secure_storage: ^9.0.0 passwordfield: ^0.2.0 + uuid: ^4.3.3 dev_dependencies: flutter_test: