Skip to content

Commit 50fb54d

Browse files
authored
Merge pull request #109 from AGiXT/Issue#108
Changed login menu to use webview instead.
2 parents 0b8113b + e676c78 commit 50fb54d

File tree

9 files changed

+663
-2978
lines changed

9 files changed

+663
-2978
lines changed

lib/main.dart

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ import 'package:agixt/models/agixt/calendar.dart';
77
import 'package:agixt/models/agixt/checklist.dart';
88
import 'package:agixt/models/agixt/daily.dart';
99
import 'package:agixt/models/agixt/stop.dart';
10-
import 'package:agixt/screens/auth/login_screen.dart';
10+
import 'package:agixt/screens/auth/webview_login_screen.dart';
1111
import 'package:agixt/screens/auth/profile_screen.dart';
1212
import 'package:agixt/screens/privacy/privacy_consent_screen.dart';
1313
import 'package:agixt/services/bluetooth_manager.dart';
1414
import 'package:agixt/services/bluetooth_background_service.dart';
1515
import 'package:agixt/services/stops_manager.dart';
1616
import 'package:agixt/services/privacy_consent_service.dart';
1717
import 'package:agixt/services/system_notification_service.dart';
18-
import 'package:agixt/services/wallet_adapter_service.dart';
1918
import 'package:agixt/utils/ui_perfs.dart';
2019
import 'package:flutter/material.dart';
2120
import 'package:flutter/services.dart';
@@ -40,7 +39,7 @@ const String AGIXT_SERVER = String.fromEnvironment(
4039
);
4140
const String APP_URI = String.fromEnvironment(
4241
'APP_URI',
43-
defaultValue: 'https://agixt.dev',
42+
defaultValue: 'https://agixt.com',
4443
);
4544
const String PRIVACY_POLICY_URL =
4645
'https://agixt.com/docs/5-Reference/1-Privacy%20Policy';
@@ -56,12 +55,6 @@ void main() async {
5655
appName: APP_NAME,
5756
);
5857

59-
try {
60-
await WalletAdapterService.initialize(appUri: APP_URI, appName: APP_NAME);
61-
} catch (e) {
62-
debugPrint('Failed to initialize wallet adapter service: $e');
63-
}
64-
6558
// Initialize notifications with error handling
6659
try {
6760
await flutterLocalNotificationsPlugin.initialize(
@@ -226,13 +219,42 @@ class AppRetainWidget extends StatelessWidget {
226219
}
227220
}
228221

222+
/// Navigator observer that detects when /home route is pushed
223+
/// and syncs the root login state
224+
class _AuthNavigatorObserver extends NavigatorObserver {
225+
final VoidCallback onHomeRouteActivated;
226+
227+
_AuthNavigatorObserver({required this.onHomeRouteActivated});
228+
229+
@override
230+
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
231+
super.didPush(route, previousRoute);
232+
if (route.settings.name == '/home') {
233+
debugPrint('AuthNavigatorObserver: /home route pushed, syncing state');
234+
onHomeRouteActivated();
235+
}
236+
}
237+
238+
@override
239+
void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
240+
super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
241+
if (newRoute?.settings.name == '/home') {
242+
debugPrint('AuthNavigatorObserver: /home route replaced, syncing state');
243+
onHomeRouteActivated();
244+
}
245+
}
246+
}
247+
229248
class AGiXTApp extends StatefulWidget {
230249
const AGiXTApp({super.key});
231250

232251
// Global navigator key for accessing context from anywhere
233252
static final GlobalKey<NavigatorState> navigatorKey =
234253
GlobalKey<NavigatorState>();
235254

255+
// Static callback for WebViewLoginScreen to notify successful login
256+
static void Function()? onLoginSuccess;
257+
236258
@override
237259
State<AGiXTApp> createState() => _AGiXTAppState();
238260
}
@@ -249,10 +271,22 @@ class _AGiXTAppState extends State<AGiXTApp> {
249271
@override
250272
void initState() {
251273
super.initState();
274+
// Register the login success callback
275+
AGiXTApp.onLoginSuccess = _handleLoginSuccess;
252276
// Initialize with proper error handling
253277
_safeInitialization();
254278
}
255279

280+
/// Called by WebViewLoginScreen when login is successful
281+
void _handleLoginSuccess() {
282+
debugPrint('Main: onLoginSuccess callback triggered');
283+
if (mounted) {
284+
setState(() {
285+
_isLoggedIn = true;
286+
});
287+
}
288+
}
289+
256290
Future<void> _safeInitialization() async {
257291
try {
258292
final hasAccepted = await PrivacyConsentService.hasAcceptedLatestPolicy();
@@ -286,9 +320,16 @@ class _AGiXTAppState extends State<AGiXTApp> {
286320
return;
287321
}
288322

323+
// Re-check login status after privacy acceptance
324+
// This is important because the user may have logged in via WebView
325+
// before accepting privacy, and we need to update our local state
326+
final isLoggedIn = await AuthService.isLoggedIn();
327+
debugPrint('After privacy acceptance, isLoggedIn = $isLoggedIn');
328+
289329
setState(() {
290330
_hasAcceptedPrivacy = true;
291331
_privacyAcceptedAt = acceptedAt;
332+
_isLoggedIn = isLoggedIn;
292333
});
293334
} catch (e) {
294335
debugPrint('Error recording privacy acceptance: $e');
@@ -336,6 +377,7 @@ class _AGiXTAppState extends State<AGiXTApp> {
336377

337378
@override
338379
void dispose() {
380+
AGiXTApp.onLoginSuccess = null;
339381
_deepLinkSubscription?.cancel();
340382

341383
// Clean up all singletons and services with error handling
@@ -459,6 +501,18 @@ class _AGiXTAppState extends State<AGiXTApp> {
459501
}
460502
}
461503

504+
/// Called by navigator observer when /home route is activated
505+
/// This syncs the root state with the actual auth state
506+
void _syncLoginState() async {
507+
final isLoggedIn = await AuthService.isLoggedIn();
508+
debugPrint('Main: Navigator detected /home route, syncing state. isLoggedIn=$isLoggedIn');
509+
if (mounted && isLoggedIn != _isLoggedIn) {
510+
setState(() {
511+
_isLoggedIn = isLoggedIn;
512+
});
513+
}
514+
}
515+
462516
Future<void> _initDeepLinkHandling() async {
463517
try {
464518
// Handle links that opened the app
@@ -579,6 +633,7 @@ class _AGiXTAppState extends State<AGiXTApp> {
579633
),
580634
themeMode: ThemeMode.system,
581635
home: _buildHome(),
636+
navigatorObservers: [_AuthNavigatorObserver(onHomeRouteActivated: _syncLoginState)],
582637
routes: {
583638
'/home': (context) {
584639
final args =
@@ -591,7 +646,7 @@ class _AGiXTAppState extends State<AGiXTApp> {
591646
startVoiceInput: startVoiceInput,
592647
);
593648
},
594-
'/login': (context) => const LoginScreen(),
649+
'/login': (context) => const WebViewLoginScreen(),
595650
'/profile': (context) => const ProfileScreen(),
596651
},
597652
);
@@ -638,7 +693,7 @@ class _AGiXTAppState extends State<AGiXTApp> {
638693
}
639694

640695
return AppRetainWidget(
641-
child: _isLoggedIn ? const HomePage() : const LoginScreen(),
696+
child: _isLoggedIn ? const HomePage() : const WebViewLoginScreen(),
642697
);
643698
} catch (e) {
644699
debugPrint('Error building home widget: $e');

lib/models/agixt/auth/oauth.dart

Lines changed: 0 additions & 122 deletions
This file was deleted.

0 commit comments

Comments
 (0)