From cf1c9643b9cbad97ff3ee1faacc2be73ec3b05a5 Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Thu, 10 Aug 2023 00:37:51 +0800 Subject: [PATCH] opt.: check client before route pushed --- ios/Runner.xcodeproj/project.pbxproj | 24 ++++++++++++------------ lib/core/route.dart | 18 ++++++++++++++++++ lib/data/res/build_data.dart | 6 +++--- lib/main.dart | 8 +------- lib/view/page/pkg.dart | 2 +- lib/view/page/server/tab.dart | 24 ++++++++++++++++++++---- lib/view/page/storage/sftp.dart | 17 +++++++---------- macos/Runner.xcodeproj/project.pbxproj | 12 ++++++------ 8 files changed, 68 insertions(+), 43 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 532676f3..238e398d 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -470,7 +470,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 457; + CURRENT_PROJECT_VERSION = 458; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; @@ -478,7 +478,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.457; + MARKETING_VERSION = 1.0.458; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -602,7 +602,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 457; + CURRENT_PROJECT_VERSION = 458; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; @@ -610,7 +610,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.457; + MARKETING_VERSION = 1.0.458; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -628,7 +628,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 457; + CURRENT_PROJECT_VERSION = 458; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; @@ -636,7 +636,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.457; + MARKETING_VERSION = 1.0.458; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -657,7 +657,7 @@ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 457; + CURRENT_PROJECT_VERSION = 458; DEVELOPMENT_TEAM = BA88US33G6; GCC_C_LANGUAGE_STANDARD = gnu11; GENERATE_INFOPLIST_FILE = YES; @@ -670,7 +670,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.0.457; + MARKETING_VERSION = 1.0.458; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget; @@ -696,7 +696,7 @@ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 457; + CURRENT_PROJECT_VERSION = 458; DEVELOPMENT_TEAM = BA88US33G6; GCC_C_LANGUAGE_STANDARD = gnu11; GENERATE_INFOPLIST_FILE = YES; @@ -709,7 +709,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.0.457; + MARKETING_VERSION = 1.0.458; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -732,7 +732,7 @@ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 457; + CURRENT_PROJECT_VERSION = 458; DEVELOPMENT_TEAM = BA88US33G6; GCC_C_LANGUAGE_STANDARD = gnu11; GENERATE_INFOPLIST_FILE = YES; @@ -745,7 +745,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.0.457; + MARKETING_VERSION = 1.0.458; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/lib/core/route.dart b/lib/core/route.dart index c9263177..da325ee7 100644 --- a/lib/core/route.dart +++ b/lib/core/route.dart @@ -1,5 +1,10 @@ import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:toolbox/core/analysis.dart'; +import 'package:toolbox/data/provider/server.dart'; +import 'package:toolbox/locator.dart'; + +import 'utils/ui.dart'; class AppRoute { final Widget page; @@ -14,4 +19,17 @@ class AppRoute { MaterialPageRoute(builder: (context) => page), ); } + + Future checkClientAndGo({ + required BuildContext context, + required S s, + required String id, + }) { + final server = locator().servers[id]; + if (server == null || server.client == null) { + showSnackBar(context, Text(s.waitConnection)); + return Future.value(null); + } + return go(context); + } } diff --git a/lib/data/res/build_data.dart b/lib/data/res/build_data.dart index 06e722e1..ac056333 100644 --- a/lib/data/res/build_data.dart +++ b/lib/data/res/build_data.dart @@ -2,8 +2,8 @@ class BuildData { static const String name = "ServerBox"; - static const int build = 457; + static const int build = 458; static const String engine = "3.10.6"; - static const String buildAt = "2023-08-09 23:52:33.375014"; - static const int modifications = 30; + static const String buildAt = "2023-08-10 00:04:32.937108"; + static const int modifications = 5; } diff --git a/lib/main.dart b/lib/main.dart index a1987c56..587057a5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -83,17 +83,11 @@ void runInZone(void Function() body) { runZonedGuarded( body, - onError, + (obj, trace) => Analysis.recordException(trace), zoneSpecification: zoneSpec, ); } -void onError(Object obj, StackTrace stack) { - Analysis.recordException(stack); - _debug.addMultiline(obj, Colors.red); - _debug.addMultiline(stack, Colors.white); -} - Future main() async { runInZone(() async { await initApp(); diff --git a/lib/view/page/pkg.dart b/lib/view/page/pkg.dart index e3f000d6..0fe0051a 100644 --- a/lib/view/page/pkg.dart +++ b/lib/view/page/pkg.dart @@ -133,7 +133,7 @@ class _PkgManagePageState extends State } Widget _buildFAB(PkgProvider pkg) { - if (pkg.isBusy || (pkg.upgradeable?.isEmpty ?? true)) { + if (pkg.upgradeable?.isEmpty ?? true) { return nil; } return FloatingActionButton( diff --git a/lib/view/page/server/tab.dart b/lib/view/page/server/tab.dart index 48d179ea..8daffc04 100644 --- a/lib/view/page/server/tab.dart +++ b/lib/view/page/server/tab.dart @@ -311,10 +311,18 @@ class _ServerPageState extends State onSelected: (ServerTabMenuType value) async { switch (value) { case ServerTabMenuType.pkg: - AppRoute(PkgManagePage(spi), 'pkg manage').go(context); + AppRoute(PkgManagePage(spi), 'pkg manage').checkClientAndGo( + context: context, + s: _s, + id: spi.id, + ); break; case ServerTabMenuType.sftp: - AppRoute(SftpPage(spi), 'SFTP').go(context); + AppRoute(SftpPage(spi), 'SFTP').checkClientAndGo( + context: context, + s: _s, + id: spi.id, + ); break; case ServerTabMenuType.snippet: final provider = locator(); @@ -349,10 +357,18 @@ class _ServerPageState extends State AppRoute(ServerEditPage(spi: spi), 'Edit server info').go(context); break; case ServerTabMenuType.docker: - AppRoute(DockerManagePage(spi), 'Docker manage').go(context); + AppRoute(DockerManagePage(spi), 'Docker manage').checkClientAndGo( + context: context, + s: _s, + id: spi.id, + ); break; case ServerTabMenuType.process: - AppRoute(ProcessPage(spi: spi), 'process page').go(context); + AppRoute(ProcessPage(spi: spi), 'process page').checkClientAndGo( + context: context, + s: _s, + id: spi.id, + ); break; } }, diff --git a/lib/view/page/storage/sftp.dart b/lib/view/page/storage/sftp.dart index cd39681a..0d5d25a7 100644 --- a/lib/view/page/storage/sftp.dart +++ b/lib/view/page/storage/sftp.dart @@ -4,6 +4,7 @@ import 'dart:typed_data'; import 'package:dartssh2/dartssh2.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:logging/logging.dart'; import 'package:toolbox/core/extension/navigator.dart'; import 'package:toolbox/core/extension/sftpfile.dart'; import 'package:toolbox/data/res/misc.dart'; @@ -16,7 +17,6 @@ import '../../../core/extension/stringx.dart'; import '../../../core/route.dart'; import '../../../core/utils/misc.dart'; import '../../../core/utils/ui.dart'; -import '../../../data/model/server/server.dart'; import '../../../data/model/server/server_private_info.dart'; import '../../../data/model/sftp/absolute_path.dart'; import '../../../data/model/sftp/browser_status.dart'; @@ -54,9 +54,10 @@ class _SftpPageState extends State { late S _s; - ServerState? _state; SSHClient? _client; + final _logger = Logger('SFTP'); + @override void didChangeDependencies() { super.didChangeDependencies(); @@ -68,7 +69,6 @@ class _SftpPageState extends State { super.initState(); final serverProvider = locator(); _client = serverProvider.servers[widget.spi.id]?.client; - _state = serverProvider.servers[widget.spi.id]?.state; } @override @@ -270,10 +270,6 @@ class _SftpPageState extends State { } Widget _buildFileView() { - if (_client == null || _state != ServerState.connected) { - return centerLoading; - } - if (_status.isBusy) { return centerLoading; } @@ -665,8 +661,9 @@ class _SftpPageState extends State { _status.isBusy = false; }); } - } catch (e) { - await showRoundDialog( + } catch (e, trace) { + _logger.warning('list dir failed', e, trace); + Future.delayed(const Duration(milliseconds: 177), () => showRoundDialog( context: context, title: Text(_s.error), child: Text(e.toString()), @@ -676,7 +673,7 @@ class _SftpPageState extends State { child: Text(_s.ok), ) ], - ); + )); await _backward(); } } diff --git a/macos/Runner.xcodeproj/project.pbxproj b/macos/Runner.xcodeproj/project.pbxproj index 6db32eb8..e0a294e1 100644 --- a/macos/Runner.xcodeproj/project.pbxproj +++ b/macos/Runner.xcodeproj/project.pbxproj @@ -475,9 +475,9 @@ baseConfigurationReference = C1C758C41C4E208965A68933 /* Pods-RunnerTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - CURRENT_PROJECT_VERSION = 457; + CURRENT_PROJECT_VERSION = 458; GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0.457; + MARKETING_VERSION = 1.0.458; PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -490,9 +490,9 @@ baseConfigurationReference = 15AF97DF993E8968098D6EBE /* Pods-RunnerTests.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - CURRENT_PROJECT_VERSION = 457; + CURRENT_PROJECT_VERSION = 458; GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0.457; + MARKETING_VERSION = 1.0.458; PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -505,9 +505,9 @@ baseConfigurationReference = 7CFA7DE7FABA75685DFB6948 /* Pods-RunnerTests.profile.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - CURRENT_PROJECT_VERSION = 457; + CURRENT_PROJECT_VERSION = 458; GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0.457; + MARKETING_VERSION = 1.0.458; PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0;