#155 new: option autoConnect

This commit is contained in:
lollipopkit
2023-09-05 21:14:39 +08:00
parent e32f7536b5
commit 191ffe0173
18 changed files with 142 additions and 66 deletions

View File

@@ -44,7 +44,8 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
late ServerProvider _serverProvider;
late S _s;
bool usePublicKey = false;
final usePublicKey = ValueNotifier(false);
final autoConnect = ValueNotifier(true);
int? _pubKeyIndex;
PrivateKeyInfo? _keyInfo;
List<String> _tags = [];
@@ -178,13 +179,24 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
Text(_s.keyAuth),
width13,
Switch(
value: usePublicKey,
onChanged: (val) => setState(() => usePublicKey = val),
value: usePublicKey.value,
onChanged: (val) => setState(() => usePublicKey.value = val),
),
],
),
Row(
children: [
width13,
Text(_s.autoConnect),
width13,
Switch(
value: autoConnect.value,
onChanged: (val) => setState(() => autoConnect.value = val),
),
],
)
];
if (usePublicKey) {
if (usePublicKey.value) {
children.add(_buildKeyAuth());
} else {
children.add(Input(
@@ -254,7 +266,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
showSnackBar(context, Text(_s.plzEnterHost));
return;
}
if (!usePublicKey && _passwordController.text == '') {
if (!usePublicKey.value && _passwordController.text == '') {
final cancel = await showRoundDialog<bool>(
context: context,
title: Text(_s.attention),
@@ -274,7 +286,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
return;
}
}
if (usePublicKey && _pubKeyIndex == -1) {
if (usePublicKey.value && _pubKeyIndex == -1) {
showSnackBar(context, Text(_s.plzSelectKey));
return;
}
@@ -296,10 +308,11 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
port: int.parse(_portController.text),
user: _usernameController.text,
pwd: authorization,
pubKeyId: usePublicKey ? _keyInfo!.id : null,
pubKeyId: usePublicKey.value ? _keyInfo!.id : null,
tags: _tags,
alterUrl:
_alterUrlController.text == '' ? null : _alterUrlController.text,
autoConnect: autoConnect.value,
);
if (widget.spi == null) {
@@ -336,12 +349,13 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
if (widget.spi?.pubKeyId == null) {
_passwordController.text = widget.spi?.pwd ?? '';
} else {
usePublicKey = true;
usePublicKey.value = true;
}
if (widget.spi?.tags != null) {
_tags = widget.spi!.tags!;
}
_alterUrlController.text = widget.spi?.alterUrl ?? '';
autoConnect.value = widget.spi?.autoConnect ?? true;
setState(() {});
}
}

View File

@@ -193,13 +193,19 @@ class _ServerPageState extends State<ServerPage>
_showFailReason(si.status);
}
},
onLongPress: () => setState(() {
if (_flipedCardIds.contains(si.spi.id)) {
_flipedCardIds.remove(si.spi.id);
onLongPress: () {
if (si.state == ServerState.finished) {
setState(() {
if (_flipedCardIds.contains(si.spi.id)) {
_flipedCardIds.remove(si.spi.id);
} else {
_flipedCardIds.add(si.spi.id);
}
});
} else {
_flipedCardIds.add(si.spi.id);
AppRoute.serverEdit(spi: si.spi).go(context);
}
}),
},
child: Padding(
padding: const EdgeInsets.all(13),
child: _buildRealServerCard(si),
@@ -221,10 +227,12 @@ class _ServerPageState extends State<ServerPage>
final title = _buildServerCardTitle(srv.status, srv.state, srv.spi);
final List<Widget> children = [title];
if (_flipedCardIds.contains(srv.spi.id)) {
children.addAll(_buildFlipedCard(srv));
} else if (srv.state == ServerState.finished) {
children.addAll(_buildNormalCard(srv.status, srv.spi));
if (srv.state == ServerState.finished) {
if (_flipedCardIds.contains(srv.spi.id)) {
children.addAll(_buildFlipedCard(srv));
} else {
children.addAll(_buildNormalCard(srv.status, srv.spi));
}
}
return AnimatedContainer(
@@ -304,6 +312,22 @@ class _ServerPageState extends State<ServerPage>
ServerState cs,
ServerPrivateInfo spi,
) {
Widget? rightCorner;
if (!(spi.autoConnect ?? true) && cs == ServerState.disconnected) {
rightCorner = InkWell(
onTap: () => _serverProvider.refreshData(spi: spi),
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 7),
child: Icon(
Icons.link,
size: 21,
color: Colors.grey,
),
),
);
} else if (_settingStore.serverTabUseOldUI.fetch()) {
rightCorner = ServerFuncBtnsTopRight(spi: spi, s: _s);
}
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 7),
child: Row(
@@ -326,8 +350,7 @@ class _ServerPageState extends State<ServerPage>
Row(
children: [
_buildTopRightText(ss, cs),
if (_settingStore.serverTabUseOldUI.fetch())
ServerFuncBtnsTopRight(spi: spi, s: _s)
if (rightCorner != null) rightCorner,
],
)
],
@@ -489,12 +512,12 @@ class _ServerPageState extends State<ServerPage>
}
double _calcCardHeight(ServerState cs, String id) {
if (_flipedCardIds.contains(id)) {
return 77.0;
}
if (cs != ServerState.finished) {
return 23.0;
}
if (_flipedCardIds.contains(id)) {
return 77.0;
}
if (_settingStore.moveOutServerTabFuncBtns.fetch() &&
// Discussion #146
!_settingStore.serverTabUseOldUI.fetch()) {