diff --git a/lib/data/model/app/shell_func.dart b/lib/data/model/app/shell_func.dart index 8b52409c..a48bf10d 100644 --- a/lib/data/model/app/shell_func.dart +++ b/lib/data/model/app/shell_func.dart @@ -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 +"""; diff --git a/lib/data/provider/debug.dart b/lib/data/provider/debug.dart index 4daaf32e..bf6ca5c7 100644 --- a/lib/data/provider/debug.dart +++ b/lib/data/provider/debug.dart @@ -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 = []; - 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); } diff --git a/lib/data/provider/server.dart b/lib/data/provider/server.dart index 57a4bb56..4ff26e6b 100644 --- a/lib/data/provider/server.dart +++ b/lib/data/provider/server.dart @@ -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; diff --git a/lib/data/res/build_data.dart b/lib/data/res/build_data.dart index 652db57e..83edee34 100644 --- a/lib/data/res/build_data.dart +++ b/lib/data/res/build_data.dart @@ -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; } diff --git a/lib/data/res/misc.dart b/lib/data/res/misc.dart index 85d03d99..5b2bb3c0 100644 --- a/lib/data/res/misc.dart +++ b/lib/data/res/misc.dart @@ -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 diff --git a/lib/main.dart b/lib/main.dart index 413d2e58..fb79ccbf 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -114,18 +114,9 @@ Future _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); }); } diff --git a/macos/Runner.xcodeproj/project.pbxproj b/macos/Runner.xcodeproj/project.pbxproj index e3944a4c..d0f5184c 100644 --- a/macos/Runner.xcodeproj/project.pbxproj +++ b/macos/Runner.xcodeproj/project.pbxproj @@ -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;