mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-09 08:47:31 +00:00
Merge 55a47e27f3 into fc5bfa089c
This commit is contained in:
commit
345509ae5a
@ -73,4 +73,4 @@ class DesktopLoginPage extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
@ -6,6 +7,9 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||||||
import 'package:spotube/provider/authentication_provider.dart';
|
import 'package:spotube/provider/authentication_provider.dart';
|
||||||
import 'package:spotube/utils/platform.dart';
|
import 'package:spotube/utils/platform.dart';
|
||||||
|
|
||||||
|
const _userAgent =
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36";
|
||||||
|
|
||||||
class WebViewLogin extends HookConsumerWidget {
|
class WebViewLogin extends HookConsumerWidget {
|
||||||
const WebViewLogin({super.key});
|
const WebViewLogin({super.key});
|
||||||
|
|
||||||
@ -14,7 +18,7 @@ class WebViewLogin extends HookConsumerWidget {
|
|||||||
final authenticationNotifier = ref.watch(authenticationProvider.notifier);
|
final authenticationNotifier = ref.watch(authenticationProvider.notifier);
|
||||||
|
|
||||||
if (kIsDesktop) {
|
if (kIsDesktop) {
|
||||||
const Scaffold(
|
return const Scaffold(
|
||||||
body: Center(
|
body: Center(
|
||||||
child: Text('This feature is not available on desktop'),
|
child: Text('This feature is not available on desktop'),
|
||||||
),
|
),
|
||||||
@ -24,9 +28,16 @@ class WebViewLogin extends HookConsumerWidget {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: InAppWebView(
|
child: InAppWebView(
|
||||||
|
master
|
||||||
|
initialOptions: InAppWebViewGroupOptions(
|
||||||
|
crossPlatform: InAppWebViewOptions(
|
||||||
|
userAgent: _userAgent,
|
||||||
|
),
|
||||||
|
|
||||||
initialSettings: InAppWebViewSettings(
|
initialSettings: InAppWebViewSettings(
|
||||||
userAgent:
|
userAgent:
|
||||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 afari/537.36",
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 afari/537.36",
|
||||||
|
master
|
||||||
),
|
),
|
||||||
initialUrlRequest: URLRequest(
|
initialUrlRequest: URLRequest(
|
||||||
url: WebUri("https://accounts.spotify.com/"),
|
url: WebUri("https://accounts.spotify.com/"),
|
||||||
@ -49,8 +60,19 @@ class WebViewLogin extends HookConsumerWidget {
|
|||||||
if (exp.hasMatch(url)) {
|
if (exp.hasMatch(url)) {
|
||||||
final cookies =
|
final cookies =
|
||||||
await CookieManager.instance().getCookies(url: action);
|
await CookieManager.instance().getCookies(url: action);
|
||||||
final cookieHeader =
|
final spDcCookie = cookies.firstWhereOrNull((element) => element.name == "sp_dc");
|
||||||
"sp_dc=${cookies.firstWhere((element) => element.name == "sp_dc").value}";
|
|
||||||
|
if (spDcCookie != null) {
|
||||||
|
final cookieHeader = "sp_dc=${spDcCookie.value}";
|
||||||
|
|
||||||
|
master
|
||||||
|
authenticationNotifier.setCredentials(
|
||||||
|
await AuthenticationCredentials.fromCookie(cookieHeader),
|
||||||
|
);
|
||||||
|
if (mounted()) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
GoRouter.of(context).pushReplacementNamed("/");
|
||||||
|
}
|
||||||
|
|
||||||
authenticationNotifier.setCredentials(
|
authenticationNotifier.setCredentials(
|
||||||
await AuthenticationCredentials.fromCookie(cookieHeader),
|
await AuthenticationCredentials.fromCookie(cookieHeader),
|
||||||
@ -58,6 +80,7 @@ class WebViewLogin extends HookConsumerWidget {
|
|||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
// ignore: use_build_context_synchronously
|
// ignore: use_build_context_synchronously
|
||||||
GoRouter.of(context).go("/");
|
GoRouter.of(context).go("/");
|
||||||
|
master
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -65,4 +88,4 @@ class WebViewLogin extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,6 +96,24 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
vertical: 10,
|
vertical: 10,
|
||||||
),
|
),
|
||||||
color: theme.scaffoldBackgroundColor,
|
color: theme.scaffoldBackgroundColor,
|
||||||
|
master
|
||||||
|
child: TextField(
|
||||||
|
autofocus: queries
|
||||||
|
.none((s) => s.hasPageData && !s.hasPageError) &&
|
||||||
|
!kIsMobile,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
prefixIcon: const Icon(SpotubeIcons.search),
|
||||||
|
hintText: "${context.l10n.search}...",
|
||||||
|
),
|
||||||
|
onChanged: (value) async {
|
||||||
|
ref.read(searchTermStateProvider.notifier).state =
|
||||||
|
value;
|
||||||
|
// Fl-Query is too fast, so we need to delay the search
|
||||||
|
// to prevent spamming the API :)
|
||||||
|
Timer(const Duration(milliseconds: 50), () {
|
||||||
|
onSearch();
|
||||||
|
});
|
||||||
|
|
||||||
child: SearchAnchor(
|
child: SearchAnchor(
|
||||||
searchController: controller,
|
searchController: controller,
|
||||||
viewBuilder: (_) => HookBuilder(builder: (context) {
|
viewBuilder: (_) => HookBuilder(builder: (context) {
|
||||||
@ -176,6 +194,7 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
onTap: controller.openView,
|
onTap: controller.openView,
|
||||||
onChanged: (_) => controller.openView(),
|
onChanged: (_) => controller.openView(),
|
||||||
);
|
);
|
||||||
|
master
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -183,4 +183,4 @@ class AuthenticationNotifier
|
|||||||
final authenticationProvider =
|
final authenticationProvider =
|
||||||
StateNotifierProvider<AuthenticationNotifier, AuthenticationCredentials?>(
|
StateNotifierProvider<AuthenticationNotifier, AuthenticationCredentials?>(
|
||||||
(ref) => AuthenticationNotifier(),
|
(ref) => AuthenticationNotifier(),
|
||||||
);
|
);
|
||||||
@ -8,6 +8,10 @@ ThemeData theme(Color seed, Brightness brightness, bool isAmoled) {
|
|||||||
surface: isAmoled ? Colors.black : null,
|
surface: isAmoled ? Colors.black : null,
|
||||||
brightness: brightness,
|
brightness: brightness,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const borderRadius = BorderRadius.all(Radius.circular(15));
|
||||||
|
const roundedRectangleBorder = RoundedRectangleBorder(borderRadius: borderRadius);
|
||||||
|
|
||||||
return ThemeData(
|
return ThemeData(
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
colorScheme: scheme,
|
colorScheme: scheme,
|
||||||
@ -16,9 +20,9 @@ ThemeData theme(Color seed, Brightness brightness, bool isAmoled) {
|
|||||||
iconColor: scheme.onSurface,
|
iconColor: scheme.onSurface,
|
||||||
),
|
),
|
||||||
appBarTheme: const AppBarTheme(surfaceTintColor: Colors.transparent),
|
appBarTheme: const AppBarTheme(surfaceTintColor: Colors.transparent),
|
||||||
inputDecorationTheme: InputDecorationTheme(
|
inputDecorationTheme: const InputDecorationTheme(
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(15),
|
borderRadius: borderRadius,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
iconTheme: IconThemeData(size: 16, color: scheme.onSurface),
|
iconTheme: IconThemeData(size: 16, color: scheme.onSurface),
|
||||||
@ -36,17 +40,17 @@ ThemeData theme(Color seed, Brightness brightness, bool isAmoled) {
|
|||||||
dividerColor: Colors.transparent,
|
dividerColor: Colors.transparent,
|
||||||
indicator: BoxDecoration(
|
indicator: BoxDecoration(
|
||||||
color: scheme.secondaryContainer,
|
color: scheme.secondaryContainer,
|
||||||
borderRadius: BorderRadius.circular(15),
|
borderRadius: borderRadius,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
popupMenuTheme: PopupMenuThemeData(
|
popupMenuTheme: PopupMenuThemeData(
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
|
shape: roundedRectangleBorder,
|
||||||
color: scheme.surface,
|
color: scheme.surface,
|
||||||
elevation: 4,
|
elevation: 4,
|
||||||
),
|
),
|
||||||
snackBarTheme: SnackBarThemeData(
|
snackBarTheme: SnackBarThemeData(
|
||||||
behavior: SnackBarBehavior.floating,
|
behavior: SnackBarBehavior.floating,
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
|
shape: roundedRectangleBorder,
|
||||||
backgroundColor: scheme.onSurface,
|
backgroundColor: scheme.onSurface,
|
||||||
contentTextStyle: TextStyle(color: scheme.surface),
|
contentTextStyle: TextStyle(color: scheme.surface),
|
||||||
),
|
),
|
||||||
@ -63,11 +67,7 @@ ThemeData theme(Color seed, Brightness brightness, bool isAmoled) {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
elevation: const MaterialStatePropertyAll(0),
|
elevation: const MaterialStatePropertyAll(0),
|
||||||
shape: MaterialStatePropertyAll(
|
shape: MaterialStatePropertyAll(roundedRectangleBorder),
|
||||||
RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
scrollbarTheme: const ScrollbarThemeData(
|
scrollbarTheme: const ScrollbarThemeData(
|
||||||
thickness: MaterialStatePropertyAll(14),
|
thickness: MaterialStatePropertyAll(14),
|
||||||
@ -76,4 +76,4 @@ ThemeData theme(Color seed, Brightness brightness, bool isAmoled) {
|
|||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user