mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
chore: connectivity adapter use http as well
This commit is contained in:
parent
edb8928d53
commit
593bc2de90
@ -29,7 +29,8 @@ import 'package:spotube/provider/user_preferences_provider.dart';
|
||||
import 'package:spotube/utils/platform.dart';
|
||||
import 'package:spotube/utils/service_utils.dart';
|
||||
import 'package:spotube/utils/type_conversion_utils.dart';
|
||||
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart' show FfiException;
|
||||
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart'
|
||||
show FfiException;
|
||||
|
||||
const supportedAudioTypes = [
|
||||
"audio/webm",
|
||||
@ -77,14 +78,14 @@ final localTracksProvider = FutureProvider<List<LocalTrack>>((ref) async {
|
||||
final mimetype = lookupMimeType(file.path);
|
||||
return mimetype != null && supportedAudioTypes.contains(mimetype);
|
||||
}).map(
|
||||
(f) async {
|
||||
(file) async {
|
||||
try {
|
||||
final metadata = await MetadataGod.readMetadata(file: f.path);
|
||||
final metadata = await MetadataGod.readMetadata(file: file.path);
|
||||
|
||||
final imageFile = File(join(
|
||||
(await getTemporaryDirectory()).path,
|
||||
"spotube",
|
||||
basenameWithoutExtension(f.path) +
|
||||
basenameWithoutExtension(file.path) +
|
||||
imgMimeToExt[metadata.picture?.mimeType ?? "image/jpeg"]!,
|
||||
));
|
||||
if (!await imageFile.exists() && metadata.picture != null) {
|
||||
@ -95,10 +96,10 @@ final localTracksProvider = FutureProvider<List<LocalTrack>>((ref) async {
|
||||
);
|
||||
}
|
||||
|
||||
return {"metadata": metadata, "file": f, "art": imageFile.path};
|
||||
return {"metadata": metadata, "file": file, "art": imageFile.path};
|
||||
} catch (e, stack) {
|
||||
if (e is FfiException) {
|
||||
return {"file": f};
|
||||
return {"file": file};
|
||||
}
|
||||
Catcher2.reportCheckedError(e, stack);
|
||||
return {};
|
||||
|
@ -1,14 +1,18 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:fl_query/fl_query.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class FlQueryInternetConnectionCheckerAdapter extends ConnectivityAdapter
|
||||
with WidgetsBindingObserver {
|
||||
final _connectionStreamController = StreamController<bool>.broadcast();
|
||||
final Dio dio;
|
||||
|
||||
FlQueryInternetConnectionCheckerAdapter() : super() {
|
||||
FlQueryInternetConnectionCheckerAdapter()
|
||||
: dio = Dio(),
|
||||
super() {
|
||||
Timer? timer;
|
||||
|
||||
onConnectivityChanged.listen((connected) {
|
||||
@ -81,7 +85,12 @@ class FlQueryInternetConnectionCheckerAdapter extends ConnectivityAdapter
|
||||
}
|
||||
return false;
|
||||
} on SocketException catch (_) {
|
||||
return false;
|
||||
try {
|
||||
final response = await dio.head('https://$address');
|
||||
return (response.statusCode ?? 500) <= 400;
|
||||
} on DioException catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user