mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00

* feat: add riverpod based favorite album provider * feat: add album is saved, new releases and tracks providers * feat: add artist related providers * feat: add all categories providers * feat: add lyrics provider * feat: add playlist related providers * feat: add search provider * feat: add view and spotify friends provider * feat: add playlist create and update and favorite handlers * feat: use providers in home screen * chore: fix dart lint issues * feat: use new providers for playlist and albums screen * feat: use providers in artist page * feat: use providers on library page * feat: use provider for playlist and album card and heart button * feat: use provider in search page * feat: use providers in generate playlist * feat: use provider in lyrics screen * feat: use provider for create playlist * feat: use provider in add track dialog * feat: use providers in remaining pages and remove fl_query * fix: remove direct access to provider.value * fix: glitching when loading * fix: user album loading next page indicator * feat: make many provider autoDispose after 5 minutes of no usage * fix: ignore episodes in tracks
74 lines
2.4 KiB
Dart
74 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:spotube/provider/authentication_provider.dart';
|
|
import 'package:spotube/utils/platform.dart';
|
|
|
|
class WebViewLogin extends HookConsumerWidget {
|
|
const WebViewLogin({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, ref) {
|
|
final mounted = useIsMounted();
|
|
final authenticationNotifier =
|
|
ref.watch(AuthenticationNotifier.provider.notifier);
|
|
|
|
if (kIsDesktop) {
|
|
const Scaffold(
|
|
body: Center(
|
|
child: Text('This feature is not available on desktop'),
|
|
),
|
|
);
|
|
}
|
|
|
|
return Scaffold(
|
|
body: SafeArea(
|
|
child: InAppWebView(
|
|
initialOptions: InAppWebViewGroupOptions(
|
|
crossPlatform: InAppWebViewOptions(
|
|
userAgent:
|
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 afari/537.36",
|
|
),
|
|
),
|
|
initialUrlRequest: URLRequest(
|
|
url: Uri.parse("https://accounts.spotify.com/"),
|
|
),
|
|
androidOnPermissionRequest: (controller, origin, resources) async {
|
|
return PermissionRequestResponse(
|
|
resources: resources,
|
|
action: PermissionRequestResponseAction.GRANT,
|
|
);
|
|
},
|
|
onLoadStop: (controller, action) async {
|
|
if (action == null) return;
|
|
String url = action.toString();
|
|
if (url.endsWith("/")) {
|
|
url = url.substring(0, url.length - 1);
|
|
}
|
|
|
|
final exp = RegExp(r"https:\/\/accounts.spotify.com\/.+\/status");
|
|
|
|
if (exp.hasMatch(url)) {
|
|
final cookies =
|
|
await CookieManager.instance().getCookies(url: action);
|
|
final cookieHeader =
|
|
"sp_dc=${cookies.firstWhere((element) => element.name == "sp_dc").value}";
|
|
|
|
authenticationNotifier.setCredentials(
|
|
await AuthenticationCredentials.fromCookie(cookieHeader),
|
|
);
|
|
if (mounted()) {
|
|
// ignore: use_build_context_synchronously
|
|
GoRouter.of(context).go("/");
|
|
}
|
|
}
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|