Skip to content

Commit

Permalink
Fix serialisation error and logging on MusicPlayerBackgroundTask
Browse files Browse the repository at this point in the history
  • Loading branch information
jmshrv committed Apr 9, 2021
1 parent 8bb3049 commit e7a5860
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
15 changes: 2 additions & 13 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';

import 'generateMaterialColor.dart';
import 'setupLogging.dart';
import 'screens/UserSelector.dart';
import 'screens/MusicScreen.dart';
import 'screens/ViewSelector.dart';
Expand All @@ -26,26 +27,14 @@ import 'models/FinampModels.dart';

void main() async {
await setupHive();
_setupLogging();
setupLogging();
_setupJellyfinApiData();
await _setupDownloader();
_setupDownloadsHelper();
_setupAudioServiceHelper();
runApp(Finamp());
}

void _setupLogging() {
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((event) {
if (kDebugMode) {
print(
"[${event.loggerName}/${event.level.name}] ${event.time}: ${event.message}");
}
Hive.box<FinampLogRecord>("FinampLogs")
.add(FinampLogRecord.fromLogRecord(event));
});
}

void _setupJellyfinApiData() {
GetIt.instance.registerSingleton(JellyfinApiData());
}
Expand Down
2 changes: 1 addition & 1 deletion lib/models/JellyfinModels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,7 @@ class NameLongIdPair {
NameLongIdPair(this.name, this.id);

final String name;
final int id;
final String id;

factory NameLongIdPair.fromJson(Map<String, dynamic> json) =>
_$NameLongIdPairFromJson(json);
Expand Down
2 changes: 1 addition & 1 deletion lib/models/JellyfinModels.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions lib/services/MusicPlayerBackgroundTask.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import 'JellyfinApiData.dart';
import 'DownloadsHelper.dart';
import 'FinampSettingsHelper.dart';
import '../models/JellyfinModels.dart';
import '../models/FinampModels.dart';
import '../main.dart';
import '../setupLogging.dart';

/// This provider handles the currently playing music so that multiple widgets can control music.
class MusicPlayerBackgroundTask extends BackgroundAudioTask {
Expand All @@ -32,13 +34,14 @@ class MusicPlayerBackgroundTask extends BackgroundAudioTask {
@override
Future<void> onStart(Map<String, dynamic> params) async {
try {
// Set up Hive in this isolate
await setupHive();
setupLogging();
audioServiceBackgroundTaskLogger.info("Starting audio service");

// Set up an instance of JellyfinApiData since get_it can't talk across isolates
GetIt.instance.registerLazySingleton(() => JellyfinApiData());

// Set up Hive in this isolate
await setupHive();
_downloadedItemsBox = Hive.box("DownloadedItems");

// Initialise FlutterDownloader in this isolate (only needed to check if file download is complete)
Expand Down
17 changes: 17 additions & 0 deletions lib/setupLogging.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart';
import 'package:logging/logging.dart';

import 'models/FinampModels.dart';

void setupLogging() {
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((event) {
if (kDebugMode) {
print(
"[${event.loggerName}/${event.level.name}] ${event.time}: ${event.message}");
}
Hive.box<FinampLogRecord>("FinampLogs")
.add(FinampLogRecord.fromLogRecord(event));
});
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.1.0
version: 0.1.1

environment:
sdk: ">=2.10.0 <3.0.0"
Expand Down

0 comments on commit e7a5860

Please sign in to comment.