android and approve mode

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2023-06-28 20:22:57 +08:00
parent bb679bf25a
commit f38ebb7b3c
2 changed files with 79 additions and 53 deletions

View File

@ -25,6 +25,18 @@ class ServerPage extends StatefulWidget implements PageShape {
PopupMenuButton<String>(
icon: const Icon(Icons.more_vert),
itemBuilder: (context) {
listTile(String text, bool checked) {
return ListTile(
title: Text(translate(text)),
trailing: Icon(
Icons.check,
color: checked ? null : Colors.transparent,
));
}
final approveMode = gFFI.serverModel.approveMode;
final verificationMethod = gFFI.serverModel.verificationMethod;
final showPasswordOption = approveMode != 'click';
return [
PopupMenuItem(
enabled: gFFI.serverModel.connectStatus > 0,
@ -32,61 +44,63 @@ class ServerPage extends StatefulWidget implements PageShape {
value: "changeID",
child: Text(translate("Change ID")),
),
PopupMenuItem(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
value: "setPermanentPassword",
enabled:
gFFI.serverModel.verificationMethod != kUseTemporaryPassword,
child: Text(translate("Set permanent password")),
),
PopupMenuItem(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
value: "setTemporaryPasswordLength",
enabled:
gFFI.serverModel.verificationMethod != kUsePermanentPassword,
child: Text(translate("One-time password length")),
),
const PopupMenuDivider(),
PopupMenuItem(
padding: const EdgeInsets.symmetric(horizontal: 0.0),
value: kUseTemporaryPassword,
child: ListTile(
title: Text(translate("Use one-time password")),
trailing: Icon(
Icons.check,
color: gFFI.serverModel.verificationMethod ==
kUseTemporaryPassword
? null
: Colors.transparent,
)),
value: 'AcceptSessionsViaPassword',
child: listTile(
'Accept sessions via password', approveMode == 'password'),
),
PopupMenuItem(
padding: const EdgeInsets.symmetric(horizontal: 0.0),
value: 'AcceptSessionsViaClick',
child:
listTile('Accept sessions via click', approveMode == 'click'),
),
PopupMenuItem(
padding: const EdgeInsets.symmetric(horizontal: 0.0),
value: "AcceptSessionsViaBoth",
child: listTile("Accept sessions via both",
approveMode != 'password' && approveMode != 'click'),
),
if (showPasswordOption) const PopupMenuDivider(),
if (showPasswordOption &&
verificationMethod != kUseTemporaryPassword)
PopupMenuItem(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
value: "setPermanentPassword",
child: Text(translate("Set permanent password")),
),
if (showPasswordOption &&
verificationMethod != kUsePermanentPassword)
PopupMenuItem(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
value: "setTemporaryPasswordLength",
child: Text(translate("One-time password length")),
),
if (showPasswordOption) const PopupMenuDivider(),
if (showPasswordOption)
PopupMenuItem(
padding: const EdgeInsets.symmetric(horizontal: 0.0),
value: kUseTemporaryPassword,
child: listTile('Use one-time password',
verificationMethod == kUseTemporaryPassword),
),
if (showPasswordOption)
PopupMenuItem(
padding: const EdgeInsets.symmetric(horizontal: 0.0),
value: kUsePermanentPassword,
child: ListTile(
title: Text(translate("Use permanent password")),
trailing: Icon(
Icons.check,
color: gFFI.serverModel.verificationMethod ==
kUsePermanentPassword
? null
: Colors.transparent,
)),
child: listTile('Use permanent password',
verificationMethod == kUsePermanentPassword),
),
if (showPasswordOption)
PopupMenuItem(
padding: const EdgeInsets.symmetric(horizontal: 0.0),
value: kUseBothPasswords,
child: ListTile(
title: Text(translate("Use both passwords")),
trailing: Icon(
Icons.check,
color: gFFI.serverModel.verificationMethod !=
kUseTemporaryPassword &&
gFFI.serverModel.verificationMethod !=
kUsePermanentPassword
? null
: Colors.transparent,
)),
child: listTile(
'Use both passwords',
verificationMethod != kUseTemporaryPassword &&
verificationMethod != kUsePermanentPassword),
),
];
},
@ -102,6 +116,15 @@ class ServerPage extends StatefulWidget implements PageShape {
value == kUseBothPasswords) {
bind.mainSetOption(key: "verification-method", value: value);
gFFI.serverModel.updatePasswordModel();
} else if (value.startsWith("AcceptSessionsVia")) {
value = value.substring("AcceptSessionsVia".length);
if (value == "Password") {
gFFI.serverModel.setApproveMode('password');
} else if (value == "Click") {
gFFI.serverModel.setApproveMode('click');
} else {
gFFI.serverModel.setApproveMode('');
}
}
})
];
@ -434,11 +457,13 @@ class ConnectionManager extends StatelessWidget {
serverModel.sendLoginResponse(
client, false);
}).marginOnly(right: 15),
if (serverModel.approveMode != 'password')
ElevatedButton.icon(
icon: const Icon(Icons.check),
label: Text(translate("Accept")),
onPressed: () {
serverModel.sendLoginResponse(client, true);
serverModel.sendLoginResponse(
client, true);
}),
]),
])))

View File

@ -520,6 +520,7 @@ class ServerModel with ChangeNotifier {
),
actions: [
dialogButton("Dismiss", onPressed: cancel, isOutline: true),
if (approveMode != 'password')
dialogButton("Accept", onPressed: submit),
],
onSubmit: submit,