fix: Use latest dartssh2 and add a switch for temperature between celsius and millicelsius (#1095)

* refactor(sftp): Optimize file download logic and SSH command execution handling

Replace manual chunked downloads with a more concise `sftp.download` method
Consistently use `utf8.decode` to process SSH command output

Remove redundant code and comments, and simplify the logic

* chore: Update `dartssh2` submodule

* feat (Temperature Display): Added an option to switch between degrees Celsius and millicelsius

Allows users to switch temperature units in server settings, resolving the issue of incorrect temperature display on some devices

* chore: Add a participnt

* fix(sftp): Fixed a resource leak issue during file downloads and SSH command execution

Ensured that remote and local file handles are properly closed during file downloads to prevent resource leaks. Additionally, improved error handling during SSH command execution to ensure that all streams are either successfully completed or properly handled in the event of an error.
This commit is contained in:
GT610
2026-04-01 11:27:58 +08:00
committed by GitHub
parent 36851ef1c2
commit 3c592baf2c
36 changed files with 211 additions and 102 deletions

View File

@@ -18,6 +18,8 @@ final class ServerCustom {
final String? preferTempDev;
final bool tempIsCelsius;
final String? logoUrl;
/// The device name of the network interface displayed in the home server card.
@@ -33,6 +35,7 @@ final class ServerCustom {
this.pvePwd,
this.cmds,
this.preferTempDev,
this.tempIsCelsius = false,
this.logoUrl,
this.netDev,
this.scriptDir,
@@ -51,6 +54,7 @@ final class ServerCustom {
other.pvePwd == pvePwd &&
other.cmds == cmds &&
other.preferTempDev == preferTempDev &&
other.tempIsCelsius == tempIsCelsius &&
other.logoUrl == logoUrl &&
other.netDev == netDev &&
other.scriptDir == scriptDir;
@@ -64,6 +68,7 @@ final class ServerCustom {
pvePwd.hashCode ^
cmds.hashCode ^
preferTempDev.hashCode ^
tempIsCelsius.hashCode ^
logoUrl.hashCode ^
netDev.hashCode ^
scriptDir.hashCode;

View File

@@ -14,6 +14,7 @@ ServerCustom _$ServerCustomFromJson(Map<String, dynamic> json) => ServerCustom(
(k, e) => MapEntry(k, e as String),
),
preferTempDev: json['preferTempDev'] as String?,
tempIsCelsius: json['tempIsCelsius'] as bool? ?? false,
logoUrl: json['logoUrl'] as String?,
netDev: json['netDev'] as String?,
scriptDir: json['scriptDir'] as String?,
@@ -26,6 +27,7 @@ Map<String, dynamic> _$ServerCustomToJson(ServerCustom instance) =>
'pvePwd': ?instance.pvePwd,
'cmds': ?instance.cmds,
'preferTempDev': ?instance.preferTempDev,
'tempIsCelsius': instance.tempIsCelsius,
'logoUrl': ?instance.logoUrl,
'netDev': ?instance.netDev,
'scriptDir': ?instance.scriptDir,

View File

@@ -23,12 +23,14 @@ class ServerStatusUpdateReq {
final Map<String, String> parsedOutput;
final SystemType system;
final Map<String, String> customCmds;
final double tempDivisor;
const ServerStatusUpdateReq({
required this.system,
required this.ss,
required this.parsedOutput,
required this.customCmds,
this.tempDivisor = 1000.0,
});
}
@@ -88,6 +90,7 @@ Future<ServerStatus> _getLinuxStatus(ServerStatusUpdateReq req) async {
req.ss.temps.parse(
StatusCmdType.tempType.findInMap(parsedOutput),
StatusCmdType.tempVal.findInMap(parsedOutput),
divisor: req.tempDivisor,
);
} catch (e, s) {
Loggers.app.warning(e, s);
@@ -495,7 +498,7 @@ void _parseWindowsTemperatureData(ServerStatusUpdateReq req, Map<String, String>
try {
final tempRaw = WindowsStatusCmdType.temp.findInMap(parsedOutput);
if (tempRaw.isNotEmpty && tempRaw != 'null') {
_parseWindowsTemperatures(req.ss.temps, tempRaw);
_parseWindowsTemperatures(req.ss.temps, tempRaw, divisor: req.tempDivisor);
}
} catch (e, s) {
Loggers.app.warning('Windows temperature parsing failed: $e', s);
@@ -648,7 +651,7 @@ List<DiskIOPiece> _parseWindowsDiskIO(String raw, int currentTime) {
}
}
void _parseWindowsTemperatures(Temperatures temps, String raw) {
void _parseWindowsTemperatures(Temperatures temps, String raw, {double divisor = 1000.0}) {
try {
// Handle error output
if (raw.contains('Error') || raw.contains('Exception') || raw.contains('The term')) {
@@ -677,7 +680,7 @@ void _parseWindowsTemperatures(Temperatures temps, String raw) {
}
if (typeLines.isNotEmpty && valueLines.isNotEmpty) {
temps.parse(typeLines.join('\n'), valueLines.join('\n'));
temps.parse(typeLines.join('\n'), valueLines.join('\n'), divisor: divisor);
}
} catch (e, s) {
Loggers.app.warning('Failed to parse Windows temperature data', e, s);

View File

@@ -1,7 +1,7 @@
class Temperatures {
final Map<String, double> _map = {};
void parse(String type, String value) {
void parse(String type, String value, {double divisor = 1000.0}) {
final typeSplited = type.split('\n');
final valueSplited = value.split('\n');
for (var i = 0; i < typeSplited.length && i < valueSplited.length; i++) {
@@ -15,7 +15,7 @@ class Temperatures {
if (temp == null) {
continue;
}
_map[name] = temp / 1000;
_map[name] = temp / divisor;
}
}