mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 15:24:35 +01:00
new: prefer temperature device (#285)
This commit is contained in:
@@ -2,6 +2,7 @@ import 'dart:convert';
|
||||
|
||||
import 'package:toolbox/core/extension/listx.dart';
|
||||
import 'package:toolbox/data/res/logger.dart';
|
||||
import 'package:toolbox/data/res/store.dart';
|
||||
|
||||
final class SensorAdaptor {
|
||||
final String raw;
|
||||
@@ -101,6 +102,22 @@ final class SensorItem {
|
||||
return items;
|
||||
}
|
||||
|
||||
static double? findPreferTempVal(List<SensorItem> items) {
|
||||
if (items.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
final preferTemperatureDevs = Stores.setting.preferTemperatureDevs.fetch();
|
||||
if (preferTemperatureDevs.isNotEmpty) {
|
||||
for (final key in preferTemperatureDevs) {
|
||||
final item = items.firstWhereOrNull((e) => e.device == key);
|
||||
if (item != null) {
|
||||
return item.props.values.firstOrNull?.current;
|
||||
}
|
||||
}
|
||||
}
|
||||
return items.first.props.values.firstOrNull?.current;
|
||||
}
|
||||
|
||||
static const sensorsRaw = '''
|
||||
{
|
||||
"coretemp-isa-0000":{
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:toolbox/data/res/store.dart';
|
||||
|
||||
class Temperatures {
|
||||
final Map<String, double> _map = {};
|
||||
|
||||
@@ -35,8 +37,16 @@ class Temperatures {
|
||||
if (_map.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
for (final key in _map.keys) {
|
||||
if (cpuTempReg.hasMatch(key)) {
|
||||
final preferTemperatureDevs = Stores.setting.preferTemperatureDevs.fetch();
|
||||
if (preferTemperatureDevs.isNotEmpty) {
|
||||
for (final key in preferTemperatureDevs) {
|
||||
if (_map.containsKey(key)) {
|
||||
return _map[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final key in _cpuTemp) {
|
||||
if (_map.containsKey(key)) {
|
||||
return _map[key];
|
||||
}
|
||||
}
|
||||
@@ -45,5 +55,5 @@ class Temperatures {
|
||||
}
|
||||
|
||||
/// soc: mobile phone
|
||||
/// cpu_thermal / x86_pkg_temp: x86
|
||||
final cpuTempReg = RegExp(r'(x86_pkg_temp|cpu_thermal|soc)');
|
||||
/// cpu_thermal / x86_pkg_temp / coretemp / zenpower: x86
|
||||
const _cpuTemp = ['x86_pkg_temp', 'coretemp', 'zenpower', 'cpu_thermal', 'soc'];
|
||||
|
||||
@@ -239,6 +239,13 @@ class SettingStore extends PersistentStore {
|
||||
/// Auto refresh container status
|
||||
late final contaienrAutoRefresh = property('contaienrAutoRefresh', true);
|
||||
|
||||
/// eg:
|
||||
/// Available devices: ['iwlwifi','x86pkg_temp']
|
||||
/// Prefer list: ['x86pkg_temp','example']
|
||||
/// Result: use x86pkg_temp's temperature as the temperature
|
||||
late final preferTemperatureDevs =
|
||||
listProperty('preferTemperatureDevs', <String>[]);
|
||||
|
||||
// Never show these settings for users
|
||||
//
|
||||
// ------BEGIN------
|
||||
|
||||
@@ -178,6 +178,8 @@
|
||||
"plzEnterHost": "Bitte Host eingeben.",
|
||||
"plzSelectKey": "Wähle einen Key.",
|
||||
"port": "Port",
|
||||
"preferTemperatureDeviceList": "Liste mit Priorität für die Anzeige der Temperatur",
|
||||
"preferTemperatureDeviceListTip": "Zum Beispiel: Geräte, die die Anzeige der Temperatur unterstützen, sind ['a', 'b'], diese Einstellung ist ['b', 'c'], daher wird die Temperatur des Geräts b angezeigt",
|
||||
"preview": "Vorschau",
|
||||
"primaryColorSeed": "Farbschema",
|
||||
"privateKey": "Private Key",
|
||||
|
||||
@@ -178,6 +178,8 @@
|
||||
"plzEnterHost": "Please enter host.",
|
||||
"plzSelectKey": "Please select a key.",
|
||||
"port": "Port",
|
||||
"preferTemperatureDeviceList": "List prioritizing the display of temperature",
|
||||
"preferTemperatureDeviceListTip": "For example: Devices supporting temperature display include ['a', 'b'], this configuration is ['b', 'c'], so display the temperature of device b",
|
||||
"preview": "Preview",
|
||||
"primaryColorSeed": "Primary color seed",
|
||||
"privateKey": "Private Key",
|
||||
|
||||
@@ -178,6 +178,8 @@
|
||||
"plzEnterHost": "Veuillez saisir l'hôte.",
|
||||
"plzSelectKey": "Veuillez sélectionner une clé.",
|
||||
"port": "Port",
|
||||
"preferTemperatureDeviceList": "Liste d'affichage prioritaire de la température",
|
||||
"preferTemperatureDeviceListTip": "Par exemple : Les appareils prenant en charge l'affichage de la température sont ['a', 'b'], cette configuration est ['b', 'c'], donc afficher la température de l'appareil b",
|
||||
"preview": "Aperçu",
|
||||
"primaryColorSeed": "Graine de couleur primaire",
|
||||
"privateKey": "Clé privée",
|
||||
|
||||
@@ -178,6 +178,8 @@
|
||||
"plzEnterHost": "Harap masukkan host.",
|
||||
"plzSelectKey": "Pilih kunci.",
|
||||
"port": "Port",
|
||||
"preferTemperatureDeviceList": "Daftar prioritas tampilan suhu",
|
||||
"preferTemperatureDeviceListTip": "Contohnya: Perangkat yang mendukung tampilan suhu adalah ['a', 'b'], pengaturan ini adalah ['b', 'c'], maka tampilkan suhu perangkat b",
|
||||
"preview": "Pratinjau",
|
||||
"primaryColorSeed": "Warna utama",
|
||||
"privateKey": "Kunci Pribadi",
|
||||
|
||||
@@ -178,6 +178,8 @@
|
||||
"plzEnterHost": "请输入主机",
|
||||
"plzSelectKey": "请选择私钥",
|
||||
"port": "端口",
|
||||
"preferTemperatureDeviceList": "优先显示温度的列表",
|
||||
"preferTemperatureDeviceListTip": "例如:设备支持显示温度的设备有['a','b'],此设置为['b','c'],则显示设备b的温度",
|
||||
"preview": "预览",
|
||||
"primaryColorSeed": "主题色种子",
|
||||
"privateKey": "私钥",
|
||||
|
||||
@@ -178,6 +178,8 @@
|
||||
"plzEnterHost": "請輸入主機",
|
||||
"plzSelectKey": "請選擇私鑰",
|
||||
"port": "端口",
|
||||
"preferTemperatureDeviceList": "優先顯示溫度的列表",
|
||||
"preferTemperatureDeviceListTip": "例如:支持顯示溫度的設備有['a', 'b'],此設置為['b', 'c'],則顯示設備b的溫度",
|
||||
"preview": "預覽",
|
||||
"primaryColorSeed": "主要色調種子",
|
||||
"privateKey": "私鑰",
|
||||
|
||||
@@ -12,6 +12,7 @@ import 'package:toolbox/core/extension/ssh_client.dart';
|
||||
import 'package:toolbox/core/utils/platform/base.dart';
|
||||
import 'package:toolbox/core/utils/share.dart';
|
||||
import 'package:toolbox/data/model/app/shell_func.dart';
|
||||
import 'package:toolbox/data/model/server/sensors.dart';
|
||||
import 'package:toolbox/data/model/server/try_limiter.dart';
|
||||
import 'package:toolbox/data/res/provider.dart';
|
||||
import 'package:toolbox/data/res/store.dart';
|
||||
@@ -393,12 +394,6 @@ class _ServerPageState extends State<ServerPage>
|
||||
}
|
||||
|
||||
Widget _buildTopRightText(ServerStatus ss, ServerState cs) {
|
||||
final topRightStr = _getTopRightStr(
|
||||
cs,
|
||||
ss.temps.first,
|
||||
ss.more[StatusCmdType.uptime] ?? '',
|
||||
ss.err,
|
||||
);
|
||||
if (cs == ServerState.failed && ss.err != null) {
|
||||
return GestureDetector(
|
||||
onTap: () => _showFailReason(ss),
|
||||
@@ -408,6 +403,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
),
|
||||
);
|
||||
}
|
||||
final topRightStr = _getTopRightStr(ss, cs);
|
||||
return Text(
|
||||
topRightStr,
|
||||
style: UIs.text13Grey,
|
||||
@@ -549,19 +545,21 @@ class _ServerPageState extends State<ServerPage>
|
||||
_tag == null || (pro.pick(id: e)?.spi.tags?.contains(_tag) ?? false))
|
||||
.toList();
|
||||
|
||||
String _getTopRightStr(
|
||||
ServerState cs,
|
||||
double? temp,
|
||||
String upTime,
|
||||
String? failedInfo,
|
||||
) {
|
||||
String _getTopRightStr(ServerStatus ss, ServerState cs) {
|
||||
switch (cs) {
|
||||
case ServerState.disconnected:
|
||||
return l10n.disconnected;
|
||||
case ServerState.finished:
|
||||
final tempStr = temp == null ? '' : '${temp.toStringAsFixed(1)}°C';
|
||||
final temp = ss.temps.first;
|
||||
final sensorTemp = SensorItem.findPreferTempVal(ss.sensors);
|
||||
final tempStr = switch ((temp, sensorTemp)) {
|
||||
(_, final double val) => '${val.toStringAsFixed(1)}°C',
|
||||
(final double val, _) => '${val.toStringAsFixed(1)}°C',
|
||||
_ => null,
|
||||
};
|
||||
final upTime = ss.more[StatusCmdType.uptime];
|
||||
final items = [tempStr, upTime];
|
||||
final str = items.where((element) => element.isNotEmpty).join(' | ');
|
||||
final str = items.where((e) => e != null && e.isNotEmpty).join(' | ');
|
||||
if (str.isEmpty) return l10n.noResult;
|
||||
return str;
|
||||
case ServerState.loading:
|
||||
@@ -571,10 +569,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
case ServerState.connecting:
|
||||
return l10n.serverTabConnecting;
|
||||
case ServerState.failed:
|
||||
if (failedInfo == null) {
|
||||
return l10n.serverTabFailed;
|
||||
}
|
||||
return failedInfo;
|
||||
return ss.err ?? l10n.serverTabFailed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -190,6 +190,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
//_buildDiskIgnorePath(),
|
||||
_buildDeleteServers(),
|
||||
_buildTextScaler(),
|
||||
_buildPreferTemperatureDeviceList(),
|
||||
//if (isDesktop) _buildDoubleColumnServersPage(),
|
||||
].map((e) => CardX(child: e)).toList(),
|
||||
);
|
||||
@@ -1153,4 +1154,37 @@ class _SettingPageState extends State<SettingPage> {
|
||||
trailing: StoreSwitch(prop: _setting.containerParseStat),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPreferTemperatureDeviceList() {
|
||||
void onSubmitted(String s) {
|
||||
final list = s.split('\n');
|
||||
_setting.preferTemperatureDevs.put(list);
|
||||
context.pop();
|
||||
}
|
||||
return ListTile(
|
||||
title: Text(l10n.preferTemperatureDeviceList),
|
||||
subtitle: Text(l10n.preferTemperatureDeviceListTip, style: UIs.textGrey),
|
||||
trailing: const Icon(Icons.keyboard_arrow_right),
|
||||
onTap: () {
|
||||
final list = _setting.preferTemperatureDevs.fetch();
|
||||
final listStr = list.join('\n');
|
||||
final ctrl = TextEditingController(text: listStr);
|
||||
context.showRoundDialog(
|
||||
title: Text(l10n.preferTemperatureDeviceList),
|
||||
child: Input(
|
||||
autoFocus: true,
|
||||
controller: ctrl,
|
||||
maxLines: 3,
|
||||
onSubmitted: onSubmitted,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => onSubmitted(ctrl.text),
|
||||
child: Text(l10n.ok),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user