fix: wrong hostname display (#336)

This commit is contained in:
lollipopkit
2024-04-16 00:19:00 +08:00
parent b80bf51a61
commit ff8bc49074
2 changed files with 12 additions and 6 deletions

View File

@@ -18,7 +18,7 @@ enum ShellFunc {
/// The suffix `\t` is for formatting /// The suffix `\t` is for formatting
static const cmdDivider = '\necho $seperator\n\t'; static const cmdDivider = '\necho $seperator\n\t';
static const _srvBoxDir = '.config/server_box'; static const _srvBoxDir = '.config/server_box';
static const _scriptFile = 'mobile_v${BuildData.script}.sh'; static const scriptFile = 'mobile_v${BuildData.script}.sh';
/// Issue #159 /// Issue #159
/// ///
@@ -27,10 +27,10 @@ enum ShellFunc {
/// So different version of app can run at the same time. /// So different version of app can run at the same time.
/// ///
/// **Can't** use it in SFTP, because SFTP can't recognize `$HOME` /// **Can't** use it in SFTP, because SFTP can't recognize `$HOME`
static String getShellPath(String home) => '$home/$_srvBoxDir/$_scriptFile'; static String getShellPath(String home) => '$home/$_srvBoxDir/$scriptFile';
static const srvBoxDir = '$_homeVar/$_srvBoxDir'; static const srvBoxDir = '$_homeVar/$_srvBoxDir';
static const _installShellPath = '$_homeVar/$_srvBoxDir/$_scriptFile'; static const _installShellPath = '$_homeVar/$_srvBoxDir/$scriptFile';
// Issue #299, chmod ~/.config to avoid permission issue // Issue #299, chmod ~/.config to avoid permission issue
static const installShellCmd = """ static const installShellCmd = """
@@ -226,7 +226,7 @@ const _statusCmds = [
"cat /proc/meminfo | grep -E 'Mem|Swap'", "cat /proc/meminfo | grep -E 'Mem|Swap'",
'cat /sys/class/thermal/thermal_zone*/type', 'cat /sys/class/thermal/thermal_zone*/type',
'cat /sys/class/thermal/thermal_zone*/temp', 'cat /sys/class/thermal/thermal_zone*/temp',
'hostname', 'cat /etc/hostname',
'cat /proc/diskstats', 'cat /proc/diskstats',
'for f in /sys/class/power_supply/*/uevent; do cat "\$f"; echo; done', 'for f in /sys/class/power_supply/*/uevent; do cat "\$f"; echo; done',
'nvidia-smi -q -x', 'nvidia-smi -q -x',

View File

@@ -60,8 +60,8 @@ Future<ServerStatus> _getLinuxStatus(ServerStatusUpdateReq req) async {
} }
try { try {
final host = StatusCmdType.host.find(segments); final host = _parseHostName(StatusCmdType.host.find(segments));
if (host.isNotEmpty) { if (host != null) {
req.ss.more[StatusCmdType.host] = host; req.ss.more[StatusCmdType.host] = host;
} }
} catch (e, s) { } catch (e, s) {
@@ -237,3 +237,9 @@ String? _parseSysVer(String raw) {
} }
return null; return null;
} }
String? _parseHostName(String raw) {
if (raw.isEmpty) return null;
if (raw.contains(ShellFunc.scriptFile)) return null;
return raw;
}