Skip to content

Commit

Permalink
Readd FinampLogRecord and FinampLevel adapters (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmshrv committed Apr 10, 2021
1 parent 1e61803 commit 2dace74
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Future<void> setupHive() async {
Hive.registerAdapter(ResponseProfileAdapter());
Hive.registerAdapter(SubtitleProfileAdapter());
Hive.registerAdapter(FinampSettingsAdapter());
Hive.registerAdapter(FinampLogRecordAdapter());
Hive.registerAdapter(FinampLevelAdapter());
await Future.wait([
Hive.openBox<DownloadedParent>("DownloadedParents"),
Hive.openBox<DownloadedSong>("DownloadedItems"),
Expand All @@ -109,7 +111,7 @@ Future<void> setupHive() async {
finampSettingsBox.put("FinampSettings", FinampSettings());

// Initial releases of the app used Hive to store logs. This removes the logs box from the disk if it exists.
// TODO: Remove this in a few months (added 2021-04-09)
// TODO: Remove this (and the hive adapters for FinampLogRecord and FinampLevel) in a few months (added 2021-04-09)
if (await Hive.boxExists("FinampLogs")) {
await Hive.openBox("FinampLogs");
await Hive.box("FinampLogs").deleteFromDisk();
Expand Down
8 changes: 8 additions & 0 deletions lib/models/FinampModels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class FinampSettings {
/// Once audio_service 0.18.0 releases, this won't be needed anymore.
/// Serialisation is only needed so that we can pass these objects through isolates.
@JsonSerializable(explicitToJson: true)
@HiveType(typeId: 29)
class FinampLogRecord {
FinampLogRecord({
this.level,
Expand All @@ -50,13 +51,17 @@ class FinampLogRecord {
this.time,
});

@HiveField(0)
final FinampLevel level;
@HiveField(1)
final String message;

/// Logger where this record is stored.
@HiveField(2)
final String loggerName;

/// Time when this record was created.
@HiveField(3)
final DateTime time;

static FinampLogRecord fromLogRecord(LogRecord logRecord) => FinampLogRecord(
Expand All @@ -72,11 +77,14 @@ class FinampLogRecord {
}

@JsonSerializable(explicitToJson: true)
@HiveType(typeId: 30)
class FinampLevel implements Comparable<FinampLevel> {
@HiveField(0)
final String name;

/// Unique value for this level. Used to order levels, so filtering can
/// exclude messages whose level is under certain value.
@HiveField(1)
final int value;

const FinampLevel(this.name, this.value);
Expand Down
80 changes: 80 additions & 0 deletions lib/models/FinampModels.g.dart

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

0 comments on commit 2dace74

Please sign in to comment.