From 1a32264bc7ffaeb4ef150e56b38fe7fd2a73fc5e Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sat, 15 Mar 2025 10:37:29 +0600 Subject: [PATCH] fix: spotify authentication 429 errors --- .../authentication/authentication.dart | 18 ++++++++++++------ pubspec.lock | 16 ++++++++++++++++ pubspec.yaml | 1 + 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/provider/authentication/authentication.dart b/lib/provider/authentication/authentication.dart index f6c6acfb..87eb7d42 100644 --- a/lib/provider/authentication/authentication.dart +++ b/lib/provider/authentication/authentication.dart @@ -6,6 +6,7 @@ import 'package:collection/collection.dart'; import 'package:desktop_webview_window/desktop_webview_window.dart'; import 'package:dio/dio.dart'; import 'package:dio/io.dart'; +import 'package:dio_http2_adapter/dio_http2_adapter.dart'; import 'package:drift/drift.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart' hide X509Certificate; @@ -34,13 +35,18 @@ extension ExpirationAuthenticationTableData on AuthenticationTableData { class AuthenticationNotifier extends AsyncNotifier { static final Dio dio = () { - final dio = Dio(); + final dio = Dio() + ..httpClientAdapter = Http2Adapter( + ConnectionManager( + idleTimeout: const Duration(seconds: 10), + ), + ); - (dio.httpClientAdapter as IOHttpClientAdapter) - .createHttpClient = () => HttpClient() - ..badCertificateCallback = (X509Certificate cert, String host, int port) { - return host.endsWith("spotify.com") && port == 443; - }; + // (dio.httpClientAdapter as IOHttpClientAdapter) + // .createHttpClient = () => HttpClient() + // ..badCertificateCallback = (X509Certificate cert, String host, int port) { + // return host.endsWith("spotify.com") && port == 443; + // }; return dio; }(); diff --git a/pubspec.lock b/pubspec.lock index 89e33185..325e9dfd 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -544,6 +544,14 @@ packages: url: "https://pub.dev" source: hosted version: "5.7.0" + dio_http2_adapter: + dependency: "direct main" + description: + name: dio_http2_adapter + sha256: b8bd5d587fd228a461711f8b82f378ccd4bf1fbf7802e7663ca60d7b5ce0e3aa + url: "https://pub.dev" + source: hosted + version: "2.6.0" dio_web_adapter: dependency: transitive description: @@ -1186,6 +1194,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.2" + http2: + dependency: transitive + description: + name: http2 + sha256: "382d3aefc5bd6dc68c6b892d7664f29b5beb3251611ae946a98d35158a82bbfa" + url: "https://pub.dev" + source: hosted + version: "2.3.1" http_methods: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index bb7b58b5..911f0962 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -141,6 +141,7 @@ dependencies: http_parser: ^4.1.2 collection: any otp_util: ^1.0.2 + dio_http2_adapter: ^2.6.0 dev_dependencies: build_runner: ^2.4.13