From fbaab3744e3ab5fceec27d52393870bb6a508978 Mon Sep 17 00:00:00 2001 From: lemoer Date: Sat, 5 Jul 2025 21:26:41 +0200 Subject: [PATCH] Add a "this device" hint --- app/lib/main.dart | 67 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/app/lib/main.dart b/app/lib/main.dart index edf8492..4dfeb75 100644 --- a/app/lib/main.dart +++ b/app/lib/main.dart @@ -311,8 +311,13 @@ class _MyHomePageState extends State { case AuthentikUserSettingsChangeDialogStatus.userSettingsObtained: title = Text("User Settings Obtained"); children = [Text("You can now edit your user settings.")]; - for (var key in authentikApiState.allKeys) { - children.add(KeepOrDeleteKey(sshKey: key)); + for (var k in authentikApiState.allKeys) { + children.add(KeepOrDeleteKey(sshKey: k, isOurKey: k == key)); + } + + if (!authentikApiState.allKeys.contains(key)) { + // If the key is not already in the list, add it + children.add(KeepOrDeleteKey(sshKey: key, isOurKey: true)); } actions.add( @@ -584,12 +589,21 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier { class KeepOrDeleteKey extends StatelessWidget { final String sshKey; + final bool isOurKey; - const KeepOrDeleteKey({super.key, required this.sshKey}); + const KeepOrDeleteKey({ + super.key, + required this.sshKey, + this.isOurKey = false, + }); @override Widget build(BuildContext context) { final key = sshKey; + final isKeyPreviouslyExisting = context + .select( + (keylist) => keylist.allKeys.contains(key), + ); final isKeySelectedToKeep = context .select( (keylist) => keylist.isKeySelectedToKeep(key), @@ -622,14 +636,41 @@ class KeepOrDeleteKey extends StatelessWidget { } } + var textPush = "Keep Key"; + var textDoNotPush = "Select for Deletion"; + + if (!isKeyPreviouslyExisting) { + textPush = "Push Key"; + textDoNotPush = "Do Not Push Key"; + } + + Widget titleWidget = Text(title, style: TextStyle(fontSize: 25)); + + if (isOurKey) { + titleWidget = Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + titleWidget, + Container( + decoration: BoxDecoration( + color: Colors.green, + borderRadius: BorderRadius.circular(5), + ), + padding: EdgeInsets.all(5), + child: Text( + "This Device", + style: TextStyle(fontSize: 15, color: Colors.white), + ), + ), + ], + ); + } + return Card( margin: EdgeInsets.fromLTRB(20, 20, 20, 0), child: Column( children: [ - Padding( - padding: EdgeInsets.all(20), - child: Text(title, style: TextStyle(fontSize: 25)), - ), + Padding(padding: EdgeInsets.all(20), child: titleWidget), Padding( padding: EdgeInsets.fromLTRB(20, 0, 20, 20), child: Text(sshKey, style: TextStyle(fontSize: 15)), @@ -644,20 +685,20 @@ class KeepOrDeleteKey extends StatelessWidget { Provider.of( context, listen: false, - ).selectKeyForDeletion(sshKey); + ).keepKey(sshKey); }, - style: buttonStyleDelete, - child: Text('Select for Deletion'), + style: buttonStyleKeep, + child: Text(textPush), ), TextButton( onPressed: () { Provider.of( context, listen: false, - ).keepKey(sshKey); + ).selectKeyForDeletion(sshKey); }, - style: buttonStyleKeep, - child: Text('Keep Key'), + style: buttonStyleDelete, + child: Text(textDoNotPush), ), ], ),