mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05: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/platform.dart';
|
||||||
import 'package:spotube/utils/service_utils.dart';
|
import 'package:spotube/utils/service_utils.dart';
|
||||||
import 'package:spotube/utils/type_conversion_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 = [
|
const supportedAudioTypes = [
|
||||||
"audio/webm",
|
"audio/webm",
|
||||||
@ -77,14 +78,14 @@ final localTracksProvider = FutureProvider<List<LocalTrack>>((ref) async {
|
|||||||
final mimetype = lookupMimeType(file.path);
|
final mimetype = lookupMimeType(file.path);
|
||||||
return mimetype != null && supportedAudioTypes.contains(mimetype);
|
return mimetype != null && supportedAudioTypes.contains(mimetype);
|
||||||
}).map(
|
}).map(
|
||||||
(f) async {
|
(file) async {
|
||||||
try {
|
try {
|
||||||
final metadata = await MetadataGod.readMetadata(file: f.path);
|
final metadata = await MetadataGod.readMetadata(file: file.path);
|
||||||
|
|
||||||
final imageFile = File(join(
|
final imageFile = File(join(
|
||||||
(await getTemporaryDirectory()).path,
|
(await getTemporaryDirectory()).path,
|
||||||
"spotube",
|
"spotube",
|
||||||
basenameWithoutExtension(f.path) +
|
basenameWithoutExtension(file.path) +
|
||||||
imgMimeToExt[metadata.picture?.mimeType ?? "image/jpeg"]!,
|
imgMimeToExt[metadata.picture?.mimeType ?? "image/jpeg"]!,
|
||||||
));
|
));
|
||||||
if (!await imageFile.exists() && metadata.picture != null) {
|
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) {
|
} catch (e, stack) {
|
||||||
if (e is FfiException) {
|
if (e is FfiException) {
|
||||||
return {"file": f};
|
return {"file": file};
|
||||||
}
|
}
|
||||||
Catcher2.reportCheckedError(e, stack);
|
Catcher2.reportCheckedError(e, stack);
|
||||||
return {};
|
return {};
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
import 'package:fl_query/fl_query.dart';
|
import 'package:fl_query/fl_query.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
class FlQueryInternetConnectionCheckerAdapter extends ConnectivityAdapter
|
class FlQueryInternetConnectionCheckerAdapter extends ConnectivityAdapter
|
||||||
with WidgetsBindingObserver {
|
with WidgetsBindingObserver {
|
||||||
final _connectionStreamController = StreamController<bool>.broadcast();
|
final _connectionStreamController = StreamController<bool>.broadcast();
|
||||||
|
final Dio dio;
|
||||||
|
|
||||||
FlQueryInternetConnectionCheckerAdapter() : super() {
|
FlQueryInternetConnectionCheckerAdapter()
|
||||||
|
: dio = Dio(),
|
||||||
|
super() {
|
||||||
Timer? timer;
|
Timer? timer;
|
||||||
|
|
||||||
onConnectivityChanged.listen((connected) {
|
onConnectivityChanged.listen((connected) {
|
||||||
@ -81,9 +85,14 @@ class FlQueryInternetConnectionCheckerAdapter extends ConnectivityAdapter
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} on SocketException catch (_) {
|
} on SocketException catch (_) {
|
||||||
|
try {
|
||||||
|
final response = await dio.head('https://$address');
|
||||||
|
return (response.statusCode ?? 500) <= 400;
|
||||||
|
} on DioException catch (_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<bool> _isConnected() async {
|
Future<bool> _isConnected() async {
|
||||||
return await doesConnectTo('google.com') ||
|
return await doesConnectTo('google.com') ||
|
||||||
|
Loading…
Reference in New Issue
Block a user