approve mode, cm sync option

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2022-11-20 15:53:08 +08:00
parent 8b20237096
commit 05c549a5fe
39 changed files with 298 additions and 56 deletions

View File

@@ -580,20 +580,21 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {
return ChangeNotifierProvider.value(
value: gFFI.serverModel,
child: Consumer<ServerModel>(builder: ((context, model, child) {
List<String> keys = [
List<String> passwordKeys = [
kUseTemporaryPassword,
kUsePermanentPassword,
kUseBothPasswords,
];
List<String> values = [
List<String> passwordValues = [
translate('Use temporary password'),
translate('Use permanent password'),
translate('Use both passwords'),
];
bool tmpEnabled = model.verificationMethod != kUsePermanentPassword;
bool permEnabled = model.verificationMethod != kUseTemporaryPassword;
String currentValue = values[keys.indexOf(model.verificationMethod)];
List<Widget> radios = values
String currentValue =
passwordValues[passwordKeys.indexOf(model.verificationMethod)];
List<Widget> radios = passwordValues
.map((value) => _Radio<String>(
context,
value: value,
@@ -601,8 +602,8 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {
label: value,
onChanged: ((value) {
() async {
await model
.setVerificationMethod(keys[values.indexOf(value)]);
await model.setVerificationMethod(
passwordKeys[passwordValues.indexOf(value)]);
await model.updatePasswordModel();
}();
}),
@@ -640,20 +641,51 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {
))
.toList();
final modeKeys = ['password', 'click', ''];
final modeValues = [
translate('Accept sessions via password'),
translate('Accept sessions via click'),
translate('Accept sessions via both'),
];
var modeInitialKey = model.approveMode;
if (!modeKeys.contains(modeInitialKey)) modeInitialKey = '';
final usePassword = model.approveMode != 'click';
return _Card(title: 'Password', children: [
radios[0],
_SubLabeledWidget(
'Temporary Password Length',
Row(
children: [
...lengthRadios,
],
),
enabled: tmpEnabled && !locked),
radios[1],
_SubButton('Set permanent password', setPasswordDialog,
permEnabled && !locked),
radios[2],
_ComboBox(
keys: modeKeys,
values: modeValues,
initialKey: modeInitialKey,
onChanged: (key) => model.setApproveMode(key),
).marginOnly(left: _kContentHMargin),
Offstage(
offstage: !usePassword,
child: radios[0],
),
Offstage(
offstage: !usePassword,
child: _SubLabeledWidget(
'Temporary Password Length',
Row(
children: [
...lengthRadios,
],
),
enabled: tmpEnabled && !locked),
),
Offstage(
offstage: !usePassword,
child: radios[1],
),
Offstage(
offstage: !usePassword,
child: _SubButton('Set permanent password', setPasswordDialog,
permEnabled && !locked),
),
Offstage(
offstage: !usePassword,
child: radios[2],
),
]);
})));
}

View File

@@ -84,7 +84,6 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
if (call.method == "new_remote_desktop") {
final args = jsonDecode(call.arguments);
final id = args['id'];
ConnectionTypeState.init(id);
window_on_top(windowId());
ConnectionTypeState.init(id);
tabController.add(TabInfo(

View File

@@ -555,11 +555,12 @@ class _CmControlPanel extends StatelessWidget {
final bool canElevate = bind.cmCanElevate();
final model = Provider.of<ServerModel>(context);
final showElevation = canElevate && model.showElevation;
final showAccept = model.approveMode != 'password';
return Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Offstage(
offstage: !showElevation,
offstage: !showElevation || !showAccept,
child: buildButton(context, color: Colors.green[700], onClick: () {
handleAccept(context);
handleElevate(context);
@@ -575,11 +576,17 @@ class _CmControlPanel extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: buildButton(context, color: MyTheme.accent, onClick: () {
handleAccept(context);
windowManager.minimize();
}, text: 'Accept', textColor: Colors.white)),
if (showAccept)
Expanded(
child: Column(
children: [
buildButton(context, color: MyTheme.accent, onClick: () {
handleAccept(context);
windowManager.minimize();
}, text: 'Accept', textColor: Colors.white),
],
),
),
Expanded(
child: buildButton(context,
color: Colors.transparent,
@@ -621,7 +628,7 @@ class _CmControlPanel extends StatelessWidget {
);
}
return Container(
height: 35,
height: 30,
decoration: BoxDecoration(
color: color, borderRadius: BorderRadius.circular(4), border: border),
child: InkWell(

View File

@@ -255,6 +255,9 @@ class FfiModel with ChangeNotifier {
} else if (type == 'restarting') {
showMsgBox(id, type, title, text, link, false, dialogManager,
hasCancel: false);
} else if (type == 'wait-remote-accept-nook') {
msgBoxCommon(dialogManager, title, Text(translate(text)),
[msgBoxButton("Cancel", closeConnection)]);
} else {
var hasRetry = evt['hasRetry'] == 'true';
showMsgBox(id, type, title, text, link, hasRetry, dialogManager);

View File

@@ -31,6 +31,7 @@ class ServerModel with ChangeNotifier {
int _connectStatus = 0; // Rendezvous Server status
String _verificationMethod = "";
String _temporaryPasswordLength = "";
String _approveMode = "";
late String _emptyIdShow;
late final IDTextEditingController _serverId;
@@ -68,6 +69,8 @@ class ServerModel with ChangeNotifier {
return _verificationMethod;
}
String get approveMode => _approveMode;
setVerificationMethod(String method) async {
await bind.mainSetOption(key: "verification-method", value: method);
}
@@ -84,6 +87,10 @@ class ServerModel with ChangeNotifier {
await bind.mainSetOption(key: "temporary-password-length", value: length);
}
setApproveMode(String mode) async {
await bind.mainSetOption(key: 'approve-mode', value: mode);
}
TextEditingController get serverId => _serverId;
TextEditingController get serverPasswd => _serverPasswd;
@@ -98,8 +105,7 @@ class ServerModel with ChangeNotifier {
_emptyIdShow = translate("Generating ...");
_serverId = IDTextEditingController(text: _emptyIdShow);
Timer.periodic(Duration(seconds: 1), (timer) async {
if (isTest) return timer.cancel();
timerCallback() async {
var status = await bind.mainGetOnlineStatue();
if (status > 0) {
status = 1;
@@ -115,7 +121,14 @@ class ServerModel with ChangeNotifier {
}
updatePasswordModel();
});
}
if (!isTest) {
Future.delayed(Duration.zero, timerCallback);
Timer.periodic(Duration(milliseconds: 500), (timer) async {
await timerCallback();
});
}
}
/// 1. check android permission
@@ -151,11 +164,17 @@ class ServerModel with ChangeNotifier {
await bind.mainGetOption(key: "verification-method");
final temporaryPasswordLength =
await bind.mainGetOption(key: "temporary-password-length");
final approveMode = await bind.mainGetOption(key: 'approve-mode');
if (_approveMode != approveMode) {
_approveMode = approveMode;
update = true;
}
final oldPwdText = _serverPasswd.text;
if (_serverPasswd.text != temporaryPassword) {
_serverPasswd.text = temporaryPassword;
}
if (verificationMethod == kUsePermanentPassword) {
if (verificationMethod == kUsePermanentPassword ||
_approveMode == 'click') {
_serverPasswd.text = '-';
}
if (oldPwdText != _serverPasswd.text) {