✨ Connect with spotify
This commit is contained in:
parent
be44aadc07
commit
7285eb4959
@ -1,8 +1,11 @@
|
|||||||
|
import 'package:desktop_webview_window/desktop_webview_window.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:media_kit/media_kit.dart';
|
import 'package:media_kit/media_kit.dart';
|
||||||
|
import 'package:rhythm_box/platform.dart';
|
||||||
import 'package:rhythm_box/providers/audio_player.dart';
|
import 'package:rhythm_box/providers/audio_player.dart';
|
||||||
import 'package:rhythm_box/providers/audio_player_stream.dart';
|
import 'package:rhythm_box/providers/audio_player_stream.dart';
|
||||||
|
import 'package:rhythm_box/providers/auth.dart';
|
||||||
import 'package:rhythm_box/providers/database.dart';
|
import 'package:rhythm_box/providers/database.dart';
|
||||||
import 'package:rhythm_box/providers/history.dart';
|
import 'package:rhythm_box/providers/history.dart';
|
||||||
import 'package:rhythm_box/providers/palette.dart';
|
import 'package:rhythm_box/providers/palette.dart';
|
||||||
@ -11,6 +14,8 @@ import 'package:rhythm_box/providers/skip_segments.dart';
|
|||||||
import 'package:rhythm_box/providers/spotify.dart';
|
import 'package:rhythm_box/providers/spotify.dart';
|
||||||
import 'package:rhythm_box/providers/user_preferences.dart';
|
import 'package:rhythm_box/providers/user_preferences.dart';
|
||||||
import 'package:rhythm_box/router.dart';
|
import 'package:rhythm_box/router.dart';
|
||||||
|
import 'package:rhythm_box/services/kv_store/encrypted_kv_store.dart';
|
||||||
|
import 'package:rhythm_box/services/kv_store/kv_store.dart';
|
||||||
import 'package:rhythm_box/services/lyrics/provider.dart';
|
import 'package:rhythm_box/services/lyrics/provider.dart';
|
||||||
import 'package:rhythm_box/services/server/active_sourced_track.dart';
|
import 'package:rhythm_box/services/server/active_sourced_track.dart';
|
||||||
import 'package:rhythm_box/services/server/routes/playback.dart';
|
import 'package:rhythm_box/services/server/routes/playback.dart';
|
||||||
@ -18,9 +23,29 @@ import 'package:rhythm_box/services/server/server.dart';
|
|||||||
import 'package:rhythm_box/services/server/sourced_track.dart';
|
import 'package:rhythm_box/services/server/sourced_track.dart';
|
||||||
import 'package:rhythm_box/translations.dart';
|
import 'package:rhythm_box/translations.dart';
|
||||||
import 'package:rhythm_box/widgets/tracks/querying_track_info.dart';
|
import 'package:rhythm_box/widgets/tracks/querying_track_info.dart';
|
||||||
|
import 'package:smtc_windows/smtc_windows.dart';
|
||||||
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
|
Future<void> main(List<String> rawArgs) async {
|
||||||
|
if (rawArgs.contains('web_view_title_bar')) {
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
if (runWebViewTitleBarWidget(rawArgs)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
|
||||||
MediaKit.ensureInitialized();
|
MediaKit.ensureInitialized();
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
if (PlatformInfo.isDesktop) {
|
||||||
|
await windowManager.setPreventClose(true);
|
||||||
|
}
|
||||||
|
if (PlatformInfo.isWindows) {
|
||||||
|
await SMTCWindows.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
await KVStoreService.initialize();
|
||||||
|
await EncryptedKvStoreService.initialize();
|
||||||
|
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
@ -62,6 +87,7 @@ class MyApp extends StatelessWidget {
|
|||||||
Get.lazyPut(() => SyncedLyricsProvider());
|
Get.lazyPut(() => SyncedLyricsProvider());
|
||||||
|
|
||||||
Get.put(DatabaseProvider());
|
Get.put(DatabaseProvider());
|
||||||
|
Get.put(AuthenticationProvider());
|
||||||
|
|
||||||
Get.put(AudioPlayerProvider());
|
Get.put(AudioPlayerProvider());
|
||||||
Get.put(ActiveSourcedTrackProvider());
|
Get.put(ActiveSourcedTrackProvider());
|
||||||
|
140
lib/providers/auth.dart
Normal file
140
lib/providers/auth.dart
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:dio/io.dart';
|
||||||
|
import 'package:drift/drift.dart';
|
||||||
|
import 'package:get/get.dart' hide Value;
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:rhythm_box/providers/database.dart';
|
||||||
|
import 'package:rhythm_box/services/database/database.dart';
|
||||||
|
|
||||||
|
extension ExpirationAuthenticationTableData on AuthenticationTableData {
|
||||||
|
bool get isExpired => DateTime.now().isAfter(expiration);
|
||||||
|
|
||||||
|
String? getCookie(String key) => cookie.value
|
||||||
|
.split('; ')
|
||||||
|
.firstWhereOrNull((c) => c.trim().startsWith('$key='))
|
||||||
|
?.trim()
|
||||||
|
.split('=')
|
||||||
|
.last
|
||||||
|
.replaceAll(';', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
class AuthenticationProvider extends GetxController {
|
||||||
|
static final Dio dio = () {
|
||||||
|
final dio = Dio();
|
||||||
|
|
||||||
|
(dio.httpClientAdapter as IOHttpClientAdapter)
|
||||||
|
.createHttpClient = () => HttpClient()
|
||||||
|
..badCertificateCallback = (X509Certificate cert, String host, int port) {
|
||||||
|
return host.endsWith('spotify.com') && port == 443;
|
||||||
|
};
|
||||||
|
|
||||||
|
return dio;
|
||||||
|
}();
|
||||||
|
|
||||||
|
var auth = Rxn<AuthenticationTableData?>();
|
||||||
|
Timer? refreshTimer;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
super.onInit();
|
||||||
|
loadAuthenticationData();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> loadAuthenticationData() async {
|
||||||
|
final database = Get.find<DatabaseProvider>().database;
|
||||||
|
final data = await (database.select(database.authenticationTable)
|
||||||
|
..where((s) => s.id.equals(0)))
|
||||||
|
.getSingleOrNull();
|
||||||
|
|
||||||
|
auth.value = data;
|
||||||
|
_setRefreshTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _setRefreshTimer() {
|
||||||
|
refreshTimer?.cancel();
|
||||||
|
if (auth.value != null && auth.value!.isExpired) {
|
||||||
|
refreshCredentials();
|
||||||
|
}
|
||||||
|
refreshTimer = Timer(
|
||||||
|
auth.value!.expiration.difference(DateTime.now()),
|
||||||
|
() => refreshCredentials(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> refreshCredentials() async {
|
||||||
|
final database = Get.find<DatabaseProvider>().database;
|
||||||
|
final refreshedCredentials =
|
||||||
|
await credentialsFromCookie(auth.value!.cookie.value);
|
||||||
|
|
||||||
|
await database
|
||||||
|
.update(database.authenticationTable)
|
||||||
|
.replace(refreshedCredentials);
|
||||||
|
loadAuthenticationData(); // Reload data after refreshing
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> login(String cookie) async {
|
||||||
|
final database = Get.find<DatabaseProvider>().database;
|
||||||
|
final refreshedCredentials = await credentialsFromCookie(cookie);
|
||||||
|
|
||||||
|
await database
|
||||||
|
.into(database.authenticationTable)
|
||||||
|
.insert(refreshedCredentials, mode: InsertMode.replace);
|
||||||
|
loadAuthenticationData(); // Reload data after login
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<AuthenticationTableCompanion> credentialsFromCookie(
|
||||||
|
String cookie) async {
|
||||||
|
try {
|
||||||
|
final spDc = cookie
|
||||||
|
.split('; ')
|
||||||
|
.firstWhereOrNull((c) => c.trim().startsWith('sp_dc='))
|
||||||
|
?.trim();
|
||||||
|
final res = await dio.getUri(
|
||||||
|
Uri.parse(
|
||||||
|
'https://open.spotify.com/get_access_token?reason=transport&productType=web_player'),
|
||||||
|
options: Options(
|
||||||
|
headers: {
|
||||||
|
'Cookie': spDc ?? '',
|
||||||
|
'User-Agent':
|
||||||
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
|
||||||
|
},
|
||||||
|
validateStatus: (status) => true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final body = res.data;
|
||||||
|
|
||||||
|
if ((res.statusCode ?? 500) >= 400) {
|
||||||
|
throw Exception(
|
||||||
|
"Failed to get access token: ${body['error'] ?? res.statusMessage}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return AuthenticationTableCompanion.insert(
|
||||||
|
id: const Value(0),
|
||||||
|
cookie: DecryptedText("${res.headers["set-cookie"]?.join(";")}; $spDc"),
|
||||||
|
accessToken: DecryptedText(body['accessToken']),
|
||||||
|
expiration: DateTime.fromMillisecondsSinceEpoch(
|
||||||
|
body['accessTokenExpirationTimestampMs']),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
// Handle error
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> logout() async {
|
||||||
|
auth.value = null;
|
||||||
|
final database = Get.find<DatabaseProvider>().database;
|
||||||
|
await (database.delete(database.authenticationTable)
|
||||||
|
..where((s) => s.id.equals(0)))
|
||||||
|
.go();
|
||||||
|
// Additional cleanup if necessary
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onClose() {
|
||||||
|
refreshTimer?.cancel();
|
||||||
|
super.onClose();
|
||||||
|
}
|
||||||
|
}
|
@ -7,8 +7,6 @@ class PaletteProvider extends GetxController {
|
|||||||
|
|
||||||
void updatePalette(PaletteGenerator? newPalette) {
|
void updatePalette(PaletteGenerator? newPalette) {
|
||||||
palette.value = newPalette;
|
palette.value = newPalette;
|
||||||
print('call update!');
|
|
||||||
print(newPalette);
|
|
||||||
if (newPalette != null) {
|
if (newPalette != null) {
|
||||||
Get.changeTheme(
|
Get.changeTheme(
|
||||||
ThemeData.from(
|
ThemeData.from(
|
||||||
|
@ -1,17 +1,59 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:rhythm_box/providers/auth.dart';
|
||||||
import 'package:spotify/spotify.dart';
|
import 'package:spotify/spotify.dart';
|
||||||
|
|
||||||
class SpotifyProvider extends GetxController {
|
class SpotifyProvider extends GetxController {
|
||||||
late final SpotifyApi api;
|
late SpotifyApi api;
|
||||||
|
|
||||||
|
List<StreamSubscription>? _subscriptions;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
api = SpotifyApi(
|
final AuthenticationProvider authenticate = Get.find();
|
||||||
|
if (authenticate.auth.value == null) {
|
||||||
|
api = _initApiWithClientCredentials();
|
||||||
|
} else {
|
||||||
|
api = _initApiWithUserCredentials();
|
||||||
|
}
|
||||||
|
_subscriptions = [
|
||||||
|
authenticate.auth.listen((value) {
|
||||||
|
if (value == null) {
|
||||||
|
api = _initApiWithClientCredentials();
|
||||||
|
} else {
|
||||||
|
api = _initApiWithUserCredentials();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
super.onInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
SpotifyApi _initApiWithClientCredentials() {
|
||||||
|
log('[SpotifyApi] Using client credentials...');
|
||||||
|
return SpotifyApi(
|
||||||
SpotifyApiCredentials(
|
SpotifyApiCredentials(
|
||||||
'f73d4bff91d64d89be9930036f553534',
|
'f73d4bff91d64d89be9930036f553534',
|
||||||
'5cbec0b928d247cd891d06195f07b8c9',
|
'5cbec0b928d247cd891d06195f07b8c9',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
super.onInit();
|
}
|
||||||
|
|
||||||
|
SpotifyApi _initApiWithUserCredentials() {
|
||||||
|
log('[SpotifyApi] Using user credentials...');
|
||||||
|
final AuthenticationProvider authenticate = Get.find();
|
||||||
|
return SpotifyApi.withAccessToken(
|
||||||
|
authenticate.auth.value!.accessToken.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
if (_subscriptions != null) {
|
||||||
|
for (final subscription in _subscriptions!) {
|
||||||
|
subscription.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:animations/animations.dart';
|
import 'package:animations/animations.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:rhythm_box/screens/auth/mobile_login.dart';
|
||||||
import 'package:rhythm_box/screens/explore.dart';
|
import 'package:rhythm_box/screens/explore.dart';
|
||||||
import 'package:rhythm_box/screens/player/lyrics.dart';
|
import 'package:rhythm_box/screens/player/lyrics.dart';
|
||||||
import 'package:rhythm_box/screens/player/view.dart';
|
import 'package:rhythm_box/screens/player/view.dart';
|
||||||
@ -62,4 +63,14 @@ final router = GoRouter(routes: [
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
ShellRoute(
|
||||||
|
builder: (context, state, child) => child,
|
||||||
|
routes: [
|
||||||
|
GoRoute(
|
||||||
|
path: '/auth/mobile-login',
|
||||||
|
name: 'authMobileLogin',
|
||||||
|
builder: (context, state) => const MobileLogin(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
]);
|
]);
|
||||||
|
52
lib/screens/auth/desktop_login.dart
Normal file
52
lib/screens/auth/desktop_login.dart
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:desktop_webview_window/desktop_webview_window.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:path/path.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:rhythm_box/platform.dart';
|
||||||
|
import 'package:rhythm_box/providers/auth.dart';
|
||||||
|
|
||||||
|
Future<void> desktopLogin(BuildContext context) async {
|
||||||
|
final exp = RegExp(r'https:\/\/accounts.spotify.com\/.+\/status');
|
||||||
|
final applicationSupportDir = await getApplicationSupportDirectory();
|
||||||
|
final userDataFolder =
|
||||||
|
Directory(join(applicationSupportDir.path, 'webview_window_Webview2'));
|
||||||
|
|
||||||
|
if (!await userDataFolder.exists()) {
|
||||||
|
await userDataFolder.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
final webview = await WebviewWindow.create(
|
||||||
|
configuration: CreateConfiguration(
|
||||||
|
title: 'Spotify Login',
|
||||||
|
titleBarTopPadding: PlatformInfo.isMacOS ? 20 : 0,
|
||||||
|
windowHeight: 720,
|
||||||
|
windowWidth: 1280,
|
||||||
|
userDataFolderWindows: userDataFolder.path,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
webview
|
||||||
|
..setBrightness(Theme.of(context).colorScheme.brightness)
|
||||||
|
..launch('https://accounts.spotify.com/')
|
||||||
|
..setOnUrlRequestCallback((url) {
|
||||||
|
if (exp.hasMatch(url)) {
|
||||||
|
webview.getAllCookies().then((cookies) async {
|
||||||
|
final cookieHeader =
|
||||||
|
"sp_dc=${cookies.firstWhere((element) => element.name.contains("sp_dc")).value.replaceAll("\u0000", "")}";
|
||||||
|
|
||||||
|
final AuthenticationProvider authenticate = Get.find();
|
||||||
|
await authenticate.login(cookieHeader);
|
||||||
|
|
||||||
|
webview.close();
|
||||||
|
if (context.mounted) {
|
||||||
|
GoRouter.of(context).go('/');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
13
lib/screens/auth/login.dart
Normal file
13
lib/screens/auth/login.dart
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:rhythm_box/platform.dart';
|
||||||
|
import 'package:rhythm_box/screens/auth/desktop_login.dart';
|
||||||
|
|
||||||
|
Future<void> universalLogin(BuildContext context) async {
|
||||||
|
if (PlatformInfo.isMobile) {
|
||||||
|
GoRouter.of(context).pushNamed('authMobileLogin');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return await desktopLogin(context);
|
||||||
|
}
|
67
lib/screens/auth/mobile_login.dart
Normal file
67
lib/screens/auth/mobile_login.dart
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:rhythm_box/platform.dart';
|
||||||
|
import 'package:rhythm_box/providers/auth.dart';
|
||||||
|
|
||||||
|
class MobileLogin extends StatelessWidget {
|
||||||
|
const MobileLogin({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final AuthenticationProvider authenticate = Get.find();
|
||||||
|
|
||||||
|
if (PlatformInfo.isDesktop) {
|
||||||
|
const Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: Text('This feature is not available on desktop'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('Connect with Spotify'),
|
||||||
|
),
|
||||||
|
body: SafeArea(
|
||||||
|
child: InAppWebView(
|
||||||
|
initialSettings: InAppWebViewSettings(
|
||||||
|
userAgent:
|
||||||
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36',
|
||||||
|
),
|
||||||
|
initialUrlRequest: URLRequest(
|
||||||
|
url: WebUri('https://accounts.spotify.com/'),
|
||||||
|
),
|
||||||
|
onPermissionRequest: (controller, permissionRequest) async {
|
||||||
|
return PermissionResponse(
|
||||||
|
resources: permissionRequest.resources,
|
||||||
|
action: PermissionResponseAction.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}";
|
||||||
|
|
||||||
|
await authenticate.login(cookieHeader);
|
||||||
|
if (context.mounted) {
|
||||||
|
GoRouter.of(context).pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:rhythm_box/providers/auth.dart';
|
||||||
|
import 'package:rhythm_box/providers/spotify.dart';
|
||||||
|
import 'package:rhythm_box/screens/auth/login.dart';
|
||||||
|
import 'package:rhythm_box/widgets/auto_cache_image.dart';
|
||||||
|
|
||||||
class SettingsScreen extends StatefulWidget {
|
class SettingsScreen extends StatefulWidget {
|
||||||
const SettingsScreen({super.key});
|
const SettingsScreen({super.key});
|
||||||
@ -8,6 +13,11 @@ class SettingsScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SettingsScreenState extends State<SettingsScreen> {
|
class _SettingsScreenState extends State<SettingsScreen> {
|
||||||
|
late final SpotifyProvider _spotify = Get.find();
|
||||||
|
late final AuthenticationProvider _authenticate = Get.find();
|
||||||
|
|
||||||
|
bool _isLoggingIn = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Material(
|
return Material(
|
||||||
@ -15,14 +25,73 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
ListTile(
|
Obx(() {
|
||||||
|
if (_authenticate.auth.value == null) {
|
||||||
|
return ListTile(
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||||
leading: const Icon(Icons.login),
|
leading: const Icon(Icons.login),
|
||||||
title: const Text('Connect with Spotify'),
|
title: const Text('Connect with Spotify'),
|
||||||
subtitle: const Text('To explore your own library and more'),
|
subtitle: const Text('To explore your own library and more'),
|
||||||
trailing: const Icon(Icons.chevron_right),
|
trailing: const Icon(Icons.chevron_right),
|
||||||
onTap: () {},
|
enabled: !_isLoggingIn,
|
||||||
|
onTap: () async {
|
||||||
|
setState(() => _isLoggingIn = true);
|
||||||
|
await universalLogin(context);
|
||||||
|
setState(() => _isLoggingIn = false);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return FutureBuilder(
|
||||||
|
future: _spotify.api.me.get(),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
print(snapshot.data);
|
||||||
|
print(snapshot.error);
|
||||||
|
if (!snapshot.hasData) {
|
||||||
|
return const ListTile(
|
||||||
|
contentPadding:
|
||||||
|
const EdgeInsets.symmetric(horizontal: 24),
|
||||||
|
leading: SizedBox(
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 3,
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
title: Text('Loading...'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ListTile(
|
||||||
|
leading: (snapshot.data!.images?.isNotEmpty ?? false)
|
||||||
|
? CircleAvatar(
|
||||||
|
backgroundImage: AutoCacheImage.provider(
|
||||||
|
snapshot.data!.images!.firstOrNull!.url!,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: const Icon(Icons.account_circle),
|
||||||
|
title: Text(snapshot.data!.displayName!),
|
||||||
|
subtitle: const Text('Connected with your Spotify'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
Obx(() {
|
||||||
|
if (_authenticate.auth.value == null) {
|
||||||
|
return const SizedBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ListTile(
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||||
|
leading: const Icon(Icons.logout),
|
||||||
|
title: const Text('Log out'),
|
||||||
|
subtitle: const Text('Disconnect with this Spotify account'),
|
||||||
|
trailing: const Icon(Icons.chevron_right),
|
||||||
|
onTap: () async {
|
||||||
|
_authenticate.logout();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -15,7 +15,7 @@ class WindowsAudioService {
|
|||||||
final subscriptions = <StreamSubscription>[];
|
final subscriptions = <StreamSubscription>[];
|
||||||
|
|
||||||
WindowsAudioService() : smtc = SMTCWindows(enabled: false) {
|
WindowsAudioService() : smtc = SMTCWindows(enabled: false) {
|
||||||
smtc.setPlaybackStatus(PlaybackStatus.Stopped);
|
smtc.setPlaybackStatus(PlaybackStatus.stopped);
|
||||||
final buttonStream = smtc.buttonPressStream.listen((event) {
|
final buttonStream = smtc.buttonPressStream.listen((event) {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case PressedButton.play:
|
case PressedButton.play:
|
||||||
@ -42,16 +42,16 @@ class WindowsAudioService {
|
|||||||
audioPlayer.playerStateStream.listen((state) async {
|
audioPlayer.playerStateStream.listen((state) async {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case AudioPlaybackState.playing:
|
case AudioPlaybackState.playing:
|
||||||
await smtc.setPlaybackStatus(PlaybackStatus.Playing);
|
await smtc.setPlaybackStatus(PlaybackStatus.playing);
|
||||||
break;
|
break;
|
||||||
case AudioPlaybackState.paused:
|
case AudioPlaybackState.paused:
|
||||||
await smtc.setPlaybackStatus(PlaybackStatus.Paused);
|
await smtc.setPlaybackStatus(PlaybackStatus.paused);
|
||||||
break;
|
break;
|
||||||
case AudioPlaybackState.stopped:
|
case AudioPlaybackState.stopped:
|
||||||
await smtc.setPlaybackStatus(PlaybackStatus.Stopped);
|
await smtc.setPlaybackStatus(PlaybackStatus.stopped);
|
||||||
break;
|
break;
|
||||||
case AudioPlaybackState.completed:
|
case AudioPlaybackState.completed:
|
||||||
await smtc.setPlaybackStatus(PlaybackStatus.Changing);
|
await smtc.setPlaybackStatus(PlaybackStatus.changing);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
File diff suppressed because it is too large
Load Diff
80
pubspec.lock
80
pubspec.lock
@ -186,10 +186,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: cached_network_image
|
name: cached_network_image
|
||||||
sha256: "7c1183e361e5c8b0a0f21a28401eecdbde252441106a9816400dd4c2b2424916"
|
sha256: "4a5d8d2c728b0f3d0245f69f921d7be90cae4c2fd5288f773088672c0893f819"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.4.1"
|
version: "3.4.0"
|
||||||
cached_network_image_platform_interface:
|
cached_network_image_platform_interface:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -202,10 +202,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: cached_network_image_web
|
name: cached_network_image_web
|
||||||
sha256: "980842f4e8e2535b8dbd3d5ca0b1f0ba66bf61d14cc3a17a9b4788a3685ba062"
|
sha256: "6322dde7a5ad92202e64df659241104a43db20ed594c41ca18de1014598d7996"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.1"
|
version: "1.3.0"
|
||||||
characters:
|
characters:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -305,11 +305,12 @@ packages:
|
|||||||
desktop_webview_window:
|
desktop_webview_window:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: desktop_webview_window
|
path: "packages/desktop_webview_window"
|
||||||
sha256: "57cf20d81689d5cbb1adfd0017e96b669398a669d927906073b0e42fc64111c0"
|
ref: "feat/cookies"
|
||||||
url: "https://pub.dev"
|
resolved-ref: f20e433d4a948515b35089d40069f7dd9bced9e4
|
||||||
source: hosted
|
url: "https://github.com/KRTirtho/flutter-plugins.git"
|
||||||
version: "0.2.3"
|
source: git
|
||||||
|
version: "0.2.4"
|
||||||
device_info_plus:
|
device_info_plus:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -354,26 +355,18 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: drift
|
name: drift
|
||||||
sha256: "15b51e0ee1970455c0c3f7e560f3ac02ecb9c04711a9657586e470b234659dba"
|
sha256: "4e0ffee40d23f0b809e6cff1ad202886f51d629649073ed42d9cd1d194ea943e"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.20.0"
|
version: "2.19.1+1"
|
||||||
drift_dev:
|
drift_dev:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
name: drift_dev
|
name: drift_dev
|
||||||
sha256: b9ec6159a731288e805a44225ccbebad507dd84d52ab71352c52584f13199d2d
|
sha256: ac7647c6cedca99724ca300cff9181f6dd799428f8ed71f94159ed0528eaec26
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.20.1"
|
version: "2.19.1"
|
||||||
drift_flutter:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: drift_flutter
|
|
||||||
sha256: c670c947fe17ad149678a43fdbbfdb69321f0c83d315043e34e8ad2729e11f49
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "0.2.0"
|
|
||||||
duration:
|
duration:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -527,10 +520,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: flutter_rust_bridge
|
name: flutter_rust_bridge
|
||||||
sha256: "02720226035257ad0b571c1256f43df3e1556a499f6bcb004849a0faaa0e87f0"
|
sha256: fac14d2dd67eeba29a20e5d99fac0d4d9fcd552cdf6bf4f8945f7679c6b07b1d
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.82.6"
|
version: "2.1.0"
|
||||||
flutter_secure_storage:
|
flutter_secure_storage:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -1077,14 +1070,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.0"
|
version: "1.3.0"
|
||||||
puppeteer:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: puppeteer
|
|
||||||
sha256: a6752d4f09b510ae41911bfd0997f957e723d38facf320dd9ee0e5661108744a
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "3.13.0"
|
|
||||||
recase:
|
recase:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1206,14 +1191,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.4"
|
version: "1.1.4"
|
||||||
shelf_static:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: shelf_static
|
|
||||||
sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.1.2"
|
|
||||||
shelf_web_socket:
|
shelf_web_socket:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1238,10 +1215,11 @@ packages:
|
|||||||
smtc_windows:
|
smtc_windows:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: smtc_windows
|
path: "packages/smtc_windows"
|
||||||
sha256: "0fd64d0c6a0c8ea4ea7908d31195eadc8f6d45d5245159fc67259e9e8704100f"
|
ref: cargokit
|
||||||
url: "https://pub.dev"
|
resolved-ref: "331636d8e378e3ac9ad30a4b0d3eed17d5a85fe9"
|
||||||
source: hosted
|
url: "https://github.com/KRTirtho/frb_plugins.git"
|
||||||
|
source: git
|
||||||
version: "0.1.3"
|
version: "0.1.3"
|
||||||
source_gen:
|
source_gen:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
@ -1303,10 +1281,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: sqlite3
|
name: sqlite3
|
||||||
sha256: "45f168ae2213201b54e09429ed0c593dc2c88c924a1488d6f9c523a255d567cb"
|
sha256: fde692580bee3379374af1f624eb3e113ab2865ecb161dbe2d8ac2de9735dbdb
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.6"
|
version: "2.4.5"
|
||||||
sqlite3_flutter_libs:
|
sqlite3_flutter_libs:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -1387,14 +1365,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.1"
|
version: "1.0.1"
|
||||||
tuple:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: tuple
|
|
||||||
sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.0.2"
|
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1455,10 +1425,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: web
|
name: web
|
||||||
sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062
|
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.0"
|
version: "0.5.1"
|
||||||
web_socket_channel:
|
web_socket_channel:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
23
pubspec.yaml
23
pubspec.yaml
@ -39,7 +39,7 @@ dependencies:
|
|||||||
go_router: ^14.2.7
|
go_router: ^14.2.7
|
||||||
youtube_explode_dart: ^2.2.1
|
youtube_explode_dart: ^2.2.1
|
||||||
spotify: ^0.13.7
|
spotify: ^0.13.7
|
||||||
cached_network_image: ^3.4.1
|
cached_network_image: ^3.4.0
|
||||||
package_info_plus: ^8.0.2
|
package_info_plus: ^8.0.2
|
||||||
skeletonizer: ^1.4.2
|
skeletonizer: ^1.4.2
|
||||||
gap: ^3.0.1
|
gap: ^3.0.1
|
||||||
@ -51,13 +51,17 @@ dependencies:
|
|||||||
freeze: ^1.0.0
|
freeze: ^1.0.0
|
||||||
freezed_annotation: ^2.4.4
|
freezed_annotation: ^2.4.4
|
||||||
http: ^1.2.2
|
http: ^1.2.2
|
||||||
drift: ^2.20.0
|
drift: ^2.18.0
|
||||||
collection: ^1.18.0
|
collection: ^1.18.0
|
||||||
piped_client: ^0.1.1
|
piped_client: ^0.1.1
|
||||||
flutter_broadcasts: ^0.4.0
|
flutter_broadcasts: ^0.4.0
|
||||||
audio_session: ^0.1.21
|
audio_session: ^0.1.21
|
||||||
audio_service: ^0.18.15
|
audio_service: ^0.18.15
|
||||||
smtc_windows: ^0.1.3
|
smtc_windows:
|
||||||
|
git:
|
||||||
|
url: https://github.com/KRTirtho/frb_plugins.git
|
||||||
|
path: packages/smtc_windows
|
||||||
|
ref: cargokit
|
||||||
win32_registry: ^1.1.4
|
win32_registry: ^1.1.4
|
||||||
uuid: ^4.4.2
|
uuid: ^4.4.2
|
||||||
device_info_plus: ^10.1.2
|
device_info_plus: ^10.1.2
|
||||||
@ -65,7 +69,6 @@ dependencies:
|
|||||||
shelf_router: ^1.1.4
|
shelf_router: ^1.1.4
|
||||||
dio: ^5.6.0
|
dio: ^5.6.0
|
||||||
json_annotation: ^4.9.0
|
json_annotation: ^4.9.0
|
||||||
drift_flutter: ^0.2.0
|
|
||||||
encrypt: ^5.0.3
|
encrypt: ^5.0.3
|
||||||
flutter_secure_storage: ^9.2.2
|
flutter_secure_storage: ^9.2.2
|
||||||
window_manager: ^0.4.2
|
window_manager: ^0.4.2
|
||||||
@ -73,8 +76,8 @@ dependencies:
|
|||||||
json_serializable: ^6.8.0
|
json_serializable: ^6.8.0
|
||||||
path: ^1.9.0
|
path: ^1.9.0
|
||||||
path_provider: ^2.1.4
|
path_provider: ^2.1.4
|
||||||
sqlite3: ^2.4.6
|
sqlite3_flutter_libs: ^0.5.23
|
||||||
sqlite3_flutter_libs: ^0.5.24
|
sqlite3: ^2.4.3
|
||||||
palette_generator: ^0.3.3+4
|
palette_generator: ^0.3.3+4
|
||||||
scrobblenaut:
|
scrobblenaut:
|
||||||
git:
|
git:
|
||||||
@ -86,7 +89,11 @@ dependencies:
|
|||||||
animations: ^2.0.11
|
animations: ^2.0.11
|
||||||
flutter_animate: ^4.5.0
|
flutter_animate: ^4.5.0
|
||||||
duration: ^4.0.3
|
duration: ^4.0.3
|
||||||
desktop_webview_window: ^0.2.3
|
desktop_webview_window:
|
||||||
|
git:
|
||||||
|
url: https://github.com/KRTirtho/flutter-plugins.git
|
||||||
|
ref: feat/cookies
|
||||||
|
path: packages/desktop_webview_window
|
||||||
flutter_inappwebview: ^6.0.0
|
flutter_inappwebview: ^6.0.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
@ -99,7 +106,7 @@ dev_dependencies:
|
|||||||
# package. See that file for information about deactivating specific lint
|
# package. See that file for information about deactivating specific lint
|
||||||
# rules and activating additional ones.
|
# rules and activating additional ones.
|
||||||
flutter_lints: ^4.0.0
|
flutter_lints: ^4.0.0
|
||||||
drift_dev: ^2.20.1
|
drift_dev: ^2.18.0
|
||||||
build_runner: ^2.4.12
|
build_runner: ^2.4.12
|
||||||
flutter_launcher_icons: ^0.13.1
|
flutter_launcher_icons: ^0.13.1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user