opt.
This commit is contained in:
@@ -47,7 +47,7 @@ class _DockerManagePageState extends State<DockerManagePage> {
|
||||
super.initState();
|
||||
final client = locator<ServerProvider>()
|
||||
.servers
|
||||
.firstWhere((element) => element.info == widget.spi)
|
||||
.firstWhere((element) => element.spi == widget.spi)
|
||||
.client;
|
||||
if (client == null) {
|
||||
showSnackBar(context, Text(_s.noClient));
|
||||
|
||||
@@ -188,9 +188,9 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
ListTile(
|
||||
leading: const Icon(Icons.vpn_key),
|
||||
title: Text(_s.privateKey),
|
||||
onTap: () => AppRoute(
|
||||
const StoredPrivateKeysPage(), 'private key list')
|
||||
.go(context),
|
||||
onTap: () =>
|
||||
AppRoute(const PrivateKeysListPage(), 'private key list')
|
||||
.go(context),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.download),
|
||||
|
||||
@@ -153,7 +153,7 @@ class _PingPageState extends State<PingPage>
|
||||
return;
|
||||
}
|
||||
final result = await e.client!.run('ping -c 3 $target').string;
|
||||
_results.add(PingResult.parse(e.info.name, result));
|
||||
_results.add(PingResult.parse(e.spi.name, result));
|
||||
setState(() {});
|
||||
}));
|
||||
} catch (e) {
|
||||
|
||||
@@ -51,7 +51,7 @@ class _PkgManagePageState extends State<PkgManagePage>
|
||||
super.initState();
|
||||
final si = locator<ServerProvider>()
|
||||
.servers
|
||||
.firstWhere((e) => e.info == widget.spi);
|
||||
.firstWhere((e) => e.spi == widget.spi);
|
||||
if (si.client == null) {
|
||||
showSnackBar(context, Text(_s.waitConnection));
|
||||
Navigator.of(context).pop();
|
||||
|
||||
@@ -7,14 +7,14 @@ import 'package:toolbox/generated/l10n.dart';
|
||||
import 'package:toolbox/view/page/private_key/edit.dart';
|
||||
import 'package:toolbox/view/widget/round_rect_card.dart';
|
||||
|
||||
class StoredPrivateKeysPage extends StatefulWidget {
|
||||
const StoredPrivateKeysPage({Key? key}) : super(key: key);
|
||||
class PrivateKeysListPage extends StatefulWidget {
|
||||
const PrivateKeysListPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_PrivateKeyListState createState() => _PrivateKeyListState();
|
||||
}
|
||||
|
||||
class _PrivateKeyListState extends State<StoredPrivateKeysPage> {
|
||||
class _PrivateKeyListState extends State<PrivateKeysListPage> {
|
||||
late S _s;
|
||||
|
||||
@override
|
||||
|
||||
@@ -14,6 +14,8 @@ import 'package:toolbox/generated/l10n.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
import 'package:toolbox/view/widget/round_rect_card.dart';
|
||||
|
||||
import '../../../data/res/sizedbox.dart';
|
||||
|
||||
class ServerDetailPage extends StatefulWidget {
|
||||
const ServerDetailPage(this.id, {Key? key}) : super(key: key);
|
||||
|
||||
@@ -23,10 +25,6 @@ class ServerDetailPage extends StatefulWidget {
|
||||
_ServerDetailPageState createState() => _ServerDetailPageState();
|
||||
}
|
||||
|
||||
const width13 = SizedBox(
|
||||
width: 13,
|
||||
);
|
||||
|
||||
class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late MediaQueryData _media;
|
||||
@@ -48,16 +46,16 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
return Consumer<ServerProvider>(builder: (_, provider, __) {
|
||||
return _buildMainPage(
|
||||
provider.servers.firstWhere(
|
||||
(e) => '${e.info.ip}:${e.info.port}' == widget.id,
|
||||
(e) => e.spi.id == widget.id,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildMainPage(ServerInfo si) {
|
||||
Widget _buildMainPage(Server si) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(si.info.name, style: textSize18),
|
||||
title: Text(si.spi.name, style: textSize18),
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(13),
|
||||
@@ -96,10 +94,10 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
}
|
||||
|
||||
Widget _buildCPUView(ServerStatus ss) {
|
||||
final tempWidget = ss.cpu2Status.temp.isEmpty
|
||||
final tempWidget = ss.cpu.temp.isEmpty
|
||||
? const SizedBox()
|
||||
: Text(
|
||||
ss.cpu2Status.temp,
|
||||
ss.cpu.temp,
|
||||
style: textSize13Grey,
|
||||
);
|
||||
return RoundRectCard(
|
||||
@@ -112,7 +110,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'${ss.cpu2Status.usedPercent(coreIdx: 0).toInt()}%',
|
||||
'${ss.cpu.usedPercent(coreIdx: 0).toInt()}%',
|
||||
style: textSize27,
|
||||
textScaleFactor: 1.0,
|
||||
),
|
||||
@@ -121,17 +119,18 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
_buildDetailPercent(ss.cpu2Status.user, 'user'),
|
||||
_buildDetailPercent(ss.cpu.user, 'user'),
|
||||
width13,
|
||||
_buildDetailPercent(ss.cpu2Status.sys, 'sys'),
|
||||
_buildDetailPercent(ss.cpu.sys, 'sys'),
|
||||
width13,
|
||||
_buildDetailPercent(ss.cpu2Status.iowait, 'io'),
|
||||
_buildDetailPercent(ss.cpu.iowait, 'io'),
|
||||
width13,
|
||||
_buildDetailPercent(ss.cpu2Status.idle, 'idle')
|
||||
_buildDetailPercent(ss.cpu.idle, 'idle')
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
height13,
|
||||
_buildCPUProgress(ss)
|
||||
]),
|
||||
),
|
||||
@@ -159,21 +158,17 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
}
|
||||
|
||||
Widget _buildCPUProgress(ServerStatus ss) {
|
||||
return SizedBox(
|
||||
height: 12.0 * ss.cpu2Status.coresCount,
|
||||
child: ListView.builder(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.only(top: 13),
|
||||
itemBuilder: (ctx, idx) {
|
||||
if (idx == 0) return const SizedBox();
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: _buildProgress(ss.cpu2Status.usedPercent(coreIdx: idx)),
|
||||
);
|
||||
},
|
||||
itemCount: ss.cpu2Status.coresCount,
|
||||
),
|
||||
);
|
||||
final children = <Widget>[];
|
||||
for (var i = 0; i < ss.cpu.coresCount; i++) {
|
||||
if (i == 0) continue;
|
||||
children.add(
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: _buildProgress(ss.cpu.usedPercent(coreIdx: i)),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Column(children: children);
|
||||
}
|
||||
|
||||
Widget _buildProgress(double percent) {
|
||||
@@ -188,72 +183,76 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
}
|
||||
|
||||
Widget _buildUpTimeAndSys(ServerStatus ss) {
|
||||
return RoundRectCard(Padding(
|
||||
padding: roundRectCardPadding,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(ss.sysVer, style: textSize11, textScaleFactor: 1.0),
|
||||
Text(
|
||||
ss.uptime,
|
||||
style: textSize11,
|
||||
textScaleFactor: 1.0,
|
||||
),
|
||||
],
|
||||
return RoundRectCard(
|
||||
Padding(
|
||||
padding: roundRectCardPadding,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(ss.sysVer, style: textSize11, textScaleFactor: 1.0),
|
||||
Text(
|
||||
ss.uptime,
|
||||
style: textSize11,
|
||||
textScaleFactor: 1.0,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMemView(ServerStatus ss) {
|
||||
final used = ss.memory.used / ss.memory.total * 100;
|
||||
final free = ss.memory.free / ss.memory.total * 100;
|
||||
final avail = ss.memory.avail / ss.memory.total * 100;
|
||||
final used = ss.mem.used / ss.mem.total * 100;
|
||||
final free = ss.mem.free / ss.mem.total * 100;
|
||||
final avail = ss.mem.avail / ss.mem.total * 100;
|
||||
|
||||
return RoundRectCard(Padding(
|
||||
padding: roundRectCardPadding,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text('${used.toStringAsFixed(0)}%', style: textSize27),
|
||||
const SizedBox(width: 7),
|
||||
Text('of ${(ss.memory.total * 1024).convertBytes}',
|
||||
style: textSize13Grey)
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
_buildDetailPercent(free, 'free'),
|
||||
width13,
|
||||
_buildDetailPercent(avail, 'avail'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 11,
|
||||
),
|
||||
_buildProgress(used)
|
||||
],
|
||||
return RoundRectCard(
|
||||
Padding(
|
||||
padding: roundRectCardPadding,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text('${used.toStringAsFixed(0)}%', style: textSize27),
|
||||
const SizedBox(width: 7),
|
||||
Text('of ${(ss.mem.total * 1024).convertBytes}',
|
||||
style: textSize13Grey)
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
_buildDetailPercent(free, 'free'),
|
||||
width13,
|
||||
_buildDetailPercent(avail, 'avail'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 11,
|
||||
),
|
||||
_buildProgress(used)
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDiskView(ServerStatus ss) {
|
||||
final clone = ss.disk.toList();
|
||||
for (var item in ss.disk) {
|
||||
if (ignorePath.any((ele) => item.mountLocation.contains(ele))) {
|
||||
if (ignorePath.any((ele) => item.loc.contains(ele))) {
|
||||
clone.remove(item);
|
||||
}
|
||||
}
|
||||
final children = clone
|
||||
.map((disk) => Padding(
|
||||
padding: const EdgeInsets.all(3),
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
@@ -265,8 +264,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
style: textSize11,
|
||||
textScaleFactor: 1.0,
|
||||
),
|
||||
Text(disk.mountPath,
|
||||
style: textSize11, textScaleFactor: 1.0)
|
||||
Text(disk.path, style: textSize11, textScaleFactor: 1.0)
|
||||
],
|
||||
),
|
||||
_buildProgress(disk.usedPercent.toDouble())
|
||||
@@ -274,13 +272,15 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
),
|
||||
))
|
||||
.toList();
|
||||
return RoundRectCard(Padding(
|
||||
padding: roundRectCardPadding,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: children,
|
||||
return RoundRectCard(
|
||||
Padding(
|
||||
padding: roundRectCardPadding,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: children,
|
||||
),
|
||||
),
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNetView(NetSpeed ns) {
|
||||
@@ -301,17 +301,19 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
children.addAll(ns.devices.map((e) => _buildNetSpeedItem(ns, e)));
|
||||
}
|
||||
|
||||
return RoundRectCard(Padding(
|
||||
padding: roundRectCardPadding,
|
||||
child: Column(
|
||||
children: children,
|
||||
return RoundRectCard(
|
||||
Padding(
|
||||
padding: roundRectCardPadding,
|
||||
child: Column(
|
||||
children: children,
|
||||
),
|
||||
),
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNetSpeedTop() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
padding: const EdgeInsets.only(bottom: 3),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: const [
|
||||
|
||||
@@ -100,22 +100,20 @@ class _ServerPageState extends State<ServerPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEachServerCard(ServerInfo si) {
|
||||
Widget _buildEachServerCard(Server si) {
|
||||
return RoundRectCard(
|
||||
InkWell(
|
||||
onLongPress: () => AppRoute(
|
||||
ServerEditPage(
|
||||
spi: si.info,
|
||||
spi: si.spi,
|
||||
),
|
||||
'Edit server info page')
|
||||
.go(context),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(13),
|
||||
child: _buildRealServerCard(
|
||||
si.status, si.info.name, si.connectionState, si.info),
|
||||
child: _buildRealServerCard(si.status, si.spi.name, si.cs, si.spi),
|
||||
),
|
||||
onTap: () => AppRoute(ServerDetailPage('${si.info.ip}:${si.info.port}'),
|
||||
'server detail page')
|
||||
onTap: () => AppRoute(ServerDetailPage(si.spi.id), 'server detail page')
|
||||
.go(context),
|
||||
),
|
||||
);
|
||||
@@ -123,11 +121,10 @@ class _ServerPageState extends State<ServerPage>
|
||||
|
||||
Widget _buildRealServerCard(ServerStatus ss, String serverName,
|
||||
ServerConnectionState cs, ServerPrivateInfo spi) {
|
||||
final rootDisk =
|
||||
ss.disk.firstWhere((element) => element.mountLocation == '/');
|
||||
final rootDisk = ss.disk.firstWhere((element) => element.loc == '/');
|
||||
|
||||
final topRightStr =
|
||||
getTopRightStr(cs, ss.cpu2Status.temp, ss.uptime, ss.failedInfo);
|
||||
getTopRightStr(cs, ss.cpu.temp, ss.uptime, ss.failedInfo);
|
||||
final hasError =
|
||||
cs == ServerConnectionState.failed && ss.failedInfo != null;
|
||||
final style = TextStyle(
|
||||
@@ -178,8 +175,8 @@ class _ServerPageState extends State<ServerPage>
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_buildPercentCircle(ss.cpu2Status.usedPercent()),
|
||||
_buildPercentCircle(ss.memory.used / ss.memory.total * 100),
|
||||
_buildPercentCircle(ss.cpu.usedPercent()),
|
||||
_buildPercentCircle(ss.mem.used / ss.mem.total * 100),
|
||||
_buildIOData('Conn:\n${ss.tcp.maxConn}', 'Fail:\n${ss.tcp.fail}'),
|
||||
_buildIOData(
|
||||
'Total:\n${rootDisk.size}', 'Used:\n${rootDisk.usedPercent}%')
|
||||
|
||||
@@ -37,7 +37,7 @@ class _SFTPPageState extends State<SFTPPage> {
|
||||
late MediaQueryData _media;
|
||||
late S _s;
|
||||
|
||||
ServerInfo? _si;
|
||||
Server? _si;
|
||||
SSHClient? _client;
|
||||
|
||||
@override
|
||||
@@ -51,7 +51,7 @@ class _SFTPPageState extends State<SFTPPage> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
final serverProvider = locator<ServerProvider>();
|
||||
_si = serverProvider.servers.firstWhere((s) => s.info == widget.spi);
|
||||
_si = serverProvider.servers.firstWhere((s) => s.spi == widget.spi);
|
||||
_client = _si?.client;
|
||||
}
|
||||
|
||||
@@ -175,8 +175,7 @@ class _SFTPPageState extends State<SFTPPage> {
|
||||
);
|
||||
|
||||
Widget _buildFileView() {
|
||||
if (_client == null ||
|
||||
_si?.connectionState != ServerConnectionState.connected) {
|
||||
if (_client == null || _si?.cs != ServerConnectionState.connected) {
|
||||
return centerCircleLoading;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class _SSHPageState extends State<SSHPage> {
|
||||
|
||||
final client = locator<ServerProvider>()
|
||||
.servers
|
||||
.where((e) => e.info.id == widget.spi.id)
|
||||
.where((e) => e.spi.id == widget.spi.id)
|
||||
.first
|
||||
.client;
|
||||
if (client == null) {
|
||||
|
||||
Reference in New Issue
Block a user