Skip to content

Commit

Permalink
opt.: loading dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Feb 29, 2024
1 parent 2137bfb commit 183fc7f
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 225 deletions.
36 changes: 18 additions & 18 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 775;
CURRENT_PROJECT_VERSION = 778;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
Expand All @@ -596,7 +596,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.775;
MARKETING_VERSION = 1.0.778;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down Expand Up @@ -720,7 +720,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 775;
CURRENT_PROJECT_VERSION = 778;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
Expand All @@ -730,7 +730,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.775;
MARKETING_VERSION = 1.0.778;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand All @@ -748,7 +748,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 775;
CURRENT_PROJECT_VERSION = 778;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
Expand All @@ -758,7 +758,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.775;
MARKETING_VERSION = 1.0.778;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand All @@ -779,7 +779,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 775;
CURRENT_PROJECT_VERSION = 778;
DEVELOPMENT_TEAM = BA88US33G6;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -792,7 +792,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0.775;
MARKETING_VERSION = 1.0.778;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
Expand All @@ -818,7 +818,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 775;
CURRENT_PROJECT_VERSION = 778;
DEVELOPMENT_TEAM = BA88US33G6;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -831,7 +831,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0.775;
MARKETING_VERSION = 1.0.778;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -854,7 +854,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 775;
CURRENT_PROJECT_VERSION = 778;
DEVELOPMENT_TEAM = BA88US33G6;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -867,7 +867,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0.775;
MARKETING_VERSION = 1.0.778;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -890,7 +890,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 775;
CURRENT_PROJECT_VERSION = 778;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_PREVIEWS = YES;
Expand All @@ -902,7 +902,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.775;
MARKETING_VERSION = 1.0.778;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.WatchEnd;
Expand Down Expand Up @@ -931,7 +931,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 775;
CURRENT_PROJECT_VERSION = 778;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_PREVIEWS = YES;
Expand All @@ -943,7 +943,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.775;
MARKETING_VERSION = 1.0.778;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.WatchEnd;
PRODUCT_NAME = ServerBox;
Expand All @@ -969,7 +969,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 775;
CURRENT_PROJECT_VERSION = 778;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_PREVIEWS = YES;
Expand All @@ -981,7 +981,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.775;
MARKETING_VERSION = 1.0.778;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.WatchEnd;
PRODUCT_NAME = ServerBox;
Expand Down
25 changes: 23 additions & 2 deletions lib/core/extension/context/dialog.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:choice/choice.dart';
import 'package:flutter/material.dart';
import 'package:toolbox/core/extension/context/common.dart';
Expand All @@ -14,11 +16,13 @@ extension DialogX on BuildContext {
List<Widget>? actions,
Widget? title,
bool barrierDismiss = true,
void Function(BuildContext)? onContext,
}) async {
return await showDialog<T>(
context: this,
barrierDismissible: barrierDismiss,
builder: (_) {
builder: (ctx) {
onContext?.call(ctx);
return AlertDialog(
title: title,
content: child,
Expand All @@ -29,11 +33,28 @@ extension DialogX on BuildContext {
);
}

void showLoadingDialog({bool barrierDismiss = false}) {
Future<T> showLoadingDialog<T>({
required Future<T> Function() fn,
bool barrierDismiss = false,
}) async {
BuildContext? ctx;
showRoundDialog(
child: UIs.centerSizedLoading,
barrierDismiss: barrierDismiss,
onContext: (c) => ctx = c,
);

try {
return await fn();
} catch (e) {
rethrow;
} finally {
/// Wait for context to be unmounted
await Future.delayed(const Duration(milliseconds: 100));
if (ctx?.mounted == true) {
ctx?.pop();
}
}
}

Future<String?> showPwdDialog(
Expand Down
13 changes: 8 additions & 5 deletions lib/data/provider/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,13 @@ class ServerProvider extends ChangeNotifier {
// Write script to server
// by ssh
try {
await s.client?.runForOutput(ShellFunc.installShellCmd,
action: (session) async {
session.stdin.add(ShellFunc.allScript.uint8List);
}).string;
await s.client?.runForOutput(
ShellFunc.installShellCmd,
action: (session) async {
session.stdin.add(ShellFunc.allScript.uint8List);
session.stdin.close();
},
);
} on SSHAuthAbortError catch (e) {
TryLimiter.inc(sid);
s.status.err = e.toString();
Expand Down Expand Up @@ -387,7 +390,7 @@ class ServerProvider extends ChangeNotifier {
if (!systemType.isSegmentsLenMatch(segments.length)) {
TryLimiter.inc(sid);
s.status.err =
'Segments not match: expect ${systemType.segmentsLen}, got ${segments.length}';
'Segments not match: expect ${systemType.segmentsLen}, got ${segments.length}, raw:\n\n$raw';
_setServerState(s, ServerState.failed);
return;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/data/res/build_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

class BuildData {
static const String name = "ServerBox";
static const int build = 775;
static const String engine = "3.19.0";
static const String buildAt = "2024-02-23 09:28:28";
static const int modifications = 2;
static const int script = 38;
static const int build = 778;
static const String engine = "3.19.1";
static const String buildAt = "2024-02-26 16:30:57";
static const int modifications = 6;
static const int script = 40;
}
17 changes: 7 additions & 10 deletions lib/view/page/backup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ class BackupPage extends StatelessWidget {
}

try {
context.showLoadingDialog();
final backup =
await Computer.shared.start(Backup.fromJsonString, text.trim());
final backup = await context.showLoadingDialog(
fn: () => Computer.shared.start(Backup.fromJsonString, text.trim()),
);
if (backupFormatVersion != backup.version) {
context.showSnackBar(l10n.backupVersionNotMatch);
return;
Expand Down Expand Up @@ -261,8 +261,6 @@ class BackupPage extends StatelessWidget {
} catch (e, trace) {
Loggers.app.warning('Import backup failed', e, trace);
context.showSnackBar(e.toString());
} finally {
context.pop();
}
}

Expand Down Expand Up @@ -388,9 +386,10 @@ class BackupPage extends StatelessWidget {
}

try {
context.showLoadingDialog();
final backup =
await Computer.shared.start(Backup.fromJsonString, text.trim());
final backup = await context.showLoadingDialog(
fn: () => Computer.shared.start(Backup.fromJsonString, text.trim()),
);

if (backupFormatVersion != backup.version) {
context.showSnackBar(l10n.backupVersionNotMatch);
return;
Expand Down Expand Up @@ -418,8 +417,6 @@ class BackupPage extends StatelessWidget {
} catch (e, trace) {
Loggers.app.warning('Import backup failed', e, trace);
context.showSnackBar(e.toString());
} finally {
context.pop();
}
}
}
39 changes: 19 additions & 20 deletions lib/view/page/container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ class _ContainerPageState extends State<ContainerPage> {
title: TwoLineText(up: l10n.container, down: widget.spi.name),
actions: [
IconButton(
onPressed: () async {
context.showLoadingDialog();
await _container.refresh();
context.pop();
},
onPressed: () =>
context.showLoadingDialog(fn: () => _container.refresh()),
icon: const Icon(Icons.refresh),
)
],
Expand Down Expand Up @@ -393,9 +390,10 @@ class _ContainerPageState extends State<ContainerPage> {
TextButton(
onPressed: () async {
context.pop();
context.showLoadingDialog();
final result = await _container.run(cmd);
context.pop();

final result = await context.showLoadingDialog(
fn: () => _container.run(cmd),
);
if (result != null) {
context.showSnackBar(result.message ?? l10n.unknownError);
}
Expand Down Expand Up @@ -506,9 +504,10 @@ class _ContainerPageState extends State<ContainerPage> {
TextButton(
onPressed: () async {
context.pop();
context.showLoadingDialog();
final result = await _container.delete(id, force);
context.pop();

final result = await context.showLoadingDialog(
fn: () => _container.delete(id, force),
);
if (result != null) {
context.showRoundDialog(
title: Text(l10n.error),
Expand All @@ -522,9 +521,9 @@ class _ContainerPageState extends State<ContainerPage> {
);
break;
case ContainerMenu.start:
context.showLoadingDialog();
final result = await _container.start(id);
context.pop();
final result = await context.showLoadingDialog(
fn: () => _container.start(id),
);
if (result != null) {
context.showRoundDialog(
title: Text(l10n.error),
Expand All @@ -533,9 +532,9 @@ class _ContainerPageState extends State<ContainerPage> {
}
break;
case ContainerMenu.stop:
context.showLoadingDialog();
final result = await _container.stop(id);
context.pop();
final result = await context.showLoadingDialog(
fn: () => _container.stop(id),
);
if (result != null) {
context.showRoundDialog(
title: Text(l10n.error),
Expand All @@ -544,9 +543,9 @@ class _ContainerPageState extends State<ContainerPage> {
}
break;
case ContainerMenu.restart:
context.showLoadingDialog();
final result = await _container.restart(id);
context.pop();
final result = await context.showLoadingDialog(
fn: () => _container.restart(id),
);
if (result != null) {
context.showRoundDialog(
title: Text(l10n.error),
Expand Down
7 changes: 4 additions & 3 deletions lib/view/page/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ class _EditorPageState extends State<EditorPage> {
// If path is not null, then it's a file editor
// save the text and return true to pop the page
if (widget.path != null) {
context.showLoadingDialog();
await File(widget.path!).writeAsString(_controller.text);
context.pop();
await context.showLoadingDialog(
fn: () => File(widget.path!).writeAsString(_controller.text),
);

context.pop(true);
return;
}
Expand Down
Loading

0 comments on commit 183fc7f

Please sign in to comment.