From a5063a662ef8eb7f3f741af6ca4c24a0962f1e0a Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Wed, 29 Oct 2025 14:04:39 +0100 Subject: [PATCH] refactor: remove dead code --- lib/auth/plex_auth.dart | 111 ---------------------------- lib/client/plex_client.dart | 14 ---- lib/screens/discover_screen.dart | 6 +- lib/services/plex_auth_service.dart | 23 ------ lib/theme/mono_theme.dart | 15 +++- lib/utils/plex_headers.dart | 37 ---------- pubspec.lock | 76 +------------------ pubspec.yaml | 4 - 8 files changed, 21 insertions(+), 265 deletions(-) delete mode 100644 lib/auth/plex_auth.dart delete mode 100644 lib/utils/plex_headers.dart diff --git a/lib/auth/plex_auth.dart b/lib/auth/plex_auth.dart deleted file mode 100644 index b8cfb598..00000000 --- a/lib/auth/plex_auth.dart +++ /dev/null @@ -1,111 +0,0 @@ -import 'dart:convert'; -import 'package:http/http.dart' as http; - -class PlexAuth { - static const String authUrl = 'https://plex.tv/api/v2'; - static const String clientsUrl = 'https://clients.plex.tv/api/v2'; - - final String clientIdentifier; - final String product; - - PlexAuth({ - required this.clientIdentifier, - this.product = 'Plex Flutter Client', - }); - - Map get _headers => { - 'Accept': 'application/json', - 'X-Plex-Client-Identifier': clientIdentifier, - 'X-Plex-Product': product, - }; - - /// Generate a PIN for authentication - Future> generatePin({bool strong = true}) async { - final response = await http.post( - Uri.parse('$authUrl/pins?strong=$strong'), - headers: _headers, - ); - - if (response.statusCode == 201) { - return json.decode(response.body); - } else { - throw Exception('Failed to generate PIN: ${response.body}'); - } - } - - /// Check PIN status - Future> checkPin(int pinId) async { - final response = await http.get( - Uri.parse('$authUrl/pins/$pinId'), - headers: _headers, - ); - - if (response.statusCode == 200) { - return json.decode(response.body); - } else { - throw Exception('Failed to check PIN: ${response.body}'); - } - } - - /// Get auth app URL for user to authenticate - String getAuthAppUrl(String code, {String? forwardUrl}) { - final params = { - 'clientID': clientIdentifier, - 'code': code, - 'context[device][product]': product, - if (forwardUrl != null) 'forwardUrl': forwardUrl, - }; - - final queryString = params.entries - .map( - (e) => - '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}', - ) - .join('&'); - - return 'https://app.plex.tv/auth#?$queryString'; - } - - /// Verify token validity - Future verifyToken(String token) async { - try { - final response = await http.get( - Uri.parse('$authUrl/user'), - headers: {..._headers, 'X-Plex-Token': token}, - ); - return response.statusCode == 200; - } catch (e) { - return false; - } - } - - /// Get user info - Future> getUserInfo(String token) async { - final response = await http.get( - Uri.parse('$authUrl/user'), - headers: {..._headers, 'X-Plex-Token': token}, - ); - - if (response.statusCode == 200) { - return json.decode(response.body); - } else { - throw Exception('Failed to get user info: ${response.body}'); - } - } - - /// Get available resources (servers) - Future> getResources(String token) async { - final response = await http.get( - Uri.parse( - '$clientsUrl/resources?includeHttps=1&includeRelay=1&includeIPv6=1', - ), - headers: {..._headers, 'X-Plex-Token': token}, - ); - - if (response.statusCode == 200) { - return json.decode(response.body); - } else { - throw Exception('Failed to get resources: ${response.body}'); - } - } -} diff --git a/lib/client/plex_client.dart b/lib/client/plex_client.dart index 98b7669e..ef34f714 100644 --- a/lib/client/plex_client.dart +++ b/lib/client/plex_client.dart @@ -51,20 +51,6 @@ class PlexClient { } } - /// Test connection to a specific URL with token (legacy method) - static Future testConnectionUrl( - String baseUrl, - String token, { - Duration timeout = const Duration(seconds: 5), - }) async { - final result = await testConnectionWithLatency( - baseUrl, - token, - timeout: timeout, - ); - return result.success; - } - /// Test connection to a specific URL with token and measure latency static Future testConnectionWithLatency( String baseUrl, diff --git a/lib/screens/discover_screen.dart b/lib/screens/discover_screen.dart index 53f967b7..d694bac1 100644 --- a/lib/screens/discover_screen.dart +++ b/lib/screens/discover_screen.dart @@ -17,6 +17,7 @@ import '../utils/platform_detector.dart'; import 'video_player_screen.dart'; import 'main_screen.dart'; import 'about_screen.dart'; +import 'auth_screen.dart'; class DiscoverScreen extends StatefulWidget { final PlexClient client; @@ -341,7 +342,10 @@ class _DiscoverScreenState extends State await storage.clearCredentials(); if (mounted) { - Navigator.of(context).pushNamedAndRemoveUntil('/', (route) => false); + Navigator.of(context).pushAndRemoveUntil( + MaterialPageRoute(builder: (context) => const AuthScreen()), + (route) => false, + ); } } } diff --git a/lib/services/plex_auth_service.dart b/lib/services/plex_auth_service.dart index 9dfaad74..186cfc64 100644 --- a/lib/services/plex_auth_service.dart +++ b/lib/services/plex_auth_service.dart @@ -351,29 +351,6 @@ class PlexServer { yield bestConnection; } } - - /// Legacy method for backward compatibility - returns first working connection - /// For optimal performance, use findBestWorkingConnection() stream instead - @Deprecated('Use findBestWorkingConnection() stream for optimized connection') - Future findBestWorkingConnectionLegacy() async { - if (connections.isEmpty) return null; - - // Test all connections simultaneously - final working = []; - await Future.wait( - connections.map((connection) async { - final works = await PlexClient.testConnectionUrl( - connection.uri, - accessToken, - ); - if (works) { - working.add(connection); - } - }), - ); - - return _selectBest(working); - } } /// Represents a connection to a Plex server diff --git a/lib/theme/mono_theme.dart b/lib/theme/mono_theme.dart index 899d0e21..d4f2185a 100644 --- a/lib/theme/mono_theme.dart +++ b/lib/theme/mono_theme.dart @@ -112,7 +112,20 @@ ThemeData monoTheme({required bool dark}) { backgroundColor: WidgetStatePropertyAll(c.text), foregroundColor: WidgetStatePropertyAll(dark ? c.bg : Colors.white), shape: WidgetStatePropertyAll( - RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), + RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)), + ), + ), + ), + filledButtonTheme: FilledButtonThemeData( + style: ButtonStyle( + padding: const WidgetStatePropertyAll( + EdgeInsets.symmetric(horizontal: 18, vertical: 14), + ), + elevation: const WidgetStatePropertyAll(0), + backgroundColor: WidgetStatePropertyAll(c.text), + foregroundColor: WidgetStatePropertyAll(dark ? c.bg : Colors.white), + shape: WidgetStatePropertyAll( + RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)), ), ), ), diff --git a/lib/utils/plex_headers.dart b/lib/utils/plex_headers.dart deleted file mode 100644 index f5ead39c..00000000 --- a/lib/utils/plex_headers.dart +++ /dev/null @@ -1,37 +0,0 @@ -/// Utility class for building Plex API headers -class PlexHeaders { - /// Standard Plex headers required for API requests - static const String plexClientIdentifier = 'X-Plex-Client-Identifier'; - static const String plexProduct = 'X-Plex-Product'; - static const String plexVersion = 'X-Plex-Version'; - static const String plexToken = 'X-Plex-Token'; - static const String plexPlatform = 'X-Plex-Platform'; - static const String plexPlatformVersion = 'X-Plex-Platform-Version'; - static const String plexDevice = 'X-Plex-Device'; - - /// Builds standard Plex headers with optional token - static Map buildHeaders({ - required String clientIdentifier, - String? token, - String product = 'Plezy', - String version = '1.0', - String platform = 'Flutter', - String platformVersion = '1.0', - String device = 'Mobile', - }) { - final headers = { - plexClientIdentifier: clientIdentifier, - plexProduct: product, - plexVersion: version, - plexPlatform: platform, - plexPlatformVersion: platformVersion, - plexDevice: device, - }; - - if (token != null) { - headers[plexToken] = token; - } - - return headers; - } -} diff --git a/pubspec.lock b/pubspec.lock index d9c4d8d3..e4c41227 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -185,14 +185,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.6" - dart_service_protocol_shared: - dependency: transitive - description: - name: dart_service_protocol_shared - sha256: "1737875c176d7e3d87bb3a359182828b542fe20a0b34198b8d31a81af5c7a76d" - url: "https://pub.dev" - source: hosted - version: "0.0.3" dart_style: dependency: transitive description: @@ -225,14 +217,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.1" - dtd: - dependency: "direct main" - description: - name: dtd - sha256: "09ddb228b3d1478a093556357692a4c203ff4f9d5f8cda05dfdca0ff3fb7c5d3" - url: "https://pub.dev" - source: hosted - version: "4.0.0" fake_async: dependency: transitive description: @@ -294,14 +278,6 @@ packages: url: "https://pub.dev" source: hosted version: "5.0.0" - flutter_svg: - dependency: "direct main" - description: - name: flutter_svg - sha256: b9c2ad5872518a27507ab432d1fb97e8813b05f0fc693f9d40fad06d073e0678 - url: "https://pub.dev" - source: hosted - version: "2.2.1" flutter_test: dependency: "direct dev" description: flutter @@ -329,7 +305,7 @@ packages: source: hosted version: "2.3.2" http: - dependency: "direct main" + dependency: transitive description: name: http sha256: bb2ce4590bc2667c96f318d68cac1b5a7987ec819351d32b1c987239a815e007 @@ -376,14 +352,6 @@ packages: url: "https://pub.dev" source: hosted version: "4.9.0" - json_rpc_2: - dependency: transitive - description: - name: json_rpc_2 - sha256: "3c46c2633aec07810c3d6a2eb08d575b5b4072980db08f1344e66aeb53d6e4a7" - url: "https://pub.dev" - source: hosted - version: "4.0.0" json_serializable: dependency: "direct dev" description: @@ -585,14 +553,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.9.1" - path_parsing: - dependency: transitive - description: - name: path_parsing - sha256: "883402936929eac138ee0a45da5b0f2c80f89913e6dc3bf77eb65b84b409c6ca" - url: "https://pub.dev" - source: hosted - version: "1.1.0" path_provider: dependency: transitive description: @@ -982,14 +942,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.4.0" - unified_analytics: - dependency: transitive - description: - name: unified_analytics - sha256: "8d1429a4b27320a9c4fc854287d18c8fde1549bf622165c5837202a9f370b53d" - url: "https://pub.dev" - source: hosted - version: "8.0.5" universal_platform: dependency: transitive description: @@ -1078,30 +1030,6 @@ packages: url: "https://pub.dev" source: hosted version: "4.5.1" - vector_graphics: - dependency: transitive - description: - name: vector_graphics - sha256: a4f059dc26fc8295b5921376600a194c4ec7d55e72f2fe4c7d2831e103d461e6 - url: "https://pub.dev" - source: hosted - version: "1.1.19" - vector_graphics_codec: - dependency: transitive - description: - name: vector_graphics_codec - sha256: "99fd9fbd34d9f9a32efd7b6a6aae14125d8237b10403b422a6a6dfeac2806146" - url: "https://pub.dev" - source: hosted - version: "1.1.13" - vector_graphics_compiler: - dependency: transitive - description: - name: vector_graphics_compiler - sha256: d354a7ec6931e6047785f4db12a1f61ec3d43b207fc0790f863818543f8ff0dc - url: "https://pub.dev" - source: hosted - version: "1.1.19" vector_math: dependency: transitive description: @@ -1199,7 +1127,7 @@ packages: source: hosted version: "1.1.0" xml: - dependency: "direct main" + dependency: transitive description: name: xml sha256: "971043b3a0d3da28727e40ed3e0b5d18b742fa5a68665cca88e74b7876d5e025" diff --git a/pubspec.yaml b/pubspec.yaml index 84162f92..edb7d6da 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,12 +9,9 @@ environment: dependencies: flutter: sdk: flutter - http: ^1.2.0 dio: ^5.4.0 json_annotation: ^4.8.1 - xml: ^6.5.0 shared_preferences: ^2.2.2 - dtd: ^4.0.0 cached_network_image: ^3.4.1 media_kit: ^1.1.10+1 media_kit_video: ^1.2.4 @@ -24,7 +21,6 @@ dependencies: uuid: ^4.4.0 window_manager: ^0.4.3 logger: ^2.0.2 - flutter_svg: ^2.0.10 package_info_plus: ^9.0.0 dependency_overrides: