| 
									
										
										
										
											2023-10-12 20:25:00 +08:00
										 |  |  | import 'package:appflowy/env/env.dart'; | 
					
						
							|  |  |  | import 'package:appflowy/startup/startup.dart'; | 
					
						
							|  |  |  | import 'package:appflowy/user/application/user_auth_listener.dart'; | 
					
						
							| 
									
										
										
										
											2023-10-24 20:11:06 +08:00
										 |  |  | import 'package:appflowy_backend/log.dart'; | 
					
						
							| 
									
										
										
										
											2023-10-12 20:25:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class InitAppFlowyCloudTask extends LaunchTask { | 
					
						
							| 
									
										
										
										
											2023-10-24 23:13:51 +08:00
										 |  |  |   UserAuthStateListener? _authStateListener; | 
					
						
							| 
									
										
										
										
											2023-10-12 20:25:00 +08:00
										 |  |  |   bool isLoggingOut = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Future<void> initialize(LaunchContext context) async { | 
					
						
							|  |  |  |     if (!isAppFlowyCloudEnabled) { | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-10-24 23:13:51 +08:00
										 |  |  |     _authStateListener = UserAuthStateListener(); | 
					
						
							| 
									
										
										
										
											2023-10-12 20:25:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-24 23:13:51 +08:00
										 |  |  |     _authStateListener?.start( | 
					
						
							| 
									
										
										
										
											2023-10-12 20:25:00 +08:00
										 |  |  |       didSignIn: () { | 
					
						
							|  |  |  |         isLoggingOut = false; | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       onInvalidAuth: (message) async { | 
					
						
							| 
									
										
										
										
											2023-10-24 20:11:06 +08:00
										 |  |  |         Log.error(message); | 
					
						
							| 
									
										
										
										
											2023-10-12 20:25:00 +08:00
										 |  |  |         if (!isLoggingOut) { | 
					
						
							|  |  |  |           await runAppFlowy(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-10-24 23:13:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Future<void> dispose() async { | 
					
						
							|  |  |  |     await _authStateListener?.stop(); | 
					
						
							|  |  |  |     _authStateListener = null; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-10-12 20:25:00 +08:00
										 |  |  | } |