mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
opt.: l10n & fix: write script (#514)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:fl_lib/fl_lib.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:server_box/core/extension/context/locale.dart';
|
||||
|
||||
@@ -21,46 +22,27 @@ enum ContainerMenu {
|
||||
terminal,
|
||||
//stats,
|
||||
];
|
||||
} else {
|
||||
return [start, rm, logs];
|
||||
}
|
||||
return [start, rm, logs];
|
||||
}
|
||||
|
||||
IconData get icon {
|
||||
switch (this) {
|
||||
case ContainerMenu.start:
|
||||
return Icons.play_arrow;
|
||||
case ContainerMenu.stop:
|
||||
return Icons.stop;
|
||||
case ContainerMenu.restart:
|
||||
return Icons.restart_alt;
|
||||
case ContainerMenu.rm:
|
||||
return Icons.delete;
|
||||
case ContainerMenu.logs:
|
||||
return Icons.logo_dev;
|
||||
case ContainerMenu.terminal:
|
||||
return Icons.terminal;
|
||||
// case DockerMenuType.stats:
|
||||
// return Icons.bar_chart;
|
||||
}
|
||||
}
|
||||
IconData get icon => switch (this) {
|
||||
ContainerMenu.start => Icons.play_arrow,
|
||||
ContainerMenu.stop => Icons.stop,
|
||||
ContainerMenu.restart => Icons.restart_alt,
|
||||
ContainerMenu.rm => Icons.delete,
|
||||
ContainerMenu.logs => Icons.logo_dev,
|
||||
ContainerMenu.terminal => Icons.terminal,
|
||||
// DockerMenuType.stats => Icons.bar_chart,
|
||||
};
|
||||
|
||||
String get toStr {
|
||||
switch (this) {
|
||||
case ContainerMenu.start:
|
||||
return l10n.start;
|
||||
case ContainerMenu.stop:
|
||||
return l10n.stop;
|
||||
case ContainerMenu.restart:
|
||||
return l10n.restart;
|
||||
case ContainerMenu.rm:
|
||||
return l10n.delete;
|
||||
case ContainerMenu.logs:
|
||||
return l10n.log;
|
||||
case ContainerMenu.terminal:
|
||||
return l10n.terminal;
|
||||
// case DockerMenuType.stats:
|
||||
// return s.stats;
|
||||
}
|
||||
}
|
||||
String get toStr => switch (this) {
|
||||
ContainerMenu.start => l10n.start,
|
||||
ContainerMenu.stop => l10n.stop,
|
||||
ContainerMenu.restart => l10n.restart,
|
||||
ContainerMenu.rm => libL10n.delete,
|
||||
ContainerMenu.logs => libL10n.log,
|
||||
ContainerMenu.terminal => l10n.terminal,
|
||||
// DockerMenuType.stats => s.stats,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:fl_lib/fl_lib.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:server_box/core/extension/context/locale.dart';
|
||||
import 'package:server_box/data/model/server/server.dart';
|
||||
@@ -14,27 +15,17 @@ enum NetViewType {
|
||||
@HiveField(2)
|
||||
traffic;
|
||||
|
||||
NetViewType get next {
|
||||
switch (this) {
|
||||
case conn:
|
||||
return speed;
|
||||
case speed:
|
||||
return traffic;
|
||||
case traffic:
|
||||
return conn;
|
||||
}
|
||||
}
|
||||
NetViewType get next => switch (this) {
|
||||
conn => speed,
|
||||
speed => traffic,
|
||||
traffic => conn,
|
||||
};
|
||||
|
||||
String get toStr {
|
||||
switch (this) {
|
||||
case NetViewType.conn:
|
||||
return l10n.conn;
|
||||
case NetViewType.traffic:
|
||||
return l10n.traffic;
|
||||
case NetViewType.speed:
|
||||
return l10n.speed;
|
||||
}
|
||||
}
|
||||
String get toStr => switch (this) {
|
||||
NetViewType.conn => l10n.conn,
|
||||
NetViewType.traffic => l10n.traffic,
|
||||
NetViewType.speed => l10n.speed,
|
||||
};
|
||||
|
||||
(String, String) build(ServerStatus ss) {
|
||||
final ignoreLocal = Stores.setting.ignoreLocalNet.fetch();
|
||||
@@ -42,7 +33,7 @@ enum NetViewType {
|
||||
case NetViewType.conn:
|
||||
return (
|
||||
'${l10n.conn}:\n${ss.tcp.maxConn}',
|
||||
'${l10n.failed}:\n${ss.tcp.fail}',
|
||||
'${libL10n.fail}:\n${ss.tcp.fail}',
|
||||
);
|
||||
case NetViewType.speed:
|
||||
if (ignoreLocal) {
|
||||
@@ -69,25 +60,15 @@ enum NetViewType {
|
||||
}
|
||||
}
|
||||
|
||||
int toJson() {
|
||||
switch (this) {
|
||||
case NetViewType.conn:
|
||||
return 0;
|
||||
case NetViewType.speed:
|
||||
return 1;
|
||||
case NetViewType.traffic:
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
int toJson() => switch (this) {
|
||||
NetViewType.conn => 0,
|
||||
NetViewType.speed => 1,
|
||||
NetViewType.traffic => 2,
|
||||
};
|
||||
|
||||
static NetViewType fromJson(int json) {
|
||||
switch (json) {
|
||||
case 0:
|
||||
return NetViewType.conn;
|
||||
case 2:
|
||||
return NetViewType.traffic;
|
||||
default:
|
||||
return NetViewType.speed;
|
||||
}
|
||||
}
|
||||
static NetViewType fromJson(int json) => switch (json) {
|
||||
0 => NetViewType.conn,
|
||||
1 => NetViewType.speed,
|
||||
_ => NetViewType.traffic,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,14 +19,40 @@ enum ShellFunc {
|
||||
|
||||
/// srvboxm -> ServerBox Mobile
|
||||
static const scriptFile = 'srvboxm_v${BuildData.script}.sh';
|
||||
static const scriptDir = '~/.config/server_box';
|
||||
static const scriptPath = '$scriptDir/$scriptFile';
|
||||
static const scriptDirHome = '~/.config/server_box';
|
||||
static const scriptDirTmp = '/tmp/server_box';
|
||||
|
||||
static const String installShellCmd = """
|
||||
static final _scriptDirMap = <String, String>{};
|
||||
|
||||
/// Get the script directory for the given [id].
|
||||
///
|
||||
/// Default is [scriptDirTmp]/[scriptFile], if this path is not accessible,
|
||||
/// it will be changed to [scriptDirHome]/[scriptFile].
|
||||
static String getScriptDir(String id) {
|
||||
return _scriptDirMap.putIfAbsent(id, () {
|
||||
return scriptDirTmp;
|
||||
});
|
||||
}
|
||||
|
||||
static void switchScriptDir(String id) => switch (_scriptDirMap[id]) {
|
||||
scriptDirTmp => _scriptDirMap[id] = scriptDirHome,
|
||||
scriptDirHome => _scriptDirMap[id] = scriptDirTmp,
|
||||
_ => _scriptDirMap[id] = scriptDirHome,
|
||||
};
|
||||
|
||||
static String getScriptPath(String id) {
|
||||
return '${getScriptDir(id)}/$scriptFile';
|
||||
}
|
||||
|
||||
static String getInstallShellCmd(String id) {
|
||||
final scriptDir = getScriptDir(id);
|
||||
final scriptPath = '$scriptDir/$scriptFile';
|
||||
return """
|
||||
mkdir -p $scriptDir
|
||||
cat > $scriptPath
|
||||
chmod 744 $scriptPath
|
||||
""";
|
||||
}
|
||||
|
||||
String get flag => switch (this) {
|
||||
ShellFunc.process => 'p',
|
||||
@@ -37,7 +63,7 @@ chmod 744 $scriptPath
|
||||
// ShellFunc.docker=> 'd',
|
||||
};
|
||||
|
||||
String get exec => 'sh $scriptPath -$flag';
|
||||
String exec(String id) => 'sh ${getScriptPath(id)} -$flag';
|
||||
|
||||
String get name {
|
||||
switch (this) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:fl_lib/fl_lib.dart';
|
||||
import 'package:server_box/core/extension/context/locale.dart';
|
||||
|
||||
final class SensorAdaptor {
|
||||
final String raw;
|
||||
@@ -37,7 +36,7 @@ final class SensorItem {
|
||||
|
||||
String get toMarkdown {
|
||||
final sb = StringBuffer();
|
||||
sb.writeln('| ${l10n.name} | ${l10n.content} |');
|
||||
sb.writeln('| ${libL10n.name} | ${libL10n.content} |');
|
||||
sb.writeln('| --- | --- |');
|
||||
for (final entry in details.entries) {
|
||||
sb.writeln('| ${entry.key} | ${entry.value} |');
|
||||
@@ -80,9 +79,7 @@ final class SensorItem {
|
||||
for (var idx = 2; idx < len; idx++) {
|
||||
final part = sensorLines[idx];
|
||||
final detailParts = part.split(':');
|
||||
if (detailParts.length < 2) {
|
||||
continue;
|
||||
}
|
||||
if (detailParts.length < 2) continue;
|
||||
final key = detailParts[0].trim();
|
||||
final value = detailParts[1].trim();
|
||||
details[key] = value;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:fl_lib/fl_lib.dart';
|
||||
import 'package:server_box/core/extension/context/locale.dart';
|
||||
import 'package:server_box/data/model/app/error.dart';
|
||||
import 'package:server_box/data/model/app/shell_func.dart';
|
||||
import 'package:server_box/data/model/app/tag_pickable.dart';
|
||||
import 'package:server_box/data/model/server/battery.dart';
|
||||
import 'package:server_box/data/model/server/conn.dart';
|
||||
import 'package:server_box/data/model/server/cpu.dart';
|
||||
@@ -15,10 +14,6 @@ import 'package:server_box/data/model/server/server_private_info.dart';
|
||||
import 'package:server_box/data/model/server/system.dart';
|
||||
import 'package:server_box/data/model/server/temp.dart';
|
||||
|
||||
import '../app/tag_pickable.dart';
|
||||
|
||||
part 'server.ext.dart';
|
||||
|
||||
class Server implements TagPickable {
|
||||
ServerPrivateInfo spi;
|
||||
ServerStatus status;
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
part of 'server.dart';
|
||||
|
||||
extension ServerX on Server {
|
||||
String getTopRightStr(ServerPrivateInfo spi) {
|
||||
switch (conn) {
|
||||
case ServerConn.disconnected:
|
||||
return l10n.disconnected;
|
||||
case ServerConn.finished:
|
||||
// Highest priority of temperature display
|
||||
final cmdTemp = () {
|
||||
final val = status.customCmds['server_card_top_right'];
|
||||
if (val == null) return null;
|
||||
// This returned value is used on server card top right, so it should
|
||||
// be a single line string.
|
||||
return val.split('\n').lastOrNull;
|
||||
}();
|
||||
final temperatureVal = () {
|
||||
// Second priority
|
||||
final preferTempDev = spi.custom?.preferTempDev;
|
||||
if (preferTempDev != null) {
|
||||
final preferTemp = status.sensors
|
||||
.firstWhereOrNull((e) => e.device == preferTempDev)
|
||||
?.summary
|
||||
?.split(' ')
|
||||
.firstOrNull;
|
||||
if (preferTemp != null) {
|
||||
return double.tryParse(preferTemp.replaceFirst('°C', ''));
|
||||
}
|
||||
}
|
||||
// Last priority
|
||||
final temp = status.temps.first;
|
||||
if (temp != null) {
|
||||
return temp;
|
||||
}
|
||||
return null;
|
||||
}();
|
||||
final upTime = status.more[StatusCmdType.uptime];
|
||||
final items = [
|
||||
cmdTemp ??
|
||||
(temperatureVal != null
|
||||
? '${temperatureVal.toStringAsFixed(1)}°C'
|
||||
: null),
|
||||
upTime
|
||||
];
|
||||
final str = items.where((e) => e != null && e.isNotEmpty).join(' | ');
|
||||
if (str.isEmpty) return l10n.noResult;
|
||||
return str;
|
||||
case ServerConn.loading:
|
||||
return l10n.serverTabLoading;
|
||||
case ServerConn.connected:
|
||||
return l10n.connected;
|
||||
case ServerConn.connecting:
|
||||
return l10n.serverTabConnecting;
|
||||
case ServerConn.failed:
|
||||
return status.err != null ? l10n.viewErr : l10n.serverTabFailed;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user