fix docker parse error

- rootless docker socket host
- version & edition
This commit is contained in:
Junyuan Feng
2022-05-31 11:02:59 +08:00
parent bb1bf9219c
commit 04db5a82b9
8 changed files with 48 additions and 42 deletions

View File

@@ -71,3 +71,6 @@ Please use `make.dart` to build.
## License
`LGPL License. LollipopKit 2021`
## Thanks
Especially thanks to [xuty](https://github.com/xtyxtyx) and dartssh2.

View File

@@ -354,7 +354,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 149;
CURRENT_PROJECT_VERSION = 151;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
@@ -362,7 +362,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.149;
MARKETING_VERSION = 1.0.151;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -484,7 +484,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 149;
CURRENT_PROJECT_VERSION = 151;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
@@ -492,7 +492,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.149;
MARKETING_VERSION = 1.0.151;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -508,7 +508,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 149;
CURRENT_PROJECT_VERSION = 151;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
@@ -516,7 +516,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.149;
MARKETING_VERSION = 1.0.151;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";

View File

@@ -4,7 +4,9 @@ import 'package:toolbox/core/extension/uint8list.dart';
import 'package:toolbox/core/provider_base.dart';
import 'package:toolbox/data/model/docker/ps.dart';
final dockerNotFound = RegExp(r'command not found|Unknown command');
final _dockerNotFound = RegExp(r'command not found|Unknown command');
final _versionReg = RegExp(r'(Version:)\s+([0-9]+\.[0-9]+\.[0-9]+)');
final _editionReg = RegExp(r'(Client:)\s+(.+-.+)');
class DockerProvider extends BusyProvider {
SSHClient? client;
@@ -31,32 +33,30 @@ class DockerProvider extends BusyProvider {
}
final verRaw = await client!.run('docker version'.withLangExport).string;
if (verRaw.contains(dockerNotFound)) {
if (verRaw.contains(_dockerNotFound)) {
error = 'docker not found';
notifyListeners();
return;
}
final verSplit = verRaw.split('\n');
if (verSplit.length < 3) {
error = 'invalid version';
notifyListeners();
return;
} else {
try {
version = verSplit[1].split(' ').last;
edition = verSplit[0].split(': ')[1];
} catch (e) {
error = e.toString();
return;
}
}
final raw = await client!.run('docker ps -a'.withLangExport).string;
version = _versionReg.firstMatch(verRaw)?.group(2);
edition = _editionReg.firstMatch(verRaw)?.group(2);
try {
final cmd = 'docker ps -a'.withLangExport;
final raw = await () async {
final raw = await client!.run(cmd).string;
if (raw.contains('permission denied')) {
return await client!
.run(
'export DOCKER_HOST=unix:///run/user/1000/docker.sock && $cmd')
.string;
}
return raw;
}();
final lines = raw.split('\n');
lines.removeAt(0);
lines.removeWhere((element) => element.isEmpty);
try {
items = lines.map((e) => DockerPsItem.fromRawString(e)).toList();
} catch (e) {
error = e.toString();

View File

@@ -41,8 +41,7 @@ const shellCmd = "export LANG=en_US.utf-8 \necho '$seperator' \n"
"cat /sys/class/thermal/thermal_zone*/type \necho $seperator \n"
"cat /sys/class/thermal/thermal_zone*/temp";
const shellPath = '.serverbox.sh';
const memPrefix = 'Mem:';
final cpuTempReg = RegExp('(x86_pkg_temp|cpu_thermal)');
final cpuTempReg = RegExp(r'(x86_pkg_temp|cpu_thermal)');
final numReg = RegExp(r'\s{1,}');
final memItemReg = RegExp(r'([A-Z].+:)\s+([0-9]+) kB');
@@ -274,7 +273,11 @@ class ServerProvider extends BusyProvider {
}
idx++;
}
return '${(int.parse(value.split('\n')[idx].trim()) / 1000).toStringAsFixed(1)}°C';
final valueSplited = value.split('\n');
if (idx >= valueSplited.length) return '';
final temp = int.tryParse(valueSplited[idx].trim());
if (temp == null) return '';
return '${(temp / 1000).toStringAsFixed(1)}°C';
}
void _getCPU(

View File

@@ -2,9 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 149;
static const int build = 151;
static const String engine =
"Flutter 3.0.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision fb57da5f94 (5 days ago) • 2022-05-19 15:50:29 -0700\nEngine • revision caaafc5604\nTools • Dart 2.17.1 • DevTools 2.12.2\n";
static const String buildAt = "2022-05-25 13:35:39.361656";
static const int modifications = 4;
"Flutter 3.0.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision fb57da5f94 (10 days ago) • 2022-05-19 15:50:29 -0700\nEngine • revision caaafc5604\nTools • Dart 2.17.1 • DevTools 2.12.2\n";
static const String buildAt = "2022-05-30 15:20:12.101899";
static const int modifications = 6;
}

View File

@@ -420,14 +420,14 @@
CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 149;
CURRENT_PROJECT_VERSION = 151;
DEVELOPMENT_TEAM = BA88US33G6;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.0.149;
MARKETING_VERSION = 1.0.151;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
@@ -550,14 +550,14 @@
CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 149;
CURRENT_PROJECT_VERSION = 151;
DEVELOPMENT_TEAM = BA88US33G6;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.0.149;
MARKETING_VERSION = 1.0.151;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@@ -574,14 +574,14 @@
CODE_SIGN_ENTITLEMENTS = Runner/Release.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 149;
CURRENT_PROJECT_VERSION = 151;
DEVELOPMENT_TEAM = BA88US33G6;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.0.149;
MARKETING_VERSION = 1.0.151;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;

View File

@@ -123,7 +123,7 @@ packages:
name: dartssh2
url: "https://pub.dartlang.org"
source: hosted
version: "2.7.0"
version: "2.7.1"
dio:
dependency: "direct main"
description:

View File

@@ -43,7 +43,7 @@ dependencies:
git:
url: https://github.com/Countly/countly-sdk-flutter-bridge.git
ref: master
dartssh2: ^2.7.0
dartssh2: ^2.7.1
logging: ^1.0.2
flutter_material_color_picker: ^1.1.0+2
circle_chart: