opt.: logger & shell script

This commit is contained in:
lollipopkit
2023-09-19 19:36:07 +08:00
parent e74a6cf3d5
commit 453eb200a8
7 changed files with 61 additions and 68 deletions

View File

@@ -58,7 +58,7 @@ enum AppShellFuncType {
switch (this) {
case AppShellFuncType.status:
return '''
if [ "\$isLinux" != "" ]; then
if [ "\$macSign" = "" ] && [ "\$bsdSign" = "" ]; then
\t${_statusCmds.join(_cmdDivider)}
else
\t${_bsdStatusCmd.join(_cmdDivider)}
@@ -73,7 +73,7 @@ else
fi''';
case AppShellFuncType.process:
return '''
if [ "\$isLinux" != "" ]; then
if [ "\$macSign" = "" ] && [ "\$bsdSign" = "" ]; then
\tif [ "\$isBusybox" != "" ]; then
\t\tps w
\telse
@@ -106,7 +106,7 @@ fi''';
for (final func in values) {
sb.write('''
${func.name}() {
${func.cmd}
${func.cmd.split('\n').map((e) => '\t$e').join('\n')}
}
''');
@@ -214,22 +214,27 @@ const _bsdStatusCmd = [
final _shellCmd = """
#!/bin/sh
#
# Script for ServerBox app v1.0.${BuildData.build}
#
# DO NOT delete this file while app is running
# DO NOT run multi ServerBox apps with different version at the same time
export LANG=en_US.UTF-8
isLinux=\$(uname 2>&1 | grep "Linux")
# If macSign & bsdSign are both empty, then it's linux
macSign=\$(uname 2>&1 | grep "Darwin")
bsdSign=\$(uname 2>&1 | grep "BSD")
# Link /bin/sh to busybox?
isBusybox=\$(ls -l /bin/sh | grep "busybox")
userId=\$(id -u)
${AppShellFuncType.shellScript}
""";
final installShellCmd = "mkdir -p $_serverBoxDir && "
"echo '$_shellCmd' > $_shellPath && "
"chmod +x $_shellPath";
final installShellCmd = """
mkdir -p $_serverBoxDir
cat << 'EOF' > $_shellPath
$_shellCmd
EOF
chmod +x $_shellPath
""";

View File

@@ -1,10 +1,9 @@
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:toolbox/data/res/ui.dart';
import '../../data/res/misc.dart';
/// format: [NAME][LEVEL]: MESSAGE
final _headReg = RegExp(r'(\[[A-Za-z]+\])(\[[A-Z]+\]): (.*)');
const _level2Color = {
'[INFO]': Colors.blue,
'[WARNING]': Colors.yellow,
@@ -13,40 +12,37 @@ const _level2Color = {
class DebugProvider extends ChangeNotifier {
final widgets = <Widget>[];
void addText(String text) {
final match = _headReg.allMatches(text);
if (match.isNotEmpty) {
_addWidget(Text.rich(TextSpan(
children: [
TextSpan(
text: match.first.group(1),
style: const TextStyle(color: Colors.cyan),
),
TextSpan(
text: match.first.group(2),
style: TextStyle(color: _level2Color[match.first.group(2)]),
),
TextSpan(
text: '\n${match.first.group(3)}',
)
],
)));
} else {
_addWidget(Text(text));
void addLog(LogRecord record) {
final color = _level2Color[record.level.name] ?? Colors.blue;
widgets.add(Text.rich(TextSpan(
children: [
TextSpan(
text: '[${record.loggerName}]',
style: const TextStyle(color: Colors.cyan),
),
TextSpan(
text: '[${record.level}]',
style: TextStyle(color: color),
),
TextSpan(
text: record.error == null
? '\n${record.message}'
: '\n${record.message}: ${record.error}',
style: const TextStyle(color: Colors.white),
),
],
)));
if (record.stackTrace != null) {
widgets.add(SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Text(
'${record.stackTrace}',
style: const TextStyle(color: Colors.white),
),
));
}
}
void addMultiline(Object data, [Color color = Colors.blue]) {
_addWidget(SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Text('$data', style: TextStyle(color: color)),
));
}
void _addWidget(Widget widget) {
widgets.add(widget);
widgets.add(UIs.height13);
if (widgets.length > Miscs.maxDebugLogLines) {
widgets.removeRange(0, widgets.length - Miscs.maxDebugLogLines);
}

View File

@@ -104,11 +104,12 @@ class ServerProvider extends ChangeNotifier {
if (s.state != ServerState.failed) return;
_limiter.reset(s.spi.id);
}
/// If [spi.autoConnect] is false and server is disconnected, then skip.
///
///
/// If [spi.autoConnect] is false and server is connected, then refresh.
/// If no this, the server will only refresh once by clicking refresh button.
///
///
/// If [spi.autoConnect] is true, then refresh.
if (!(s.spi.autoConnect ?? true) && s.state == ServerState.disconnected) {
return;

View File

@@ -2,9 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 563;
static const String engine = "3.13.2";
static const String buildAt = "2023-09-17 14:30:45";
static const int modifications = 3;
static const int build = 565;
static const String engine = "3.13.4";
static const String buildAt = "2023-09-19 17:48:16";
static const int modifications = 5;
static const int script = 15;
}

View File

@@ -12,7 +12,7 @@ class Miscs {
/// Private Key max allowed size is 20kb
static const privateKeyMaxSize = 20 * 1024;
// Editor max allowed size is 1mb
/// Editor max allowed size is 1mb
static const editorMaxSize = 1024 * 1024;
/// Max debug log lines