From 3d0036a9268dbcee870cfe1546231d90b1e44515 Mon Sep 17 00:00:00 2001 From: appflowy Date: Thu, 28 Apr 2022 20:54:04 +0800 Subject: [PATCH] chore: show appflowy document path in debug info --- .../app_flowy/lib/startup/tasks/rust_sdk.dart | 38 +++-- .../widgets/float_bubble/question_bubble.dart | 135 ++++++++++-------- .../flowy-sync/src/client_folder/builder.rs | 6 +- shared-lib/lib-infra/src/util.rs | 7 +- 4 files changed, 95 insertions(+), 91 deletions(-) diff --git a/frontend/app_flowy/lib/startup/tasks/rust_sdk.dart b/frontend/app_flowy/lib/startup/tasks/rust_sdk.dart index 6621ec9c69..cdac0fa9e3 100644 --- a/frontend/app_flowy/lib/startup/tasks/rust_sdk.dart +++ b/frontend/app_flowy/lib/startup/tasks/rust_sdk.dart @@ -9,27 +9,21 @@ class InitRustSDKTask extends LaunchTask { @override Future initialize(LaunchContext context) async { - switch (context.env) { - case IntegrationMode.release: - Directory documentsDir = await getApplicationDocumentsDirectory(); - return Directory('${documentsDir.path}/flowy').create().then( - (Directory directory) async { - await context.getIt().init(directory); - }, - ); - case IntegrationMode.develop: - Directory documentsDir = await getApplicationDocumentsDirectory(); - return Directory('${documentsDir.path}/flowy_dev').create().then( - (Directory directory) async { - await context.getIt().init(directory); - }, - ); - case IntegrationMode.test: - final directory = Directory("${Directory.current.path}/.sandbox"); - await context.getIt().init(directory); - break; - default: - assert(false, 'Unsupported env'); - } + await appFlowyDocumentDirectory().then((directory) async { + await context.getIt().init(directory); + }); + } +} + +Future appFlowyDocumentDirectory() async { + Directory documentsDir = await getApplicationDocumentsDirectory(); + + switch (integrationEnv()) { + case IntegrationMode.develop: + return Directory('${documentsDir.path}/flowy_dev').create(); + case IntegrationMode.release: + return Directory('${documentsDir.path}/flowy').create(); + case IntegrationMode.test: + return Directory("${Directory.current.path}/.sandbox"); } } diff --git a/frontend/app_flowy/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart b/frontend/app_flowy/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart index 3309566eaf..00a10c0eb2 100644 --- a/frontend/app_flowy/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart +++ b/frontend/app_flowy/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart @@ -1,3 +1,4 @@ +import 'package:app_flowy/startup/tasks/rust_sdk.dart'; import 'package:app_flowy/workspace/presentation/home/home_stack.dart'; import 'package:app_flowy/workspace/presentation/widgets/pop_up_action.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -46,67 +47,7 @@ class QuestionBubble extends StatelessWidget { _launchURL("https://discord.gg/9Q2xaN37tV"); break; case BubbleAction.debug: - final deviceInfoPlugin = DeviceInfoPlugin(); - final deviceInfo = deviceInfoPlugin.deviceInfo; - - deviceInfo.then((info) { - var debugText = ""; - info.toMap().forEach((key, value) { - debugText = debugText + "$key: $value\n"; - }); - - Clipboard.setData(ClipboardData(text: debugText)); - - Widget toast = Container( - padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(25.0), - color: theme.main1, - ), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - const Icon(Icons.check), - const SizedBox( - width: 12.0, - ), - Text(LocaleKeys.questionBubble_debug_success.tr()), - ], - ), - ); - - fToast.showToast( - child: toast, - gravity: ToastGravity.BOTTOM, - toastDuration: const Duration(seconds: 3), - ); - }).catchError((error) { - Log.info("Debug info has not yet been implemented on this platform"); - - Widget toast = Container( - padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(25.0), - color: Colors.red, - ), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - const Icon(Icons.close), - const SizedBox( - width: 12.0, - ), - Text(LocaleKeys.questionBubble_debug_fail.tr()), - ], - ), - ); - - fToast.showToast( - child: toast, - gravity: ToastGravity.BOTTOM, - toastDuration: const Duration(seconds: 3), - ); - }, test: (e) => e is UnimplementedError); + const _DebugToast().show(); break; } }); @@ -130,6 +71,78 @@ class QuestionBubble extends StatelessWidget { } } +class _DebugToast extends StatelessWidget { + const _DebugToast({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return FutureBuilder( + future: Future(() async { + var debugInfo = ""; + debugInfo += await _getDeviceInfo(); + debugInfo += await _getDocumentPath(); + + Clipboard.setData(ClipboardData(text: debugInfo)); + }), + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + if (snapshot.hasError) { + return _done(context, Text("Error: ${snapshot.error}")); + } else { + return _done(context, null); + } + } else { + return const CircularProgressIndicator(); + } + }, + ); + } + + Widget _done(BuildContext context, Widget? error) { + final theme = context.watch(); + return Container( + padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0), + decoration: BoxDecoration(borderRadius: BorderRadius.circular(25.0), color: theme.main1), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + const Icon(Icons.check), + const SizedBox(width: 12.0), + (error == null) ? Text(LocaleKeys.questionBubble_debug_success.tr()) : error + ], + ), + ); + } + + void show() { + fToast.showToast( + child: this, + gravity: ToastGravity.BOTTOM, + toastDuration: const Duration(seconds: 3), + ); + } + + Future _getDeviceInfo() async { + final deviceInfoPlugin = DeviceInfoPlugin(); + final deviceInfo = deviceInfoPlugin.deviceInfo; + + return deviceInfo.then((info) { + var debugText = ""; + info.toMap().forEach((key, value) { + debugText = debugText + "$key: $value\n"; + }); + return debugText; + }); + } + + Future _getDocumentPath() async { + return appFlowyDocumentDirectory().then((directory) { + final path = directory.path.toString(); + return "Document: $path\n"; + }); + } +} + class QuestionBubbleActionSheet with ActionList, FlowyOverlayDelegate { final Function(dartz.Option) onSelected; final _items = BubbleAction.values.map((action) => BubbleActionWrapper(action)).toList(); diff --git a/shared-lib/flowy-sync/src/client_folder/builder.rs b/shared-lib/flowy-sync/src/client_folder/builder.rs index 22174de348..9858600c6e 100644 --- a/shared-lib/flowy-sync/src/client_folder/builder.rs +++ b/shared-lib/flowy-sync/src/client_folder/builder.rs @@ -41,8 +41,10 @@ impl FolderPadBuilder { // TODO: Reconvert from history if delta.to_str() failed. let folder_json = delta.to_str()?; - let mut folder: FolderPad = serde_json::from_str(&folder_json) - .map_err(|e| CollaborateError::internal().context(format!("Deserialize delta to folder failed: {}", e)))?; + let mut folder: FolderPad = serde_json::from_str(&folder_json).map_err(|e| { + tracing::error!("Deserialize folder from json failed: {}", folder_json); + return CollaborateError::internal().context(format!("Deserialize delta to folder failed: {}", e)); + })?; folder.delta = delta; Ok(folder) } diff --git a/shared-lib/lib-infra/src/util.rs b/shared-lib/lib-infra/src/util.rs index 3d26cfa3f9..8802c60d61 100644 --- a/shared-lib/lib-infra/src/util.rs +++ b/shared-lib/lib-infra/src/util.rs @@ -1,9 +1,4 @@ -pub fn move_vec_element( - vec: &mut Vec, - filter: F, - _from_index: usize, - mut to_index: usize, -) -> Result +pub fn move_vec_element(vec: &mut Vec, filter: F, _from_index: usize, to_index: usize) -> Result where F: FnMut(&T) -> bool, {