Skip to content

Commit

Permalink
chore: connectivity adapter use http as well
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Oct 15, 2023
1 parent edb8928 commit 593bc2d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 7 additions & 6 deletions lib/components/library/user_local_tracks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {};
Expand Down
13 changes: 11 additions & 2 deletions lib/services/connectivity_adapter.dart
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit 593bc2d

Please sign in to comment.