Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: dismiss settings dialog after signing in (#6324)

Lucas938abb396ea2
diff --git a/frontend/appflowy_flutter/lib/startup/startup.dart b/frontend/appflowy_flutter/lib/startup/startup.dart
index 3741380567..ac0dfbf88a 100644
--- a/frontend/appflowy_flutter/lib/startup/startup.dart
+++ b/frontend/appflowy_flutter/lib/startup/startup.dart
@@ -5,6 +5,7 @@ import 'package:appflowy/env/cloud_env.dart';
import 'package:appflowy/startup/tasks/feature_flag_task.dart';
import 'package:appflowy/workspace/application/settings/prelude.dart';
import 'package:appflowy_backend/appflowy_backend.dart';
+import 'package:appflowy_backend/log.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
@@ -30,6 +31,8 @@ class FlowyRunnerContext {
}
Future<void> runAppFlowy({bool isAnon = false}) async {
+ Log.info('restart AppFlowy: isAnon: $isAnon');
+
if (kReleaseMode) {
await FlowyRunner.run(
AppFlowyApplication(),
diff --git a/frontend/appflowy_flutter/lib/startup/tasks/appflowy_cloud_task.dart b/frontend/appflowy_flutter/lib/startup/tasks/appflowy_cloud_task.dart
index 5aad45b3c5..2c22b8a01e 100644
--- a/frontend/appflowy_flutter/lib/startup/tasks/appflowy_cloud_task.dart
+++ b/frontend/appflowy_flutter/lib/startup/tasks/appflowy_cloud_task.dart
@@ -1,8 +1,6 @@
import 'dart:async';
import 'dart:io';
-import 'package:flutter/material.dart';
-
import 'package:app_links/app_links.dart';
import 'package:appflowy/env/cloud_env.dart';
import 'package:appflowy/startup/startup.dart';
@@ -13,58 +11,60 @@ import 'package:appflowy/user/application/auth/device_id.dart';
import 'package:appflowy/user/application/user_auth_listener.dart';
import 'package:appflowy/workspace/application/subscription_success_listenable/subscription_success_listenable.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
+import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-error/code.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:appflowy_result/appflowy_result.dart';
+import 'package:flutter/material.dart';
import 'package:url_protocol/url_protocol.dart';
const appflowyDeepLinkSchema = 'appflowy-flutter';
class AppFlowyCloudDeepLink {
AppFlowyCloudDeepLink() {
- if (_deeplinkSubscription == null) {
- _deeplinkSubscription = _appLinks.uriLinkStream.listen(
- (Uri? uri) async {
- Log.info('onDeepLink: ${uri.toString()}');
- await _handleUri(uri);
- },
- onError: (Object err, StackTrace stackTrace) {
- Log.error('on DeepLink stream error: ${err.toString()}', stackTrace);
- _deeplinkSubscription?.cancel();
- _deeplinkSubscription = null;
- },
- );
- if (Platform.isWindows) {
- // register deep link for Windows
- registerProtocolHandler(appflowyDeepLinkSchema);
- }
- } else {
- _deeplinkSubscription?.resume();
+ _deepLinkSubscription = _AppLinkWrapper.instance.listen(
+ (Uri? uri) async {
+ Log.info('onDeepLink: ${uri.toString()}');
+ await _handleUri(uri);
+ },
+ onError: (Object err, StackTrace stackTrace) {
+ Log.error('on DeepLink stream error: ${err.toString()}', stackTrace);
+ _deepLinkSubscription.cancel();
+ },
+ );
+ if (Platform.isWindows) {
+ // register deep link for Windows
+ registerProtocolHandler(appflowyDeepLinkSchema);
}
}
- final _appLinks = AppLinks();
-
ValueNotifier<DeepLinkResult?>? _stateNotifier = ValueNotifier(null);
+
Completer<FlowyResult<UserProfilePB, FlowyError>>? _completer;
- // The AppLinks is a singleton, so we need to cancel the previous subscription
- // before creating a new one.
- static StreamSubscription<Uri?>? _deeplinkSubscription;
+ set completer(Completer<FlowyResult<UserProfilePB, FlowyError>>? value) {
+ Log.debug('AppFlowyCloudDeepLink: $hashCode completer');
+ _completer = value;
+ }
+
+ late final StreamSubscription<Uri?> _deepLinkSubscription;
Future<void> dispose() async {
- _deeplinkSubscription?.pause();
+ Log.debug('AppFlowyCloudDeepLink: $hashCode dispose');
+ await _deepLinkSubscription.cancel();
+
_stateNotifier?.dispose();
_stateNotifier = null;
+ completer = null;
}
void registerCompleter(
Completer<FlowyResult<UserProfilePB, FlowyError>> completer,
) {
- _completer = completer;
+ this.completer = completer;
}
VoidCallback subscribeDeepLinkLoadingState(
@@ -91,7 +91,7 @@ class AppFlowyCloudDeepLink {
if (uri == null) {
Log.error('onDeepLinkError: Unexpected empty deep link callback');
_completer?.complete(FlowyResult.failure(AuthError.emptyDeepLink));
- _completer = null;
+ completer = null;
return;
}
@@ -128,16 +128,16 @@ class AppFlowyCloudDeepLink {
Log.error(err);
final context = AppGlobals.rootNavKey.currentState?.context;
if (context != null) {
- showSnackBarMessage(
+ showToastNotification(
context,
- err.msg,
+ message: err.msg,
);
}
},
);
} else {
_completer?.complete(result);
- _completer = null;
+ completer = null;
}
},
(err) {
@@ -152,7 +152,7 @@ class AppFlowyCloudDeepLink {
}
} else {
_completer?.complete(FlowyResult.failure(err));
- _completer = null;
+ completer = null;
}
},
);
@@ -221,3 +221,35 @@ enum DeepLinkState {
loading,
finish,
}
+
+// wrapper for AppLinks to support multiple listeners
+class _AppLinkWrapper {
+ _AppLinkWrapper._() {
+ _appLinkSubscription = _appLinks.uriLinkStream.listen((event) {
+ _streamSubscription.sink.add(event);
+ });
+ }
+
+ static final _AppLinkWrapper instance = _AppLinkWrapper._();
+
+ final AppLinks _appLinks = AppLinks();
+ final _streamSubscription = StreamController<Uri?>.broadcast();
+ late final StreamSubscription<Uri?> _appLinkSubscription;
+
+ StreamSubscription<Uri?> listen(
+ void Function(Uri?) listener, {
+ Function? onError,
+ bool? cancelOnError,
+ }) {
+ return _streamSubscription.stream.listen(
+ listener,
+ onError: onError,
+ cancelOnError: cancelOnError,
+ );
+ }
+
+ void dispose() {
+ _streamSubscription.close();
+ _appLinkSubscription.cancel();
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/account/account_sign_in_out.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/account/account_sign_in_out.dart
index d897a7931b..54accfd6ce 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/account/account_sign_in_out.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/account/account_sign_in_out.dart
@@ -88,8 +88,16 @@ class _SignInDialogContent extends StatelessWidget {
const _OrDivider(),
const VSpace(10),
SettingThirdPartyLogin(
- didLogin: () {},
- ), // TODO: Pass onAction
+ didLogin: () {
+ // dismiss the setting dialog
+ Navigator.of(context).popUntil((route) {
+ if (route.settings.name == '/') {
+ return true;
+ }
+ return false;
+ });
+ },
+ ),
],
],
),
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_third_party_login.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_third_party_login.dart
index e623652f8b..cf51d7a3e9 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_third_party_login.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_third_party_login.dart
@@ -1,5 +1,3 @@
-import 'package:flutter/material.dart';
-
import 'package:appflowy/env/cloud_env.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/startup/startup.dart';
@@ -12,10 +10,14 @@ import 'package:appflowy_result/appflowy_result.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/snap_bar.dart';
+import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class SettingThirdPartyLogin extends StatelessWidget {
- const SettingThirdPartyLogin({required this.didLogin, super.key});
+ const SettingThirdPartyLogin({
+ super.key,
+ required this.didLogin,
+ });
final VoidCallback didLogin;