Skip to content

Commit

Permalink
fix: UI: distinguish CCTK requests by id
Browse files Browse the repository at this point in the history
  • Loading branch information
alexVinarskis committed Feb 18, 2024
1 parent b7f9788 commit 7ee48bd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lib/classes/api_cctk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -39,6 +40,7 @@ class ApiCCTK {
static Shell _shell = Shell();

static SharedPreferences? _prefs;
static const _uuid = Uuid();

static final CCTKState cctkState = CCTKState();

Expand Down Expand Up @@ -186,7 +188,7 @@ class ApiCCTK {
return true;
}

static Future<bool> request(String cctkType, String mode) async {
static Future<bool> request(String cctkType, String mode, {String? requestCode}) async {
/* Query, process, and respond */
late String cmd;
if (Platform.isLinux) {
Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/classes/cctk_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 7 additions & 5 deletions lib/components/notification_bios_protection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class NotificationBiosProtectionState extends State<NotificationBiosProtection>
final FocusNode modalButtonFocusNode = FocusNode();
final TextEditingController modalPwdController = TextEditingController();
bool _savingPwd = false;
String _lastRequestCode = "";

@override
void initState() {
Expand All @@ -65,6 +66,10 @@ class NotificationBiosProtectionState extends State<NotificationBiosProtection>
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) {
Expand All @@ -90,11 +95,8 @@ class NotificationBiosProtectionState extends State<NotificationBiosProtection>

/* 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;
}
Expand Down
24 changes: 24 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7ee48bd

Please sign in to comment.