mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 15:24:35 +01:00
opt.: logger & shell script
This commit is contained in:
@@ -58,7 +58,7 @@ enum AppShellFuncType {
|
|||||||
switch (this) {
|
switch (this) {
|
||||||
case AppShellFuncType.status:
|
case AppShellFuncType.status:
|
||||||
return '''
|
return '''
|
||||||
if [ "\$isLinux" != "" ]; then
|
if [ "\$macSign" = "" ] && [ "\$bsdSign" = "" ]; then
|
||||||
\t${_statusCmds.join(_cmdDivider)}
|
\t${_statusCmds.join(_cmdDivider)}
|
||||||
else
|
else
|
||||||
\t${_bsdStatusCmd.join(_cmdDivider)}
|
\t${_bsdStatusCmd.join(_cmdDivider)}
|
||||||
@@ -73,7 +73,7 @@ else
|
|||||||
fi''';
|
fi''';
|
||||||
case AppShellFuncType.process:
|
case AppShellFuncType.process:
|
||||||
return '''
|
return '''
|
||||||
if [ "\$isLinux" != "" ]; then
|
if [ "\$macSign" = "" ] && [ "\$bsdSign" = "" ]; then
|
||||||
\tif [ "\$isBusybox" != "" ]; then
|
\tif [ "\$isBusybox" != "" ]; then
|
||||||
\t\tps w
|
\t\tps w
|
||||||
\telse
|
\telse
|
||||||
@@ -106,7 +106,7 @@ fi''';
|
|||||||
for (final func in values) {
|
for (final func in values) {
|
||||||
sb.write('''
|
sb.write('''
|
||||||
${func.name}() {
|
${func.name}() {
|
||||||
${func.cmd}
|
${func.cmd.split('\n').map((e) => '\t$e').join('\n')}
|
||||||
}
|
}
|
||||||
|
|
||||||
''');
|
''');
|
||||||
@@ -214,22 +214,27 @@ const _bsdStatusCmd = [
|
|||||||
|
|
||||||
final _shellCmd = """
|
final _shellCmd = """
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
|
||||||
# Script for ServerBox app v1.0.${BuildData.build}
|
# Script for ServerBox app v1.0.${BuildData.build}
|
||||||
#
|
|
||||||
# DO NOT delete this file while app is running
|
# 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
|
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?
|
# Link /bin/sh to busybox?
|
||||||
isBusybox=\$(ls -l /bin/sh | grep "busybox")
|
isBusybox=\$(ls -l /bin/sh | grep "busybox")
|
||||||
|
|
||||||
userId=\$(id -u)
|
userId=\$(id -u)
|
||||||
|
|
||||||
${AppShellFuncType.shellScript}
|
${AppShellFuncType.shellScript}
|
||||||
""";
|
""";
|
||||||
|
|
||||||
final installShellCmd = "mkdir -p $_serverBoxDir && "
|
final installShellCmd = """
|
||||||
"echo '$_shellCmd' > $_shellPath && "
|
mkdir -p $_serverBoxDir
|
||||||
"chmod +x $_shellPath";
|
cat << 'EOF' > $_shellPath
|
||||||
|
$_shellCmd
|
||||||
|
EOF
|
||||||
|
chmod +x $_shellPath
|
||||||
|
""";
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:logging/logging.dart';
|
||||||
import 'package:toolbox/data/res/ui.dart';
|
import 'package:toolbox/data/res/ui.dart';
|
||||||
|
|
||||||
import '../../data/res/misc.dart';
|
import '../../data/res/misc.dart';
|
||||||
|
|
||||||
/// format: [NAME][LEVEL]: MESSAGE
|
|
||||||
final _headReg = RegExp(r'(\[[A-Za-z]+\])(\[[A-Z]+\]): (.*)');
|
|
||||||
const _level2Color = {
|
const _level2Color = {
|
||||||
'[INFO]': Colors.blue,
|
'[INFO]': Colors.blue,
|
||||||
'[WARNING]': Colors.yellow,
|
'[WARNING]': Colors.yellow,
|
||||||
@@ -13,40 +12,37 @@ const _level2Color = {
|
|||||||
class DebugProvider extends ChangeNotifier {
|
class DebugProvider extends ChangeNotifier {
|
||||||
final widgets = <Widget>[];
|
final widgets = <Widget>[];
|
||||||
|
|
||||||
void addText(String text) {
|
void addLog(LogRecord record) {
|
||||||
final match = _headReg.allMatches(text);
|
final color = _level2Color[record.level.name] ?? Colors.blue;
|
||||||
|
widgets.add(Text.rich(TextSpan(
|
||||||
if (match.isNotEmpty) {
|
children: [
|
||||||
_addWidget(Text.rich(TextSpan(
|
TextSpan(
|
||||||
children: [
|
text: '[${record.loggerName}]',
|
||||||
TextSpan(
|
style: const TextStyle(color: Colors.cyan),
|
||||||
text: match.first.group(1),
|
),
|
||||||
style: const TextStyle(color: Colors.cyan),
|
TextSpan(
|
||||||
),
|
text: '[${record.level}]',
|
||||||
TextSpan(
|
style: TextStyle(color: color),
|
||||||
text: match.first.group(2),
|
),
|
||||||
style: TextStyle(color: _level2Color[match.first.group(2)]),
|
TextSpan(
|
||||||
),
|
text: record.error == null
|
||||||
TextSpan(
|
? '\n${record.message}'
|
||||||
text: '\n${match.first.group(3)}',
|
: '\n${record.message}: ${record.error}',
|
||||||
)
|
style: const TextStyle(color: Colors.white),
|
||||||
],
|
),
|
||||||
)));
|
],
|
||||||
} else {
|
)));
|
||||||
_addWidget(Text(text));
|
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);
|
widgets.add(UIs.height13);
|
||||||
|
|
||||||
if (widgets.length > Miscs.maxDebugLogLines) {
|
if (widgets.length > Miscs.maxDebugLogLines) {
|
||||||
widgets.removeRange(0, widgets.length - Miscs.maxDebugLogLines);
|
widgets.removeRange(0, widgets.length - Miscs.maxDebugLogLines);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ class ServerProvider extends ChangeNotifier {
|
|||||||
if (s.state != ServerState.failed) return;
|
if (s.state != ServerState.failed) return;
|
||||||
_limiter.reset(s.spi.id);
|
_limiter.reset(s.spi.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If [spi.autoConnect] is false and server is disconnected, then skip.
|
/// If [spi.autoConnect] is false and server is disconnected, then skip.
|
||||||
///
|
///
|
||||||
/// If [spi.autoConnect] is false and server is connected, then refresh.
|
/// If [spi.autoConnect] is false and server is connected, then refresh.
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
class BuildData {
|
class BuildData {
|
||||||
static const String name = "ServerBox";
|
static const String name = "ServerBox";
|
||||||
static const int build = 563;
|
static const int build = 565;
|
||||||
static const String engine = "3.13.2";
|
static const String engine = "3.13.4";
|
||||||
static const String buildAt = "2023-09-17 14:30:45";
|
static const String buildAt = "2023-09-19 17:48:16";
|
||||||
static const int modifications = 3;
|
static const int modifications = 5;
|
||||||
static const int script = 15;
|
static const int script = 15;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class Miscs {
|
|||||||
/// Private Key max allowed size is 20kb
|
/// Private Key max allowed size is 20kb
|
||||||
static const privateKeyMaxSize = 20 * 1024;
|
static const privateKeyMaxSize = 20 * 1024;
|
||||||
|
|
||||||
// Editor max allowed size is 1mb
|
/// Editor max allowed size is 1mb
|
||||||
static const editorMaxSize = 1024 * 1024;
|
static const editorMaxSize = 1024 * 1024;
|
||||||
|
|
||||||
/// Max debug log lines
|
/// Max debug log lines
|
||||||
|
|||||||
@@ -114,18 +114,9 @@ Future<void> _initHive() async {
|
|||||||
void _setupLogger() {
|
void _setupLogger() {
|
||||||
Logger.root.level = Level.ALL;
|
Logger.root.level = Level.ALL;
|
||||||
Logger.root.onRecord.listen((record) {
|
Logger.root.onRecord.listen((record) {
|
||||||
var str = '[${record.loggerName}][${record.level.name}]: ${record.message}';
|
Providers.debug.addLog(record);
|
||||||
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);
|
|
||||||
}
|
|
||||||
// ignore: avoid_print
|
// ignore: avoid_print
|
||||||
print(str);
|
print(record);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -476,9 +476,9 @@
|
|||||||
baseConfigurationReference = C1C758C41C4E208965A68933 /* Pods-RunnerTests.debug.xcconfig */;
|
baseConfigurationReference = C1C758C41C4E208965A68933 /* Pods-RunnerTests.debug.xcconfig */;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||||
CURRENT_PROJECT_VERSION = 563;
|
CURRENT_PROJECT_VERSION = 565;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
MARKETING_VERSION = 1.0.563;
|
MARKETING_VERSION = 1.0.565;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
|
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
@@ -491,9 +491,9 @@
|
|||||||
baseConfigurationReference = 15AF97DF993E8968098D6EBE /* Pods-RunnerTests.release.xcconfig */;
|
baseConfigurationReference = 15AF97DF993E8968098D6EBE /* Pods-RunnerTests.release.xcconfig */;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||||
CURRENT_PROJECT_VERSION = 563;
|
CURRENT_PROJECT_VERSION = 565;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
MARKETING_VERSION = 1.0.563;
|
MARKETING_VERSION = 1.0.565;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
|
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
@@ -506,9 +506,9 @@
|
|||||||
baseConfigurationReference = 7CFA7DE7FABA75685DFB6948 /* Pods-RunnerTests.profile.xcconfig */;
|
baseConfigurationReference = 7CFA7DE7FABA75685DFB6948 /* Pods-RunnerTests.profile.xcconfig */;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||||
CURRENT_PROJECT_VERSION = 563;
|
CURRENT_PROJECT_VERSION = 565;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
MARKETING_VERSION = 1.0.563;
|
MARKETING_VERSION = 1.0.565;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
|
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
|
|||||||
Reference in New Issue
Block a user