@@ -7,6 +7,7 @@ import 'package:obscurify/core/services/storage_service.dart';
77import 'package:obscurify/core/services/plex/plex_services.dart' ;
88import 'package:obscurify/core/services/plex_connection_resolver.dart' ;
99import 'package:obscurify/core/services/authentication_check_service.dart' ;
10+ import 'package:obscurify/core/database/database_service.dart' ;
1011import 'package:obscurify/desktop/features/authentication/presentation/authentication_modal.dart' ;
1112import 'package:obscurify/desktop/features/home/home_page.dart' ;
1213import 'package:obscurify/desktop/features/settings/settings_page.dart' ;
@@ -78,13 +79,60 @@ class _MainScreenState extends State<MainScreen> {
7879 _navigateToPage (SettingsPage (
7980 onNavigate: _navigateToPage,
8081 audioPlayerService: _audioPlayerService,
82+ onAuthenticationChange: _loadCredentials,
8183 ));
8284 }
8385
8486 void _onProfileTap () {
8587 _navigateToPage (ProfilePage (storageService: _storageService));
8688 }
8789
90+ Future <void > _onLogoutTap () async {
91+ final confirmed = await showDialog <bool >(
92+ context: context,
93+ builder: (context) => AlertDialog (
94+ title: const Text ('Sign Out' ),
95+ content: const Text ('Are you sure you want to sign out?' ),
96+ actions: [
97+ TextButton (
98+ onPressed: () => Navigator .pop (context, false ),
99+ child: const Text ('Cancel' ),
100+ ),
101+ TextButton (
102+ onPressed: () => Navigator .pop (context, true ),
103+ child: const Text ('Sign Out' ),
104+ ),
105+ ],
106+ ),
107+ );
108+
109+ if (confirmed == true ) {
110+ // Stop and clear the player
111+ await _audioPlayerService.stop ();
112+
113+ // Clear credentials and database
114+ await _storageService.clearPlexCredentials ();
115+ await DatabaseService ().clearAllData ();
116+
117+ // Clear profile picture state and reload
118+ setState (() {
119+ _profileImagePath = null ;
120+ _plexProfilePictureUrl = null ;
121+ _currentToken = null ;
122+ _currentServerUrl = null ;
123+ });
124+
125+ // Reload credentials to refresh UI
126+ await _loadCredentials ();
127+
128+ if (mounted) {
129+ ScaffoldMessenger .of (context).showSnackBar (
130+ const SnackBar (content: Text ('Signed out successfully' )),
131+ );
132+ }
133+ }
134+ }
135+
88136 Future <void > _loadCredentials () async {
89137 await _resolver.initialise ();
90138 _currentToken = _resolver.userToken;
@@ -106,17 +154,7 @@ class _MainScreenState extends State<MainScreen> {
106154 if (mounted) {
107155 setState (() {
108156 _sidePanelKey = UniqueKey (); // Force SidePanel to rebuild
109- _currentPage = HomePage (
110- onNavigate: _navigateToPage,
111- audioPlayerService: _audioPlayerService,
112- storageService: _storageService,
113- token: _currentToken,
114- serverUrl: _currentServerUrl,
115- onHomeTap: _onHomeTap,
116- onSettingsTap: _onSettingsTap,
117- onProfileTap: _onProfileTap,
118- );
119- _navigationHistory[_currentHistoryIndex] = _currentPage;
157+ // Note: Don't change _currentPage here - stay on current page
120158 });
121159 }
122160 }
@@ -186,6 +224,7 @@ class _MainScreenState extends State<MainScreen> {
186224 onHomeTap: _onHomeTap,
187225 onSettingsTap: _onSettingsTap,
188226 onProfileTap: _onProfileTap,
227+ onLogoutTap: _onLogoutTap,
189228 profileImagePath: _profileImagePath,
190229 plexProfilePictureUrl: _plexProfilePictureUrl,
191230 ),
0 commit comments