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

View File

@@ -114,18 +114,9 @@ Future<void> _initHive() async {
void _setupLogger() {
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
var str = '[${record.loggerName}][${record.level.name}]: ${record.message}';
Providers.debug.addText(str);
if (record.error != null) {
str += '\n${record.error}';
Providers.debug.addMultiline(record.error.toString(), Colors.red);
}
if (record.stackTrace != null) {
str += '\n${record.stackTrace}';
Providers.debug.addMultiline(record.stackTrace.toString(), Colors.white);
}
Providers.debug.addLog(record);
// ignore: avoid_print
print(str);
print(record);
});
}

View File

@@ -476,9 +476,9 @@
baseConfigurationReference = C1C758C41C4E208965A68933 /* Pods-RunnerTests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CURRENT_PROJECT_VERSION = 563;
CURRENT_PROJECT_VERSION = 565;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0.563;
MARKETING_VERSION = 1.0.565;
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
@@ -491,9 +491,9 @@
baseConfigurationReference = 15AF97DF993E8968098D6EBE /* Pods-RunnerTests.release.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CURRENT_PROJECT_VERSION = 563;
CURRENT_PROJECT_VERSION = 565;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0.563;
MARKETING_VERSION = 1.0.565;
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
@@ -506,9 +506,9 @@
baseConfigurationReference = 7CFA7DE7FABA75685DFB6948 /* Pods-RunnerTests.profile.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CURRENT_PROJECT_VERSION = 563;
CURRENT_PROJECT_VERSION = 565;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0.563;
MARKETING_VERSION = 1.0.565;
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;