From 6e8c3c821a165ad940cb5083df8ac4200e318e7c Mon Sep 17 00:00:00 2001 From: appflowy Date: Mon, 31 Jan 2022 08:24:29 +0800 Subject: [PATCH] remove splash interface --- .../lib/user/application/splash_bloc.dart | 16 +++- .../app_flowy/lib/user/domain/i_auth.dart | 10 --- .../app_flowy/lib/user/domain/i_splash.dart | 25 ------ .../user/infrastructure/deps_resolver.dart | 9 +-- .../user/infrastructure/i_splash_impl.dart | 79 ------------------- .../lib/user/infrastructure/router.dart | 50 +++++++++++- .../lib/user/presentation/sign_up_screen.dart | 4 +- .../user/presentation/skip_log_in_screen.dart | 2 +- .../lib/user/presentation/splash_screen.dart | 10 +-- .../Flutter/GeneratedPluginRegistrant.swift | 2 - frontend/app_flowy/pubspec.lock | 7 -- frontend/app_flowy/pubspec.yaml | 1 - 12 files changed, 70 insertions(+), 145 deletions(-) delete mode 100644 frontend/app_flowy/lib/user/domain/i_auth.dart delete mode 100644 frontend/app_flowy/lib/user/domain/i_splash.dart delete mode 100644 frontend/app_flowy/lib/user/infrastructure/i_splash_impl.dart diff --git a/frontend/app_flowy/lib/user/application/splash_bloc.dart b/frontend/app_flowy/lib/user/application/splash_bloc.dart index 00dd66a635..de6d56e998 100644 --- a/frontend/app_flowy/lib/user/application/splash_bloc.dart +++ b/frontend/app_flowy/lib/user/application/splash_bloc.dart @@ -1,17 +1,25 @@ import 'package:app_flowy/user/domain/auth_state.dart'; -import 'package:app_flowy/user/domain/i_splash.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'splash_bloc.freezed.dart'; class SplashBloc extends Bloc { - final ISplashUser authImpl; - SplashBloc(this.authImpl) : super(SplashState.initial()) { + SplashBloc() : super(SplashState.initial()) { on((event, emit) async { await event.map( getUser: (val) async { - final authState = await authImpl.currentUserProfile(); + final result = await UserEventCheckUser().send(); + final authState = result.fold( + (userProfile) { + return AuthState.authenticated(userProfile); + }, + (error) { + return AuthState.unauthenticated(error); + }, + ); + emit(state.copyWith(auth: authState)); }, ); diff --git a/frontend/app_flowy/lib/user/domain/i_auth.dart b/frontend/app_flowy/lib/user/domain/i_auth.dart deleted file mode 100644 index cff6b5d05f..0000000000 --- a/frontend/app_flowy/lib/user/domain/i_auth.dart +++ /dev/null @@ -1,10 +0,0 @@ -import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile; - -class NewUser { - UserProfile profile; - String workspaceId; - NewUser({ - required this.profile, - required this.workspaceId, - }); -} diff --git a/frontend/app_flowy/lib/user/domain/i_splash.dart b/frontend/app_flowy/lib/user/domain/i_splash.dart deleted file mode 100644 index 385d9e8ae6..0000000000 --- a/frontend/app_flowy/lib/user/domain/i_splash.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/protobuf.dart'; -import 'package:flutter/widgets.dart'; - -import 'auth_state.dart'; - -abstract class ISplashUser { - Future currentUserProfile(); -} - -abstract class ISplashUserWatch { - void startWatching({ - void Function(AuthState)? authStateCallback, - }); - - Future stopWatching(); -} - -abstract class ISplashRoute { - void pushSignInScreen(BuildContext context); - void pushSkipLoginScreen(BuildContext context); - - Future pushWelcomeScreen(BuildContext context, UserProfile profile); - void pushHomeScreen(BuildContext context, UserProfile profile, CurrentWorkspaceSetting workspaceSetting); -} diff --git a/frontend/app_flowy/lib/user/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/user/infrastructure/deps_resolver.dart index aaaa9f81b1..be1e7461a0 100644 --- a/frontend/app_flowy/lib/user/infrastructure/deps_resolver.dart +++ b/frontend/app_flowy/lib/user/infrastructure/deps_resolver.dart @@ -1,10 +1,8 @@ import 'package:app_flowy/user/application/sign_in_bloc.dart'; import 'package:app_flowy/user/application/sign_up_bloc.dart'; import 'package:app_flowy/user/application/splash_bloc.dart'; -import 'package:app_flowy/user/domain/i_splash.dart'; import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart'; -import 'package:app_flowy/user/infrastructure/i_auth_impl.dart'; -import 'package:app_flowy/user/infrastructure/i_splash_impl.dart'; +import 'package:app_flowy/user/infrastructure/router.dart'; import 'package:app_flowy/workspace/application/edit_pannel/edit_pannel_bloc.dart'; import 'package:app_flowy/workspace/application/home/home_bloc.dart'; import 'package:app_flowy/workspace/application/home/home_listen_bloc.dart'; @@ -25,11 +23,10 @@ class UserDepsResolver { getIt.registerFactory(() => SignInBloc(getIt())); getIt.registerFactory(() => SignUpBloc(getIt())); - getIt.registerFactory(() => SplashUserImpl()); - getIt.registerFactory(() => SplashRoute()); + getIt.registerFactory(() => SplashRoute()); getIt.registerFactory(() => HomeBloc()); getIt.registerFactory(() => EditPannelBloc()); - getIt.registerFactory(() => SplashBloc(getIt())); + getIt.registerFactory(() => SplashBloc()); getIt.registerFactoryParam((user, _) => HomeListenBloc( getIt(param1: user), diff --git a/frontend/app_flowy/lib/user/infrastructure/i_splash_impl.dart b/frontend/app_flowy/lib/user/infrastructure/i_splash_impl.dart deleted file mode 100644 index 6064c3a489..0000000000 --- a/frontend/app_flowy/lib/user/infrastructure/i_splash_impl.dart +++ /dev/null @@ -1,79 +0,0 @@ -import 'package:app_flowy/startup/startup.dart'; -import 'package:app_flowy/user/domain/auth_state.dart'; -import 'package:app_flowy/user/domain/i_splash.dart'; -import 'package:app_flowy/user/infrastructure/router.dart'; -import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart'; -import 'package:app_flowy/user/presentation/sign_in_screen.dart'; -import 'package:app_flowy/user/presentation/skip_log_in_screen.dart'; -import 'package:app_flowy/user/presentation/welcome_screen.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; -import 'package:app_flowy/workspace/presentation/home/home_screen.dart'; -import 'package:flowy_infra/time/duration.dart'; -import 'package:flowy_infra_ui/widget/route/animation.dart'; -import 'package:flowy_sdk/dispatch/dispatch.dart'; -import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/protobuf.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; - -class SplashUserImpl implements ISplashUser { - @override - Future currentUserProfile() { - final result = UserEventCheckUser().send(); - return result.then((result) { - return result.fold( - (userProfile) { - return AuthState.authenticated(userProfile); - }, - (error) { - return AuthState.unauthenticated(error); - }, - ); - }); - } -} - -class SplashRoute implements ISplashRoute { - @override - Future pushWelcomeScreen(BuildContext context, UserProfile user) async { - final repo = UserRepo(user: user); - final screen = WelcomeScreen(repo: repo); - final workspaceId = await Navigator.of(context).push( - PageRoutes.fade( - () => screen, - RouteDurations.slow.inMilliseconds * .001, - ), - ); - - pushHomeScreen(context, repo.user, workspaceId); - } - - @override - void pushHomeScreen(BuildContext context, UserProfile userProfile, CurrentWorkspaceSetting workspaceSetting) { - Navigator.push( - context, - PageRoutes.fade(() => HomeScreen(userProfile, workspaceSetting), RouteDurations.slow.inMilliseconds * .001), - ); - } - - @override - void pushSignInScreen(BuildContext context) { - Navigator.push( - context, - PageRoutes.fade(() => SignInScreen(router: getIt()), RouteDurations.slow.inMilliseconds * .001), - ); - } - - @override - void pushSkipLoginScreen(BuildContext context) { - Navigator.push( - context, - PageRoutes.fade( - () => SkipLogInScreen( - router: getIt(), - authRepo: getIt(), - ), - RouteDurations.slow.inMilliseconds * .001), - ); - } -} diff --git a/frontend/app_flowy/lib/user/infrastructure/router.dart b/frontend/app_flowy/lib/user/infrastructure/router.dart index 1bbb9e78d1..2fb15420b5 100644 --- a/frontend/app_flowy/lib/user/infrastructure/router.dart +++ b/frontend/app_flowy/lib/user/infrastructure/router.dart @@ -1,6 +1,10 @@ import 'package:app_flowy/startup/startup.dart'; -import 'package:app_flowy/user/domain/i_splash.dart'; +import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart'; +import 'package:app_flowy/user/presentation/sign_in_screen.dart'; import 'package:app_flowy/user/presentation/sign_up_screen.dart'; +import 'package:app_flowy/user/presentation/skip_log_in_screen.dart'; +import 'package:app_flowy/user/presentation/welcome_screen.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:app_flowy/workspace/presentation/home/home_screen.dart'; import 'package:flowy_infra/time/duration.dart'; import 'package:flowy_infra_ui/widget/route/animation.dart'; @@ -9,13 +13,12 @@ import 'package:flowy_sdk/protobuf/flowy-folder-data-model/protobuf.dart'; import 'package:flutter/material.dart'; class AuthRouter { - @override void pushForgetPasswordScreen(BuildContext context) { // TODO: implement showForgetPasswordScreen } void pushWelcomeScreen(BuildContext context, UserProfile userProfile) { - getIt().pushWelcomeScreen(context, userProfile); + getIt().pushWelcomeScreen(context, userProfile); } void pushSignUpScreen(BuildContext context) { @@ -33,3 +36,44 @@ class AuthRouter { ); } } + +class SplashRoute { + Future pushWelcomeScreen(BuildContext context, UserProfile user) async { + final repo = UserRepo(user: user); + final screen = WelcomeScreen(repo: repo); + final workspaceId = await Navigator.of(context).push( + PageRoutes.fade( + () => screen, + RouteDurations.slow.inMilliseconds * .001, + ), + ); + + pushHomeScreen(context, repo.user, workspaceId); + } + + void pushHomeScreen(BuildContext context, UserProfile userProfile, CurrentWorkspaceSetting workspaceSetting) { + Navigator.push( + context, + PageRoutes.fade(() => HomeScreen(userProfile, workspaceSetting), RouteDurations.slow.inMilliseconds * .001), + ); + } + + void pushSignInScreen(BuildContext context) { + Navigator.push( + context, + PageRoutes.fade(() => SignInScreen(router: getIt()), RouteDurations.slow.inMilliseconds * .001), + ); + } + + void pushSkipLoginScreen(BuildContext context) { + Navigator.push( + context, + PageRoutes.fade( + () => SkipLogInScreen( + router: getIt(), + authRepo: getIt(), + ), + RouteDurations.slow.inMilliseconds * .001), + ); + } +} diff --git a/frontend/app_flowy/lib/user/presentation/sign_up_screen.dart b/frontend/app_flowy/lib/user/presentation/sign_up_screen.dart index c38cd48e36..00c47a6326 100644 --- a/frontend/app_flowy/lib/user/presentation/sign_up_screen.dart +++ b/frontend/app_flowy/lib/user/presentation/sign_up_screen.dart @@ -1,6 +1,6 @@ import 'package:app_flowy/startup/startup.dart'; import 'package:app_flowy/user/application/sign_up_bloc.dart'; -import 'package:app_flowy/user/domain/i_auth.dart'; +import 'package:app_flowy/user/infrastructure/router.dart'; import 'package:app_flowy/user/presentation/widgets/background.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flowy_infra/theme.dart'; @@ -17,7 +17,7 @@ import 'package:flowy_infra/image.dart'; import 'package:app_flowy/generated/locale_keys.g.dart'; class SignUpScreen extends StatelessWidget { - final IAuthRouter router; + final AuthRouter router; const SignUpScreen({Key? key, required this.router}) : super(key: key); @override diff --git a/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart b/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart index 2f3dd8127b..cab4f4db38 100644 --- a/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart +++ b/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart @@ -1,4 +1,4 @@ -import 'package:app_flowy/user/infrastructure/i_auth_impl.dart'; +import 'package:app_flowy/user/infrastructure/router.dart'; import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart'; import 'package:app_flowy/user/presentation/widgets/background.dart'; import 'package:app_flowy/workspace/domain/i_user.dart'; diff --git a/frontend/app_flowy/lib/user/presentation/splash_screen.dart b/frontend/app_flowy/lib/user/presentation/splash_screen.dart index 9b43408935..aa66a58ffe 100644 --- a/frontend/app_flowy/lib/user/presentation/splash_screen.dart +++ b/frontend/app_flowy/lib/user/presentation/splash_screen.dart @@ -1,7 +1,7 @@ import 'package:app_flowy/startup/startup.dart'; import 'package:app_flowy/user/application/splash_bloc.dart'; import 'package:app_flowy/user/domain/auth_state.dart'; -import 'package:app_flowy/user/domain/i_splash.dart'; +import 'package:app_flowy/user/infrastructure/router.dart'; import 'package:flowy_log/flowy_log.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/errors.pb.dart'; @@ -47,11 +47,11 @@ class SplashScreen extends StatelessWidget { FolderEventReadCurWorkspace().send().then( (result) { return result.fold( - (workspaceSetting) => getIt().pushHomeScreen(context, userProfile, workspaceSetting), + (workspaceSetting) => getIt().pushHomeScreen(context, userProfile, workspaceSetting), (error) async { Log.error(error); assert(error.code == ErrorCode.RecordNotFound.value); - getIt().pushWelcomeScreen(context, userProfile); + getIt().pushWelcomeScreen(context, userProfile); }, ); }, @@ -59,8 +59,8 @@ class SplashScreen extends StatelessWidget { } void _handleUnauthenticated(BuildContext context, Unauthenticated result) { - // getIt().pushSignInScreen(context); - getIt().pushSkipLoginScreen(context); + // getIt().pushSignInScreen(context); + getIt().pushSkipLoginScreen(context); } } diff --git a/frontend/app_flowy/macos/Flutter/GeneratedPluginRegistrant.swift b/frontend/app_flowy/macos/Flutter/GeneratedPluginRegistrant.swift index da7d6b58e2..8d97942332 100644 --- a/frontend/app_flowy/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/frontend/app_flowy/macos/Flutter/GeneratedPluginRegistrant.swift @@ -6,7 +6,6 @@ import FlutterMacOS import Foundation import connectivity_plus_macos -import desktop_window import device_info_plus_macos import flowy_infra_ui import flowy_sdk @@ -18,7 +17,6 @@ import window_size func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin")) - DesktopWindowPlugin.register(with: registry.registrar(forPlugin: "DesktopWindowPlugin")) DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) FlowyInfraUIPlugin.register(with: registry.registrar(forPlugin: "FlowyInfraUIPlugin")) FlowySdkPlugin.register(with: registry.registrar(forPlugin: "FlowySdkPlugin")) diff --git a/frontend/app_flowy/pubspec.lock b/frontend/app_flowy/pubspec.lock index 394f0f66b1..e00e5ccb9f 100644 --- a/frontend/app_flowy/pubspec.lock +++ b/frontend/app_flowy/pubspec.lock @@ -260,13 +260,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.6.8" - desktop_window: - dependency: "direct main" - description: - name: desktop_window - url: "https://pub.dartlang.org" - source: hosted - version: "0.4.0" device_info_plus: dependency: "direct main" description: diff --git a/frontend/app_flowy/pubspec.yaml b/frontend/app_flowy/pubspec.yaml index 64836b38d3..206c60c5ba 100644 --- a/frontend/app_flowy/pubspec.yaml +++ b/frontend/app_flowy/pubspec.yaml @@ -58,7 +58,6 @@ dependencies: url: git://github.com/google/flutter-desktop-embedding.git path: plugins/window_size ref: e48abe7c3e9ebfe0b81622167c5201d4e783bb81 - desktop_window: ^0.4.0 sized_context: ^1.0.0+1 styled_widget: "^0.3.1" expandable: ^5.0.1