mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
feat: manually close conn
This commit is contained in:
@@ -37,6 +37,8 @@ class ServerProvider extends ChangeNotifier {
|
|||||||
|
|
||||||
Timer? _timer;
|
Timer? _timer;
|
||||||
|
|
||||||
|
final _manualDisconnectedIds = <String>{};
|
||||||
|
|
||||||
Future<void> load() async {
|
Future<void> load() async {
|
||||||
// Issue #147
|
// Issue #147
|
||||||
// Clear all servers because of restarting app will cause duplicate servers
|
// Clear all servers because of restarting app will cause duplicate servers
|
||||||
@@ -139,13 +141,9 @@ class ServerProvider extends ChangeNotifier {
|
|||||||
TryLimiter.reset(s.spi.id);
|
TryLimiter.reset(s.spi.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If [spi.autoConnect] is false and server is disconnected, then skip.
|
if (!(s.spi.autoConnect ?? true) &&
|
||||||
///
|
s.conn == ServerConn.disconnected ||
|
||||||
/// If [spi.autoConnect] is false and server is connected, then refresh.
|
_manualDisconnectedIds.contains(s.spi.id)) {
|
||||||
/// If no this, the server will only refresh once by clicking refresh button.
|
|
||||||
///
|
|
||||||
/// If [spi.autoConnect] is true, then refresh.
|
|
||||||
if (!(s.spi.autoConnect ?? true) && s.conn == ServerConn.disconnected) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return await _getData(s.spi);
|
return await _getData(s.spi);
|
||||||
@@ -192,8 +190,12 @@ class ServerProvider extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _closeOneServer(String id) {
|
void _closeOneServer(String id) {
|
||||||
_servers[id]?.client?.close();
|
final item = _servers[id];
|
||||||
_servers[id]?.client = null;
|
item?.client?.close();
|
||||||
|
item?.client = null;
|
||||||
|
item?.conn = ServerConn.disconnected;
|
||||||
|
_manualDisconnectedIds.add(id);
|
||||||
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void addServer(ServerPrivateInfo spi) {
|
void addServer(ServerPrivateInfo spi) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'dart:math' as math;
|
|||||||
import 'package:after_layout/after_layout.dart';
|
import 'package:after_layout/after_layout.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get_it/get_it.dart';
|
import 'package:get_it/get_it.dart';
|
||||||
|
import 'package:icons_plus/icons_plus.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:toolbox/core/extension/context/common.dart';
|
import 'package:toolbox/core/extension/context/common.dart';
|
||||||
import 'package:toolbox/core/extension/context/dialog.dart';
|
import 'package:toolbox/core/extension/context/dialog.dart';
|
||||||
@@ -19,6 +20,7 @@ import 'package:toolbox/data/res/color.dart';
|
|||||||
import 'package:toolbox/data/res/provider.dart';
|
import 'package:toolbox/data/res/provider.dart';
|
||||||
import 'package:toolbox/data/res/store.dart';
|
import 'package:toolbox/data/res/store.dart';
|
||||||
import 'package:toolbox/view/widget/auto_hide.dart';
|
import 'package:toolbox/view/widget/auto_hide.dart';
|
||||||
|
import 'package:toolbox/view/widget/icon_text_btn.dart';
|
||||||
import 'package:toolbox/view/widget/markdown.dart';
|
import 'package:toolbox/view/widget/markdown.dart';
|
||||||
import 'package:toolbox/view/widget/percent_circle.dart';
|
import 'package:toolbox/view/widget/percent_circle.dart';
|
||||||
|
|
||||||
@@ -350,7 +352,7 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconTextBtn(
|
||||||
onPressed: () => _askFor(
|
onPressed: () => _askFor(
|
||||||
func: () async {
|
func: () async {
|
||||||
if (Stores.setting.showSuspendTip.fetch()) {
|
if (Stores.setting.showSuspendTip.fetch()) {
|
||||||
@@ -369,10 +371,10 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
typ: l10n.suspend,
|
typ: l10n.suspend,
|
||||||
name: srv.spi.name,
|
name: srv.spi.name,
|
||||||
),
|
),
|
||||||
icon: const Icon(Icons.stop),
|
icon: Icons.stop,
|
||||||
tooltip: l10n.suspend,
|
text: l10n.suspend,
|
||||||
),
|
),
|
||||||
IconButton(
|
IconTextBtn(
|
||||||
onPressed: () => _askFor(
|
onPressed: () => _askFor(
|
||||||
func: () => srv.client?.execWithPwd(
|
func: () => srv.client?.execWithPwd(
|
||||||
ShellFunc.shutdown.exec,
|
ShellFunc.shutdown.exec,
|
||||||
@@ -382,10 +384,10 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
typ: l10n.shutdown,
|
typ: l10n.shutdown,
|
||||||
name: srv.spi.name,
|
name: srv.spi.name,
|
||||||
),
|
),
|
||||||
icon: const Icon(Icons.power_off),
|
icon: Icons.power_off,
|
||||||
tooltip: l10n.shutdown,
|
text: l10n.shutdown,
|
||||||
),
|
),
|
||||||
IconButton(
|
IconTextBtn(
|
||||||
onPressed: () => _askFor(
|
onPressed: () => _askFor(
|
||||||
func: () => srv.client?.execWithPwd(
|
func: () => srv.client?.execWithPwd(
|
||||||
ShellFunc.reboot.exec,
|
ShellFunc.reboot.exec,
|
||||||
@@ -395,13 +397,13 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
typ: l10n.reboot,
|
typ: l10n.reboot,
|
||||||
name: srv.spi.name,
|
name: srv.spi.name,
|
||||||
),
|
),
|
||||||
icon: const Icon(Icons.restart_alt),
|
icon: Icons.restart_alt,
|
||||||
tooltip: l10n.reboot,
|
text: l10n.reboot,
|
||||||
),
|
),
|
||||||
IconButton(
|
IconTextBtn(
|
||||||
onPressed: () => AppRoute.serverEdit(spi: srv.spi).go(context),
|
onPressed: () => AppRoute.serverEdit(spi: srv.spi).go(context),
|
||||||
icon: const Icon(Icons.edit),
|
icon: Icons.edit,
|
||||||
tooltip: l10n.edit,
|
text: l10n.edit,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@@ -468,7 +470,7 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
ServerConn.loading ||
|
ServerConn.loading ||
|
||||||
ServerConn.connected =>
|
ServerConn.connected =>
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 7),
|
padding: const EdgeInsets.only(left: 11, right: 3),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 19,
|
width: 19,
|
||||||
height: 19,
|
height: 19,
|
||||||
@@ -484,7 +486,7 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
Pros.server.refresh(spi: s.spi);
|
Pros.server.refresh(spi: s.spi);
|
||||||
},
|
},
|
||||||
child: const Padding(
|
child: const Padding(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 7),
|
padding: EdgeInsets.only(left: 11, right: 3),
|
||||||
child: Icon(
|
child: Icon(
|
||||||
Icons.refresh,
|
Icons.refresh,
|
||||||
size: 21,
|
size: 21,
|
||||||
@@ -492,20 +494,30 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ServerConn.disconnected when !(s.spi.autoConnect ?? true) => InkWell(
|
ServerConn.disconnected => InkWell(
|
||||||
onTap: () => Pros.server.refresh(spi: s.spi),
|
onTap: () => Pros.server.refresh(spi: s.spi),
|
||||||
child: const Padding(
|
child: const Padding(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 7),
|
padding: EdgeInsets.only(left: 11, right: 3),
|
||||||
child: Icon(
|
child: Icon(
|
||||||
Icons.link,
|
BoxIcons.bx_link,
|
||||||
size: 21,
|
size: 21,
|
||||||
color: Colors.grey,
|
color: Colors.grey,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
ServerConn.finished => InkWell(
|
||||||
|
onTap: () => Pros.server.closeServer(id: s.spi.id),
|
||||||
|
child: const Padding(
|
||||||
|
padding: EdgeInsets.only(left: 11, right: 3),
|
||||||
|
child: Icon(
|
||||||
|
BoxIcons.bx_unlink,
|
||||||
|
size: 17,
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
_ when Stores.setting.serverTabUseOldUI.fetch() =>
|
_ when Stores.setting.serverTabUseOldUI.fetch() =>
|
||||||
ServerFuncBtnsTopRight(spi: s.spi),
|
ServerFuncBtnsTopRight(spi: s.spi),
|
||||||
_ => UIs.placeholder,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -648,7 +660,7 @@ ${ss.err?.message ?? l10n.unknownError}
|
|||||||
return 23.0;
|
return 23.0;
|
||||||
}
|
}
|
||||||
if (flip) {
|
if (flip) {
|
||||||
return 80.0;
|
return 97.0;
|
||||||
}
|
}
|
||||||
if (Stores.setting.moveOutServerTabFuncBtns.fetch() &&
|
if (Stores.setting.moveOutServerTabFuncBtns.fetch() &&
|
||||||
// Discussion #146
|
// Discussion #146
|
||||||
|
|||||||
38
lib/view/widget/icon_text_btn.dart
Normal file
38
lib/view/widget/icon_text_btn.dart
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:toolbox/data/res/ui.dart';
|
||||||
|
|
||||||
|
final class IconTextBtn extends StatelessWidget {
|
||||||
|
final String text;
|
||||||
|
final IconData icon;
|
||||||
|
final VoidCallback? onPressed;
|
||||||
|
final Orientation orientation;
|
||||||
|
|
||||||
|
const IconTextBtn({
|
||||||
|
super.key,
|
||||||
|
required this.text,
|
||||||
|
required this.icon,
|
||||||
|
this.onPressed,
|
||||||
|
this.orientation = Orientation.portrait,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return IconButton(
|
||||||
|
onPressed: onPressed,
|
||||||
|
tooltip: text,
|
||||||
|
icon: orientation == Orientation.landscape ? Row(
|
||||||
|
children: [
|
||||||
|
Icon(icon),
|
||||||
|
UIs.width7,
|
||||||
|
Text(text, style: UIs.text13Grey),
|
||||||
|
],
|
||||||
|
) : Column(
|
||||||
|
children: [
|
||||||
|
Icon(icon),
|
||||||
|
UIs.height7,
|
||||||
|
Text(text, style: UIs.text13Grey),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user