+20
-2
@@ -36,6 +36,7 @@ import 'services/server_registry.dart';
|
||||
import 'services/download_manager_service.dart';
|
||||
import 'services/pip_service.dart';
|
||||
import 'services/download_storage_service.dart';
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'services/plex_api_cache.dart';
|
||||
import 'database/app_database.dart';
|
||||
import 'utils/app_logger.dart';
|
||||
@@ -376,8 +377,14 @@ class _SetupScreenState extends State<SetupScreen> {
|
||||
final storage = await StorageService.getInstance();
|
||||
final registry = ServerRegistry(storage);
|
||||
|
||||
// Refresh servers from API to get updated connection info (IPs may change)
|
||||
await registry.refreshServersFromApi();
|
||||
// Check network connectivity early to fast-path airplane mode
|
||||
final connectivityResult = await Connectivity().checkConnectivity();
|
||||
final hasNetwork = !connectivityResult.contains(ConnectivityResult.none);
|
||||
|
||||
if (hasNetwork) {
|
||||
// Refresh servers from API to get updated connection info (IPs may change)
|
||||
await registry.refreshServersFromApi();
|
||||
}
|
||||
|
||||
// Load all configured servers
|
||||
final servers = await registry.getServers();
|
||||
@@ -391,6 +398,17 @@ class _SetupScreenState extends State<SetupScreen> {
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
// No network — skip connection attempts and go straight to offline mode
|
||||
if (!hasNetwork) {
|
||||
await context.read<DownloadProvider>().ensureInitialized();
|
||||
if (!mounted) return;
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const MainScreen(isOfflineMode: true)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final result = await ServerConnectionOrchestrator.connectAndInitialize(
|
||||
servers: servers,
|
||||
|
||||
@@ -51,7 +51,10 @@ class PlexAuthService {
|
||||
|
||||
static Future<PlexAuthService> create() async {
|
||||
final storage = await StorageService.getInstance();
|
||||
final dio = Dio();
|
||||
final dio = Dio(BaseOptions(
|
||||
connectTimeout: ConnectionTimeouts.plexTvConnect,
|
||||
receiveTimeout: ConnectionTimeouts.plexTvReceive,
|
||||
));
|
||||
|
||||
// Get or create client identifier
|
||||
String? clientIdentifier = storage.getClientIdentifier();
|
||||
|
||||
@@ -17,4 +17,10 @@ class ConnectionTimeouts {
|
||||
|
||||
/// Dio receive timeout for streaming/large responses from a Plex server.
|
||||
static const receive = Duration(seconds: 120);
|
||||
|
||||
/// Dio connect timeout for plex.tv / clients.plex.tv API requests.
|
||||
static const plexTvConnect = Duration(seconds: 5);
|
||||
|
||||
/// Dio receive timeout for plex.tv / clients.plex.tv API responses.
|
||||
static const plexTvReceive = Duration(seconds: 10);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user