mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-01-31 21:34:45 +01:00
opt.: sensors
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:toolbox/core/extension/context/locale.dart';
|
||||
import 'package:toolbox/data/res/logger.dart';
|
||||
|
||||
final class SensorAdaptor {
|
||||
@@ -26,14 +27,28 @@ final class SensorAdaptor {
|
||||
final class SensorItem {
|
||||
final String device;
|
||||
final SensorAdaptor adapter;
|
||||
final String val;
|
||||
final Map<String, String> details;
|
||||
|
||||
const SensorItem({
|
||||
required this.device,
|
||||
required this.adapter,
|
||||
required this.val,
|
||||
required this.details,
|
||||
});
|
||||
|
||||
String get toMarkdown {
|
||||
final sb = StringBuffer();
|
||||
sb.writeln('| ${l10n.name} | ${l10n.content} |');
|
||||
sb.writeln('| --- | --- |');
|
||||
for (final entry in details.entries) {
|
||||
sb.writeln('| ${entry.key} | ${entry.value} |');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
String? get summary {
|
||||
return details.values.firstOrNull;
|
||||
}
|
||||
|
||||
static List<SensorItem> parse(String raw) {
|
||||
final eachSensorLines = <List<String>>[[]];
|
||||
final lines = raw.split('\n');
|
||||
@@ -60,13 +75,23 @@ final class SensorItem {
|
||||
final device = sensorLines.first;
|
||||
final adapter =
|
||||
SensorAdaptor.parse(sensorLines[1].split(':').last.trim());
|
||||
final line = sensorLines[2];
|
||||
final parts = line.split(':');
|
||||
if (parts.length < 2) {
|
||||
continue;
|
||||
|
||||
final details = <String, String>{};
|
||||
for (var idx = 2; idx < len; idx++) {
|
||||
final part = sensorLines[idx];
|
||||
final detailParts = part.split(':');
|
||||
if (detailParts.length < 2) {
|
||||
continue;
|
||||
}
|
||||
final key = detailParts[0].trim();
|
||||
final value = detailParts[1].trim();
|
||||
details[key] = value;
|
||||
}
|
||||
final val = parts[1].trim();
|
||||
sensors.add(SensorItem(device: device, adapter: adapter, val: val));
|
||||
sensors.add(SensorItem(
|
||||
device: device,
|
||||
adapter: adapter,
|
||||
details: details,
|
||||
));
|
||||
}
|
||||
|
||||
return sensors;
|
||||
|
||||
@@ -20,8 +20,8 @@ extension ServerX on Server {
|
||||
if (preferTempDev != null) {
|
||||
final preferTemp = status.sensors
|
||||
.firstWhereOrNull((e) => e.device == preferTempDev)
|
||||
?.val
|
||||
.split(' ')
|
||||
?.summary
|
||||
?.split(' ')
|
||||
.firstOrNull;
|
||||
if (preferTemp != null) {
|
||||
return double.tryParse(preferTemp.replaceFirst('°C', ''));
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 892;
|
||||
static const int build = 893;
|
||||
static const String engine = "3.19.6";
|
||||
static const String buildAt = "2024-05-10 12:55:39";
|
||||
static const int modifications = 3;
|
||||
static const int script = 46;
|
||||
static const String buildAt = "2024-05-10 20:57:55";
|
||||
static const int modifications = 8;
|
||||
static const int script = 47;
|
||||
}
|
||||
|
||||
@@ -71,5 +71,6 @@ abstract final class GithubIds {
|
||||
'pctoolsx',
|
||||
'pgs666',
|
||||
'FHU-yezi',
|
||||
'ZRY233',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:extended_image/extended_image.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:icons_plus/icons_plus.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:toolbox/core/extension/context/common.dart';
|
||||
@@ -21,6 +22,7 @@ import 'package:toolbox/data/model/server/system.dart';
|
||||
import 'package:toolbox/data/res/store.dart';
|
||||
import 'package:toolbox/view/widget/expand_tile.dart';
|
||||
import 'package:toolbox/view/widget/kv_row.dart';
|
||||
import 'package:toolbox/view/widget/markdown.dart';
|
||||
import 'package:toolbox/view/widget/server_func_btns.dart';
|
||||
import 'package:toolbox/view/widget/val_builder.dart';
|
||||
|
||||
@@ -755,22 +757,51 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
}
|
||||
|
||||
Widget _buildSensorItem(SensorItem si) {
|
||||
if (si.val.isEmpty) return UIs.placeholder;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 17, vertical: 7),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(si.device, style: UIs.text15Bold),
|
||||
const Spacer(),
|
||||
Text(si.adapter.raw, style: UIs.text13Grey),
|
||||
],
|
||||
if (si.summary == null) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 17, vertical: 7),
|
||||
child: Text(si.device),
|
||||
);
|
||||
}
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
context.showRoundDialog(
|
||||
title: Text(si.device),
|
||||
child: SingleChildScrollView(
|
||||
child: SimpleMarkdown(
|
||||
data: si.toMarkdown,
|
||||
styleSheet: MarkdownStyleSheet(
|
||||
tableBorder: TableBorder.all(color: Colors.grey),
|
||||
tableHead: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(si.val, style: UIs.text13Grey),
|
||||
],
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 17, vertical: 7),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(si.device, style: UIs.text15Bold),
|
||||
UIs.width7,
|
||||
Text('(${si.adapter.raw})', style: UIs.text13Grey),
|
||||
],
|
||||
),
|
||||
Text(si.summary ?? '', style: UIs.text13Grey),
|
||||
],
|
||||
)),
|
||||
UIs.width7,
|
||||
const Icon(Icons.keyboard_arrow_right, color: Colors.grey),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user