mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
opt. proj struct
This commit is contained in:
@@ -1,19 +1,3 @@
|
||||
get initOneTimeCpuStatus => OneTimeCpuStatus(
|
||||
'cpu',
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
);
|
||||
get initCpuStatus => CpuStatus(
|
||||
[initOneTimeCpuStatus],
|
||||
[initOneTimeCpuStatus],
|
||||
'',
|
||||
);
|
||||
|
||||
class CpuStatus {
|
||||
List<OneTimeCpuStatus> _pre;
|
||||
List<OneTimeCpuStatus> _now;
|
||||
@@ -107,3 +91,51 @@ class OneTimeCpuStatus {
|
||||
|
||||
int get total => user + sys + nice + idle + iowait + irq + softirq;
|
||||
}
|
||||
|
||||
List<OneTimeCpuStatus> parseCPU(String raw) {
|
||||
final List<OneTimeCpuStatus> cpus = [];
|
||||
|
||||
for (var item in raw.split('\n')) {
|
||||
if (item == '') break;
|
||||
final id = item.split(' ').first;
|
||||
final matches = item.replaceFirst(id, '').trim().split(' ');
|
||||
cpus.add(OneTimeCpuStatus(
|
||||
id,
|
||||
int.parse(matches[0]),
|
||||
int.parse(matches[1]),
|
||||
int.parse(matches[2]),
|
||||
int.parse(matches[3]),
|
||||
int.parse(matches[4]),
|
||||
int.parse(matches[5]),
|
||||
int.parse(matches[6])));
|
||||
}
|
||||
return cpus;
|
||||
}
|
||||
|
||||
final cpuTempReg = RegExp(r'(x86_pkg_temp|cpu_thermal)');
|
||||
|
||||
String parseCPUTemp(List<String> segments) {
|
||||
const noMatch = "/sys/class/thermal/thermal_zone*/type";
|
||||
final type = segments[0];
|
||||
final value = segments[1];
|
||||
// Not support to get CPU temperature
|
||||
if (value.contains(noMatch) ||
|
||||
type.contains(noMatch) ||
|
||||
value.isEmpty ||
|
||||
type.isEmpty) {
|
||||
return '';
|
||||
}
|
||||
final split = type.split('\n');
|
||||
int idx = 0;
|
||||
for (var item in split) {
|
||||
if (item.contains(cpuTempReg)) {
|
||||
break;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
final valueSplited = value.split('\n');
|
||||
if (idx >= valueSplited.length) return '';
|
||||
final temp = int.tryParse(valueSplited[idx].trim());
|
||||
if (temp == null) return '';
|
||||
return '${(temp / 1000).toStringAsFixed(1)}°C';
|
||||
}
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
get initMemory => Memory(
|
||||
total: 1,
|
||||
used: 0,
|
||||
free: 1,
|
||||
cache: 0,
|
||||
avail: 1,
|
||||
);
|
||||
|
||||
class Memory {
|
||||
int total;
|
||||
int used;
|
||||
@@ -19,3 +11,23 @@ class Memory {
|
||||
required this.cache,
|
||||
required this.avail});
|
||||
}
|
||||
|
||||
final memItemReg = RegExp(r'([A-Z].+:)\s+([0-9]+) kB');
|
||||
|
||||
Memory parseMem(String raw) {
|
||||
final items = raw.split('\n').map((e) => memItemReg.firstMatch(e)).toList();
|
||||
final total = int.parse(
|
||||
items.firstWhere((e) => e?.group(1) == 'MemTotal:')?.group(2) ?? '1');
|
||||
final free = int.parse(
|
||||
items.firstWhere((e) => e?.group(1) == 'MemFree:')?.group(2) ?? '0');
|
||||
final cached = int.parse(
|
||||
items.firstWhere((e) => e?.group(1) == 'Cached:')?.group(2) ?? '0');
|
||||
final available = int.parse(
|
||||
items.firstWhere((e) => e?.group(1) == 'MemAvailable:')?.group(2) ?? '0');
|
||||
return Memory(
|
||||
total: total,
|
||||
used: total - available,
|
||||
free: free,
|
||||
cache: cached,
|
||||
avail: available);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
import 'package:toolbox/core/extension/numx.dart';
|
||||
|
||||
get initNetSpeedPart => NetSpeedPart(
|
||||
'',
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
);
|
||||
get initNetSpeed => NetSpeed(
|
||||
[initNetSpeedPart],
|
||||
[initNetSpeedPart],
|
||||
);
|
||||
|
||||
class NetSpeedPart {
|
||||
String device;
|
||||
int bytesIn;
|
||||
@@ -69,3 +58,23 @@ class NetSpeed {
|
||||
String buildStandardOutput(double speed) =>
|
||||
'${speed.convertBytes.toLowerCase()}/s';
|
||||
}
|
||||
|
||||
List<NetSpeedPart> parseNetSpeed(String raw) {
|
||||
final split = raw.split('\n');
|
||||
if (split.length < 4) {
|
||||
return [];
|
||||
}
|
||||
|
||||
final time = int.parse(split[split.length - 1]);
|
||||
final results = <NetSpeedPart>[];
|
||||
for (final item in split.sublist(2, split.length - 1)) {
|
||||
final data = item.trim().split(':');
|
||||
final device = data.first;
|
||||
final bytes = data.last.trim().split(' ');
|
||||
bytes.removeWhere((element) => element == '');
|
||||
final bytesIn = int.parse(bytes.first);
|
||||
final bytesOut = int.parse(bytes[8]);
|
||||
results.add(NetSpeedPart(device, bytesIn, bytesOut, time));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -8,16 +8,6 @@ import 'package:toolbox/data/model/server/tcp_status.dart';
|
||||
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
|
||||
///
|
||||
|
||||
get initStatus => ServerStatus(
|
||||
initCpuStatus,
|
||||
initMemory,
|
||||
'Loading...',
|
||||
'',
|
||||
[DiskInfo('/', '/', 0, '0', '0', '0')],
|
||||
TcpStatus(0, 0, 0, 0),
|
||||
initNetSpeed,
|
||||
);
|
||||
|
||||
class ServerStatus {
|
||||
/*
|
||||
{
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import '../../../core/extension/stringx.dart';
|
||||
|
||||
///
|
||||
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
|
||||
///
|
||||
@@ -39,3 +41,16 @@ class TcpStatus {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
final numReg = RegExp(r'\s{1,}');
|
||||
|
||||
TcpStatus? parseTcp(String raw) {
|
||||
final lines = raw.split('\n');
|
||||
final idx = lines.lastWhere((element) => element.startsWith('Tcp:'),
|
||||
orElse: () => '');
|
||||
if (idx != '') {
|
||||
final vals = idx.split(numReg);
|
||||
return TcpStatus(vals[5].i, vals[6].i, vals[7].i, vals[8].i);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
26
lib/data/model/ssh/virtual_key.dart
Normal file
26
lib/data/model/ssh/virtual_key.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:xterm/core.dart';
|
||||
|
||||
class VirtualKey {
|
||||
final TerminalKey key;
|
||||
final String text;
|
||||
final bool toggleable;
|
||||
final IconData? icon;
|
||||
|
||||
VirtualKey(this.key, this.text, {this.toggleable = false, this.icon});
|
||||
}
|
||||
|
||||
var virtualKeys = [
|
||||
VirtualKey(TerminalKey.escape, 'Esc'),
|
||||
VirtualKey(TerminalKey.alt, 'Alt', toggleable: true),
|
||||
VirtualKey(TerminalKey.pageUp, 'PgUp'),
|
||||
VirtualKey(TerminalKey.arrowUp, 'Up', icon: Icons.arrow_upward),
|
||||
VirtualKey(TerminalKey.pageDown, 'PgDn'),
|
||||
VirtualKey(TerminalKey.end, 'End'),
|
||||
VirtualKey(TerminalKey.tab, 'Tab'),
|
||||
VirtualKey(TerminalKey.control, 'Ctrl', toggleable: true),
|
||||
VirtualKey(TerminalKey.arrowLeft, 'Left', icon: Icons.arrow_back),
|
||||
VirtualKey(TerminalKey.arrowDown, 'Down', icon: Icons.arrow_downward),
|
||||
VirtualKey(TerminalKey.arrowRight, 'Right', icon: Icons.arrow_forward),
|
||||
VirtualKey(TerminalKey.home, 'Home'),
|
||||
];
|
||||
Reference in New Issue
Block a user