new: server tab process

This commit is contained in:
lollipopkit
2023-06-21 17:47:57 +08:00
parent 625bc280f0
commit 3a8e189dd7
14 changed files with 111 additions and 5 deletions

View File

@@ -870,6 +870,12 @@ abstract class S {
/// **'Private Key'**
String get privateKey;
/// No description provided for @process.
///
/// In en, this message translates to:
/// **'Process'**
String get process;
/// No description provided for @pushToken.
///
/// In en, this message translates to:

View File

@@ -413,6 +413,9 @@ class SDe extends S {
@override
String get privateKey => 'Private Key';
@override
String get process => 'Prozess';
@override
String get pushToken => 'Push Token';

View File

@@ -413,6 +413,9 @@ class SEn extends S {
@override
String get privateKey => 'Private Key';
@override
String get process => 'Process';
@override
String get pushToken => 'Push token';

View File

@@ -413,6 +413,9 @@ class SZh extends S {
@override
String get privateKey => '私钥';
@override
String get process => '进程';
@override
String get pushToken => '消息推送 Token';
@@ -1029,6 +1032,9 @@ class SZhTw extends SZh {
@override
String get privateKey => '私鑰';
@override
String get process => '進程';
@override
String get pushToken => '消息推送 Token';

View File

@@ -168,9 +168,9 @@ void showSnippetDialog(
void switchStatusBar({required bool hide}) {
if (hide) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky,
overlays: []);
overlays: []);
} else {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge,
overlays: [SystemUiOverlay.top, SystemUiOverlay.bottom]);
overlays: [SystemUiOverlay.top, SystemUiOverlay.bottom]);
}
}

View File

@@ -6,6 +6,7 @@ enum ServerTabMenuType {
snippet,
pkg,
docker,
process,
edit;
IconData get icon {
@@ -20,6 +21,8 @@ enum ServerTabMenuType {
return Icons.view_agenda;
case ServerTabMenuType.edit:
return Icons.edit;
case ServerTabMenuType.process:
return Icons.list_alt_outlined;
}
}
@@ -35,6 +38,8 @@ enum ServerTabMenuType {
return 'Docker';
case ServerTabMenuType.edit:
return s.edit;
case ServerTabMenuType.process:
return s.process;
}
}

View File

@@ -0,0 +1,41 @@
class AppShellFunc {
final String name;
final String cmd;
final String flag;
const AppShellFunc(this.name, this.cmd, this.flag);
}
typedef AppShellFuncs = List<AppShellFunc>;
extension AppShellFuncsExt on AppShellFuncs {
String get generate {
final sb = StringBuffer();
// Write each func
for (final func in this) {
sb.write('''
${func.name}() {
${func.cmd}
}
''');
}
// Write switch case
sb.write('case \$1 in\n');
for (final func in this) {
sb.write('''
'-${func.flag}')
${func.name}
;;
''');
}
sb.write('''
*)
echo "Invalid argument \$1"
;;
esac
''');
return sb.toString();
}
}

View File

@@ -240,7 +240,8 @@ class ServerProvider extends BusyProvider {
if (s.client == null) return;
// run script to get server status
raw = await s.client!.run("sh $shellPath").string;
raw =
await s.client!.run("sh $shellPath -${shellFuncStatus.flag}").string;
segments = raw.split(seperator).map((e) => e.trim()).toList();
if (raw.isEmpty || segments.length != CmdType.values.length) {
s.state = ServerState.failed;

View File

@@ -1,3 +1,4 @@
import '../model/app/shell_func.dart';
import 'build_data.dart';
const seperator = 'SrvBox';
@@ -36,11 +37,37 @@ const _cmdList = [
'cat /etc/redhat-release',
];
final shellFuncStatus = AppShellFunc(
'status',
_cmdList.join('\necho $seperator\n'),
's',
);
// Check if `htop` is installed.
// Then app open SSH term and use `htop` or `ps` to see process.
const shellFuncProcess = AppShellFunc(
'process',
'''
if command -v htop &> /dev/null
then
htop
else
top
fi
''',
'p',
);
final _generated = [
shellFuncStatus,
shellFuncProcess,
].generate;
final shellCmd = """
# Script for app `${BuildData.name} v${BuildData.build}`
# Script for app `${BuildData.name} v1.0.${BuildData.build}`
# Delete this file while app is running will cause app crash
${_cmdList.join('\necho $seperator\n')}
$_generated
""";
final installShellCmd = "mkdir -p $serverBoxDir && "

View File

@@ -126,6 +126,7 @@
"port": "Port",
"preview": "Vorschau",
"privateKey": "Private Key",
"process": "Prozess",
"pushToken": "Push Token",
"pwd": "Passwort",
"remotePath": "Entfernte Pfade",

View File

@@ -129,6 +129,7 @@
"port": "Port",
"preview": "Preview",
"privateKey": "Private Key",
"process": "Process",
"pushToken": "Push token",
"pwd": "Password",
"remotePath": "Remote path",

View File

@@ -129,6 +129,7 @@
"port": "端口",
"preview": "预览",
"privateKey": "私钥",
"process": "进程",
"pushToken": "消息推送 Token",
"pwd": "密码",
"remotePath": "远端路径",

View File

@@ -126,6 +126,7 @@
"port": "端口",
"preview": "預覽",
"privateKey": "私鑰",
"process": "進程",
"pushToken": "消息推送 Token",
"pwd": "密碼",
"remotePath": "遠端路徑",

View File

@@ -7,6 +7,7 @@ import 'package:provider/provider.dart';
import 'package:toolbox/core/extension/navigator.dart';
import 'package:toolbox/core/extension/order.dart';
import 'package:toolbox/core/utils/misc.dart';
import 'package:toolbox/data/res/server_cmd.dart';
import '../../../core/route.dart';
import '../../../core/utils/ui.dart';
@@ -336,6 +337,15 @@ class _ServerPageState extends State<ServerPage>
case ServerTabMenuType.docker:
AppRoute(DockerManagePage(spi), 'Docker manage').go(context);
break;
case ServerTabMenuType.process:
AppRoute(
SSHPage(
spi: spi,
initCmd: 'sh $shellPath -${shellFuncProcess.flag}',
),
'ssh page (process)',
).go(context);
break;
}
},
);