fix: remove dead state paths and restore track hotkeys

This commit is contained in:
edde746
2026-03-06 11:50:45 +01:00
parent 581f665f58
commit c9a1bc97c4
10 changed files with 19 additions and 136 deletions
-2
View File
@@ -19,7 +19,6 @@ import 'services/discord_rpc_service.dart';
import 'services/gamepad_service.dart';
import 'providers/user_profile_provider.dart';
import 'providers/multi_server_provider.dart';
import 'providers/server_state_provider.dart';
import 'providers/theme_provider.dart';
import 'providers/settings_provider.dart';
import 'providers/hidden_libraries_provider.dart';
@@ -326,7 +325,6 @@ class _MainAppState extends State<MainApp> with WidgetsBindingObserver {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => MultiServerProvider(_serverManager, _aggregationService)),
ChangeNotifierProvider(create: (context) => ServerStateProvider()),
// Offline mode provider - depends on MultiServerProvider
ChangeNotifierProxyProvider<MultiServerProvider, OfflineModeProvider>(
create: (_) {
+1 -6
View File
@@ -80,17 +80,12 @@ class LibrariesProvider extends ChangeNotifier {
}
}
/// Refresh libraries by clearing cache and reloading.
/// Refresh libraries by reloading from the connected servers.
Future<void> refresh() async {
if (_aggregationService == null) {
appLogger.w('LibrariesProvider: Cannot refresh - not initialized');
return;
}
// Clear aggregation service cache
_aggregationService!.clearCache();
// Reload libraries
await loadLibraries();
}
-2
View File
@@ -87,7 +87,6 @@ class MultiServerProvider extends ChangeNotifier {
/// Clear all server connections
void clearAllConnections() {
_serverManager.disconnectAll();
_aggregationService.clearCache(); // Clear cached data when servers change
appLogger.d('MultiServerProvider: All connections cleared');
notifyListeners();
}
@@ -97,7 +96,6 @@ class MultiServerProvider extends ChangeNotifier {
Future<int> reconnectWithServers(List<PlexServer> servers, {String? clientIdentifier}) async {
// Clear existing connections first
_serverManager.disconnectAll();
_aggregationService.clearCache(); // Clear cached data when servers change
appLogger.d('MultiServerProvider: Cleared connections, reconnecting to ${servers.length} servers');
// Connect with new server tokens
-32
View File
@@ -1,32 +0,0 @@
import 'package:flutter/foundation.dart';
/// Provider for tracking server-specific UI state
/// Manages which server is currently in context for detail views
class ServerStateProvider extends ChangeNotifier {
String? _currentServerId;
/// Get the currently selected server ID (for detail views)
String? get currentServerId => _currentServerId;
/// Set the current server context (e.g., when viewing a library from a specific server)
void setCurrentServer(String? serverId) {
if (_currentServerId != serverId) {
_currentServerId = serverId;
notifyListeners();
}
}
/// Clear the current server selection
void clearCurrentServer() {
if (_currentServerId != null) {
_currentServerId = null;
notifyListeners();
}
}
/// Reset all state
void reset() {
_currentServerId = null;
notifyListeners();
}
}
-80
View File
@@ -375,86 +375,6 @@ class UserProfileProvider extends ChangeNotifier {
}
}
/// Refresh provider for new server context
/// Call this when switching servers to ensure provider state is synchronized
Future<void> refreshForNewServer([BuildContext? context]) async {
appLogger.d('UserProfileProvider: Refreshing for new server context');
_setLoading(true);
try {
// Clear cached data from previous server (both memory and storage)
_home = null;
_currentUser = null;
_profileSettings = null;
_clearError();
// Re-initialize services with current storage state
_authService = await PlexAuthService.create();
_storageService = await StorageService.getInstance();
// Clear storage state that's specific to the previous server context
await Future.wait([
// Clear home users cache (server-specific)
_storageService!.clearHomeUsersCache(),
// Clear current user UUID (profile-specific, should not persist across servers)
_storageService!.clearCurrentUserUUID(),
]);
appLogger.d('UserProfileProvider: Cleared previous server storage state');
// Load fresh data for the new server (should be empty after clearing cache)
await _loadCachedData();
// Load from API since we cleared the cache
appLogger.d('UserProfileProvider: Loading fresh home users for new server');
// Store context reference before async operations to avoid build context warnings
final contextForSwitch = context;
try {
await loadHomeUsers();
// After loading home users, if a current user was set (admin user),
// perform a complete profile switch to ensure tokens are properly updated
if (_currentUser != null && contextForSwitch != null) {
appLogger.d(
'UserProfileProvider: Performing complete profile switch to ${_currentUser!.displayName} for new server',
);
// Perform full profile switch which includes API calls and token updates
final userToSwitchTo = _currentUser!;
// ignore: use_build_context_synchronously - context is checked via mounted guard above
final success = await switchToUser(userToSwitchTo, contextForSwitch);
if (success) {
appLogger.d('UserProfileProvider: Successfully switched to admin user for new server');
} else {
appLogger.w('UserProfileProvider: Failed to complete profile switch for new server');
}
} else if (_currentUser != null && contextForSwitch == null) {
appLogger.w('UserProfileProvider: Cannot perform complete profile switch - no context provided');
// Still try to fetch profile settings even without full switch
try {
await refreshProfileSettings();
} catch (e) {
appLogger.w('UserProfileProvider: Failed to refresh profile settings for new server', error: e);
}
}
} catch (e) {
appLogger.w('UserProfileProvider: Failed to load home users for new server', error: e);
// Don't set error as it's not critical
}
appLogger.d('UserProfileProvider: Refresh for new server complete');
} catch (e) {
appLogger.e('UserProfileProvider: Failed to refresh for new server', error: e);
_setError('Failed to refresh for new server');
} finally {
_setLoading(false);
}
}
void _setLoading(bool loading) {
_isLoading = loading;
notifyListeners();
-3
View File
@@ -17,7 +17,6 @@ import '../models/plex_metadata.dart';
import '../utils/content_utils.dart';
import '../models/plex_hub.dart';
import '../providers/multi_server_provider.dart';
import '../providers/server_state_provider.dart';
import '../providers/hidden_libraries_provider.dart';
import '../providers/playback_state_provider.dart';
import 'profile/user_avatar_widget.dart';
@@ -742,14 +741,12 @@ class _DiscoverScreenState extends State<DiscoverScreen>
// Use comprehensive logout through UserProfileProvider
final userProfileProvider = Provider.of<UserProfileProvider>(context, listen: false);
final multiServerProvider = context.read<MultiServerProvider>();
final serverStateProvider = context.read<ServerStateProvider>();
final hiddenLibrariesProvider = context.read<HiddenLibrariesProvider>();
final playbackStateProvider = context.read<PlaybackStateProvider>();
// Clear all user data and provider states
await userProfileProvider.logout();
multiServerProvider.clearAllConnections();
serverStateProvider.reset();
await hiddenLibrariesProvider.refresh();
playbackStateProvider.clearShuffle();
-3
View File
@@ -21,7 +21,6 @@ import '../widgets/overlay_sheet.dart';
import '../mixins/tab_visibility_aware.dart';
import '../navigation/navigation_tabs.dart';
import '../providers/multi_server_provider.dart';
import '../providers/server_state_provider.dart';
import '../providers/hidden_libraries_provider.dart';
import '../providers/libraries_provider.dart';
import '../providers/playback_state_provider.dart';
@@ -826,7 +825,6 @@ class _MainScreenState extends State<MainScreen> with RouteAware, WindowListener
// Get all providers
final multiServerProvider = context.read<MultiServerProvider>();
final serverStateProvider = context.read<ServerStateProvider>();
final hiddenLibrariesProvider = context.read<HiddenLibrariesProvider>();
final librariesProvider = context.read<LibrariesProvider>();
final playbackStateProvider = context.read<PlaybackStateProvider>();
@@ -854,7 +852,6 @@ class _MainScreenState extends State<MainScreen> with RouteAware, WindowListener
}
// Reset other provider states
serverStateProvider.reset();
hiddenLibrariesProvider.refresh();
playbackStateProvider.clearShuffle();
+2
View File
@@ -2694,6 +2694,8 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
onTogglePIPMode: _togglePIPMode,
boxFitMode: _videoFilterManager?.boxFitMode ?? 0,
onCycleBoxFitMode: _cycleBoxFitMode,
onCycleAudioTrack: _cycleAudioTrack,
onCycleSubtitleTrack: _cycleSubtitleTrack,
onAudioTrackChanged: _onAudioTrackChanged,
onSubtitleTrackChanged: _onSubtitleTrackChanged,
onSecondarySubtitleTrackChanged: _onSecondarySubtitleTrackChanged,
@@ -15,10 +15,6 @@ class DataAggregationService {
DataAggregationService(this._serverManager);
/// Clear any cached data (for compatibility with existing callers)
// ignore: no-empty-block - stub, no cache to clear in current implementation
void clearCache() {}
/// Fetch libraries from all online servers
/// Libraries are automatically tagged with server info by PlexClient
Future<List<PlexLibrary>> getLibrariesFromAllServers() async {
+16 -4
View File
@@ -69,6 +69,8 @@ Widget plexVideoControlsBuilder(
VoidCallback? onTogglePIPMode,
int boxFitMode = 0,
VoidCallback? onCycleBoxFitMode,
VoidCallback? onCycleAudioTrack,
VoidCallback? onCycleSubtitleTrack,
Function(AudioTrack)? onAudioTrackChanged,
Function(SubtitleTrack)? onSubtitleTrackChanged,
Function(SubtitleTrack)? onSecondarySubtitleTrackChanged,
@@ -96,6 +98,8 @@ Widget plexVideoControlsBuilder(
boxFitMode: boxFitMode,
onTogglePIPMode: onTogglePIPMode,
onCycleBoxFitMode: onCycleBoxFitMode,
onCycleAudioTrack: onCycleAudioTrack,
onCycleSubtitleTrack: onCycleSubtitleTrack,
onAudioTrackChanged: onAudioTrackChanged,
onSubtitleTrackChanged: onSubtitleTrackChanged,
onSecondarySubtitleTrackChanged: onSecondarySubtitleTrackChanged,
@@ -125,6 +129,8 @@ class PlexVideoControls extends StatefulWidget {
final int boxFitMode;
final VoidCallback? onTogglePIPMode;
final VoidCallback? onCycleBoxFitMode;
final VoidCallback? onCycleAudioTrack;
final VoidCallback? onCycleSubtitleTrack;
final Function(AudioTrack)? onAudioTrackChanged;
final Function(SubtitleTrack)? onSubtitleTrackChanged;
final Function(SubtitleTrack)? onSecondarySubtitleTrackChanged;
@@ -179,6 +185,8 @@ class PlexVideoControls extends StatefulWidget {
this.boxFitMode = 0,
this.onTogglePIPMode,
this.onCycleBoxFitMode,
this.onCycleAudioTrack,
this.onCycleSubtitleTrack,
this.onAudioTrackChanged,
this.onSubtitleTrackChanged,
this.onSecondarySubtitleTrackChanged,
@@ -610,11 +618,15 @@ class _PlexVideoControlsState extends State<PlexVideoControls> with WindowListen
}
}
// ignore: no-empty-block - stub for future track cycling implementation
void _nextAudioTrack() {}
void _nextAudioTrack() {
if (!widget.canControl) return;
widget.onCycleAudioTrack?.call();
}
// ignore: no-empty-block - stub for future track cycling implementation
void _nextSubtitleTrack() {}
void _nextSubtitleTrack() {
if (!widget.canControl) return;
widget.onCycleSubtitleTrack?.call();
}
void _nextChapter() {
// Go to next chapter - this would use your existing chapter navigation