Skip to content

Commit

Permalink
fix(web): not building due to metadata_god ffi
Browse files Browse the repository at this point in the history
chore: update metadata_god and remove win32v3 override
  • Loading branch information
KRTirtho committed Sep 21, 2022
1 parent 7371ccc commit 1191bf2
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 36 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols
Expand Down Expand Up @@ -75,4 +74,4 @@ dist
appimage-build

android/key.properties
.fvm/flutter_sdk
.fvm/flutter_sdk
5 changes: 3 additions & 2 deletions lib/components/Library/UserLocalTracks.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:metadata_god/metadata_god.dart';
Expand Down Expand Up @@ -35,6 +36,7 @@ const imgMimeToExt = {

final localTracksProvider = FutureProvider<List<Track>>((ref) async {
try {
if (kIsWeb) return [];
final downloadLocation = ref.watch(
userPreferencesProvider.select((s) => s.downloadLocation),
);
Expand All @@ -53,7 +55,7 @@ final localTracksProvider = FutureProvider<List<Track>>((ref) async {
}).map(
(f) async {
try {
final metadata = await MetadataGod.getMetadata(f);
final metadata = await MetadataGod.getMetadata(f.path);

final imageFile = File(join(
(await getTemporaryDirectory()).path,
Expand Down Expand Up @@ -203,6 +205,5 @@ class UserLocalTracks extends HookConsumerWidget {
)
],
);
;
}
}
23 changes: 22 additions & 1 deletion lib/components/Shared/UniversalImage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class UniversalImage extends HookWidget {
placeholder: placeholder,
cacheKey: path,
);
} else if (Uri.tryParse(path) != null) {
} else if (Uri.tryParse(path) != null && !path.startsWith("assets")) {
return Image.file(
File(path),
width: width,
Expand All @@ -74,7 +74,28 @@ class UniversalImage extends HookWidget {
);
},
);
} else if (path.startsWith("assets")) {
return Image.asset(
path,
width: width,
height: height,
cacheHeight: height?.toInt(),
cacheWidth: width?.toInt(),
scale: scale,
errorBuilder: (context, error, stackTrace) {
return placeholder?.call(context, error.toString()) ??
Image.asset(
"assets/placeholder.png",
width: width,
height: height,
cacheHeight: height?.toInt(),
cacheWidth: width?.toInt(),
scale: scale,
);
},
);
}

return Image.memory(
base64Decode(path),
width: width,
Expand Down
22 changes: 12 additions & 10 deletions lib/models/Logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ class _SpotubeLogger extends Logger {

@override
void log(Level level, message, [error, StackTrace? stackTrace]) {
(kIsAndroid
? getExternalStorageDirectory()
: getApplicationDocumentsDirectory())
.then((dir) async {
final file = File(path.join(dir!.path, ".spotube_logs"));
if (level == Level.error) {
await file.writeAsString("[${DateTime.now()}]\n$message\n$stackTrace",
mode: FileMode.writeOnlyAppend);
}
});
if (!kIsWeb) {
(kIsAndroid
? getExternalStorageDirectory()
: getApplicationDocumentsDirectory())
.then((dir) async {
final file = File(path.join(dir!.path, ".spotube_logs"));
if (level == Level.error) {
await file.writeAsString("[${DateTime.now()}]\n$message\n$stackTrace",
mode: FileMode.writeOnlyAppend);
}
});
}
super.log(level, "[$owner] $message", error, stackTrace);
}
}
Expand Down
5 changes: 3 additions & 2 deletions lib/provider/Downloader.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/widgets.dart' hide Image;
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:http/http.dart';
import 'package:metadata_god/metadata_god.dart';
Expand Down Expand Up @@ -42,6 +42,7 @@ class Downloader with ChangeNotifier {
Playback get _playback => ref.read(playbackProvider);

void addToQueue(Track baseTrack) async {
if (kIsWeb) return;
if (inQueue.any((t) => t.id == baseTrack.id!)) return;
inQueue.add(baseTrack);
currentlyRunning++;
Expand Down Expand Up @@ -103,7 +104,7 @@ class Downloader with ChangeNotifier {
final response = await get(Uri.parse(imageUri));

await MetadataGod.writeMetadata(
file,
file.path,
Metadata(
title: track.name,
artist: track.artists?.map((a) => a.name).join(", "),
Expand Down
16 changes: 7 additions & 9 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,10 @@ packages:
file_picker:
dependency: "direct main"
description:
path: "."
ref: HEAD
resolved-ref: f9133f6d5dbf33191fc9b58655aebfd15445045a
url: "https://github.com/KRTirtho/flutter_file_picker.git"
source: git
version: "5.0.1"
name: file_picker
url: "https://pub.dartlang.org"
source: hosted
version: "5.2.0"
fixnum:
dependency: transitive
description:
Expand Down Expand Up @@ -726,7 +724,7 @@ packages:
name: metadata_god
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1"
version: "0.2.0"
mime:
dependency: "direct main"
description:
Expand Down Expand Up @@ -796,7 +794,7 @@ packages:
name: package_info_plus_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0"
palette_generator:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1279,7 +1277,7 @@ packages:
source: hosted
version: "2.2.0"
win32:
dependency: "direct overridden"
dependency: transitive
description:
name: win32
url: "https://pub.dartlang.org"
Expand Down
12 changes: 2 additions & 10 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,13 @@ dependencies:
path: packages/audioplayers/
introduction_screen: ^3.0.2
audio_session: ^0.1.10
# This is temporary until the win32v3 update PR is merged and released
file_picker:
git:
url: https://github.com/KRTirtho/flutter_file_picker.git
file_picker: ^5.2.0
popover: ^0.2.6+3
queue: ^3.1.0+1
auto_size_text: ^3.0.0
badges: ^2.0.3
mime: ^1.0.2
metadata_god: ^0.1.1

# Temporary before [package_info_plus_windows] is updated to support
# win32v3
dependency_overrides:
win32: 3.0.0
metadata_god: ^0.2.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 1191bf2

Please sign in to comment.