File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,6 +32,15 @@ class IntegrationController extends MomentumController<IntegrationModel> {
3232 return _mal! ;
3333 }
3434
35+ void onReady () {
36+ mal.onLoggedIn ((getToken) async {
37+ model.update (loading: true );
38+ await getToken ();
39+ final profile = await mal.getUserProfile ();
40+ model.update (loading: false , malUsername: profile.name);
41+ });
42+ }
43+
3544 Future <String > getLoginUrl () async {
3645 model.update (loading: true );
3746 final result = await mal.getLoginUrl ();
Original file line number Diff line number Diff line change @@ -18,16 +18,26 @@ class MalService extends MalInterface {
1818 String _codeChallenge = '' ;
1919 String _authCode = '' ;
2020
21+ void Function (Future <void > Function () getToken)? loginCallback;
22+
2123 MalService () {
2224 linkStream.listen ((event) {
2325 _authCode = event ?? '' ;
2426 if (_authCode.isNotEmpty) {
25- _getToken ();
27+ if (loginCallback != null ) {
28+ loginCallback !(_getToken);
29+ } else {
30+ _getToken ();
31+ }
2632 }
2733 });
2834 _refreshAccessToken ();
2935 }
3036
37+ void onLoggedIn (void Function (Future <void > Function () getToken) callback) {
38+ loginCallback = callback;
39+ }
40+
3141 Future <void > _saveRefreshToken (String refreshToken) async {
3242 await sharedPreferences.setString ('MAL_REFRESH_TOKEN' , refreshToken);
3343 }
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ abstract class MalInterface extends MomentumService {
99
1010 Future <String > getLoginUrl ();
1111
12+ void onLoggedIn (void Function (Future <void > Function () getToken) callback);
13+
1214 Future <MalUserAnimeListResponse > getUserAnimeList ({required String status, required int offset});
1315
1416 Future <MalUserProfile > getUserProfile ();
Original file line number Diff line number Diff line change @@ -21,6 +21,11 @@ class MalMockService extends MalInterface {
2121 return '' ;
2222 }
2323
24+ @override
25+ void onLoggedIn (void Function (Future <void > Function () getToken) callback) {
26+ return ;
27+ }
28+
2429 @override
2530 Future <MalUserAnimeListResponse > getUserAnimeList ({required String status, required int offset}) async {
2631 const path = 'https://gist.githubusercontent.com/xamantra/2c6b8d8cec2004c5030753b08e65a981/raw/3d39b6e11cc4ce368e8f8ae8166c15207879b33a/mock_mal_user_animelist.json' ;
You can’t perform that action at this time.
0 commit comments