opt.: check client before route pushed

This commit is contained in:
lollipopkit
2023-08-10 00:37:51 +08:00
parent c512a6a274
commit cf1c9643b9
8 changed files with 68 additions and 43 deletions

View File

@@ -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)";

View File

@@ -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<T?> checkClientAndGo<T>({
required BuildContext context,
required S s,
required String id,
}) {
final server = locator<ServerProvider>().servers[id];
if (server == null || server.client == null) {
showSnackBar(context, Text(s.waitConnection));
return Future.value(null);
}
return go(context);
}
}

View File

@@ -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;
}

View File

@@ -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<void> main() async {
runInZone(() async {
await initApp();

View File

@@ -133,7 +133,7 @@ class _PkgManagePageState extends State<PkgManagePage>
}
Widget _buildFAB(PkgProvider pkg) {
if (pkg.isBusy || (pkg.upgradeable?.isEmpty ?? true)) {
if (pkg.upgradeable?.isEmpty ?? true) {
return nil;
}
return FloatingActionButton(

View File

@@ -311,10 +311,18 @@ class _ServerPageState extends State<ServerPage>
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<SnippetProvider>();
@@ -349,10 +357,18 @@ class _ServerPageState extends State<ServerPage>
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;
}
},

View File

@@ -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<SftpPage> {
late S _s;
ServerState? _state;
SSHClient? _client;
final _logger = Logger('SFTP');
@override
void didChangeDependencies() {
super.didChangeDependencies();
@@ -68,7 +69,6 @@ class _SftpPageState extends State<SftpPage> {
super.initState();
final serverProvider = locator<ServerProvider>();
_client = serverProvider.servers[widget.spi.id]?.client;
_state = serverProvider.servers[widget.spi.id]?.state;
}
@override
@@ -270,10 +270,6 @@ class _SftpPageState extends State<SftpPage> {
}
Widget _buildFileView() {
if (_client == null || _state != ServerState.connected) {
return centerLoading;
}
if (_status.isBusy) {
return centerLoading;
}
@@ -665,8 +661,9 @@ class _SftpPageState extends State<SftpPage> {
_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<SftpPage> {
child: Text(_s.ok),
)
],
);
));
await _backward();
}
}

View File

@@ -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;