Skip to content

Commit 8cef09c

Browse files
committed
Add onAuthenticationChange callback to ServerSettingsPage and SettingsPage for profile picture updates
1 parent 9ddc4c6 commit 8cef09c

File tree

4 files changed

+70
-12
lines changed

4 files changed

+70
-12
lines changed

lib/desktop/features/settings/server/server_settings_page.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import 'widgets/authentication_info_card.dart';
99

1010
class ServerSettingsPage extends StatefulWidget {
1111
final AudioPlayerService? audioPlayerService;
12+
final VoidCallback? onAuthenticationChange;
1213

1314
const ServerSettingsPage({
1415
super.key,
1516
this.audioPlayerService,
17+
this.onAuthenticationChange,
1618
});
1719

1820
@override
@@ -205,6 +207,9 @@ class _ServerSettingsPageState extends State<ServerSettingsPage> {
205207

206208
await _loadServersAndLibraries();
207209

210+
// Notify main screen to refresh profile picture
211+
widget.onAuthenticationChange?.call();
212+
208213
if (mounted) {
209214
ScaffoldMessenger.of(context).showSnackBar(
210215
const SnackBar(
@@ -277,6 +282,9 @@ class _ServerSettingsPageState extends State<ServerSettingsPage> {
277282
_syncStatus = null;
278283
});
279284

285+
// Notify main screen to clear profile picture
286+
widget.onAuthenticationChange?.call();
287+
280288
if (mounted) {
281289
ScaffoldMessenger.of(context).showSnackBar(
282290
const SnackBar(content: Text('Disconnected from Plex')),

lib/desktop/features/settings/settings_page.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import 'server/server_settings_page.dart';
55
class SettingsPage extends StatelessWidget {
66
final void Function(Widget) onNavigate;
77
final AudioPlayerService? audioPlayerService;
8+
final VoidCallback? onAuthenticationChange;
89

910
const SettingsPage({
1011
super.key,
1112
required this.onNavigate,
1213
this.audioPlayerService,
14+
this.onAuthenticationChange,
1315
});
1416

1517
@override
@@ -27,6 +29,7 @@ class SettingsPage extends StatelessWidget {
2729
onTap: () {
2830
onNavigate(ServerSettingsPage(
2931
audioPlayerService: audioPlayerService,
32+
onAuthenticationChange: onAuthenticationChange,
3033
));
3134
},
3235
),

lib/desktop/shell/app_bar_actions.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'dart:io';
3+
import 'package:url_launcher/url_launcher.dart';
34

45
class AppBarActions extends StatelessWidget {
56
final VoidCallback? onNotificationsTap;
@@ -101,7 +102,7 @@ class AppBarActions extends StatelessWidget {
101102
onProfileTap?.call();
102103
break;
103104
case 'support':
104-
onSupportTap?.call();
105+
_launchSupportUrl();
105106
break;
106107
case 'private_session':
107108
onPrivateSessionTap?.call();
@@ -137,4 +138,11 @@ class AppBarActions extends StatelessWidget {
137138
: null,
138139
);
139140
}
141+
142+
Future<void> _launchSupportUrl() async {
143+
final url = Uri.parse('https://github.com/sponsors/j-convey');
144+
if (await canLaunchUrl(url)) {
145+
await launchUrl(url, mode: LaunchMode.externalApplication);
146+
}
147+
}
140148
}

lib/desktop/shell/main_screen.dart

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:obscurify/core/services/storage_service.dart';
77
import 'package:obscurify/core/services/plex/plex_services.dart';
88
import 'package:obscurify/core/services/plex_connection_resolver.dart';
99
import 'package:obscurify/core/services/authentication_check_service.dart';
10+
import 'package:obscurify/core/database/database_service.dart';
1011
import 'package:obscurify/desktop/features/authentication/presentation/authentication_modal.dart';
1112
import 'package:obscurify/desktop/features/home/home_page.dart';
1213
import '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

Comments
 (0)