mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
chore: versioning of Hive boxes
This commit is contained in:
parent
b54ee96233
commit
c429e6f48d
@ -96,21 +96,33 @@ Future<void> main(List<String> rawArgs) async {
|
|||||||
|
|
||||||
await SystemTheme.accentColor.load();
|
await SystemTheme.accentColor.load();
|
||||||
MetadataGod.initialize();
|
MetadataGod.initialize();
|
||||||
|
|
||||||
|
final hiveCacheDir = (await getApplicationSupportDirectory()).path;
|
||||||
|
|
||||||
await QueryClient.initialize(
|
await QueryClient.initialize(
|
||||||
cachePrefix: "oss.krtirtho.spotube",
|
cachePrefix: "oss.krtirtho.spotube",
|
||||||
cacheDir: (await getApplicationSupportDirectory()).path,
|
cacheDir: hiveCacheDir,
|
||||||
connectivity: FlQueryConnectivityPlusAdapter(),
|
connectivity: FlQueryConnectivityPlusAdapter(),
|
||||||
);
|
);
|
||||||
Hive.registerAdapter(MatchedTrackAdapter());
|
Hive.registerAdapter(MatchedTrackAdapter());
|
||||||
Hive.registerAdapter(SkipSegmentAdapter());
|
Hive.registerAdapter(SkipSegmentAdapter());
|
||||||
Hive.registerAdapter(SearchModeAdapter());
|
Hive.registerAdapter(SearchModeAdapter());
|
||||||
|
|
||||||
|
// Cache versioning entities with Adapter
|
||||||
|
MatchedTrack.version = 'v1';
|
||||||
|
SkipSegment.version = 'v1';
|
||||||
|
|
||||||
await Hive.openLazyBox<MatchedTrack>(
|
await Hive.openLazyBox<MatchedTrack>(
|
||||||
MatchedTrack.boxName,
|
MatchedTrack.boxName,
|
||||||
path: (await getApplicationSupportDirectory()).path,
|
path: hiveCacheDir,
|
||||||
|
);
|
||||||
|
await Hive.openLazyBox<List<SkipSegment>>(
|
||||||
|
SkipSegment.boxName,
|
||||||
|
path: hiveCacheDir,
|
||||||
|
);
|
||||||
|
await PersistedStateNotifier.initializeBoxes(
|
||||||
|
path: hiveCacheDir,
|
||||||
);
|
);
|
||||||
|
|
||||||
await PersistedStateNotifier.initializeBoxes();
|
|
||||||
|
|
||||||
Catcher(
|
Catcher(
|
||||||
enableLogger: arguments["verbose"],
|
enableLogger: arguments["verbose"],
|
||||||
|
@ -15,7 +15,8 @@ class MatchedTrack {
|
|||||||
|
|
||||||
bool get isSynced => id != null;
|
bool get isSynced => id != null;
|
||||||
|
|
||||||
static const boxName = "oss.krtirtho.spotube.matched_tracks";
|
static String version = 'v1';
|
||||||
|
static final boxName = "oss.krtirtho.spotube.matched_tracks.$version";
|
||||||
|
|
||||||
static LazyBox<MatchedTrack> get box => Hive.lazyBox<MatchedTrack>(boxName);
|
static LazyBox<MatchedTrack> get box => Hive.lazyBox<MatchedTrack>(boxName);
|
||||||
|
|
||||||
|
@ -10,8 +10,10 @@ class SkipSegment {
|
|||||||
final int end;
|
final int end;
|
||||||
SkipSegment(this.start, this.end);
|
SkipSegment(this.start, this.end);
|
||||||
|
|
||||||
static const boxName = "oss.krtirtho.spotube.skip_segments";
|
static String version = 'v1';
|
||||||
static LazyBox<SkipSegment> get box => Hive.lazyBox<SkipSegment>(boxName);
|
static final boxName = "oss.krtirtho.spotube.skip_segments.$version";
|
||||||
|
static LazyBox<List<SkipSegment>> get box =>
|
||||||
|
Hive.lazyBox<List<SkipSegment>>(boxName);
|
||||||
|
|
||||||
SkipSegment.fromJson(Map<String, dynamic> json)
|
SkipSegment.fromJson(Map<String, dynamic> json)
|
||||||
: start = json['start'],
|
: start = json['start'],
|
||||||
|
@ -4,7 +4,6 @@ import 'dart:convert';
|
|||||||
import 'package:catcher/catcher.dart';
|
import 'package:catcher/catcher.dart';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:hive/hive.dart';
|
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
import 'package:palette_generator/palette_generator.dart';
|
import 'package:palette_generator/palette_generator.dart';
|
||||||
import 'package:spotify/spotify.dart';
|
import 'package:spotify/spotify.dart';
|
||||||
@ -509,8 +508,7 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
|
|||||||
preferences.searchMode != SearchMode.youtube) return [];
|
preferences.searchMode != SearchMode.youtube) return [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final box = await Hive.openLazyBox<List>(SkipSegment.boxName);
|
final cached = await SkipSegment.box.get(id);
|
||||||
final cached = await box.get(id);
|
|
||||||
if (cached != null && cached.isNotEmpty) {
|
if (cached != null && cached.isNotEmpty) {
|
||||||
return List.castFrom<dynamic, SkipSegment>(cached);
|
return List.castFrom<dynamic, SkipSegment>(cached);
|
||||||
}
|
}
|
||||||
@ -550,13 +548,13 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
|
|||||||
"[SponsorBlock] successfully fetched skip segments for $id",
|
"[SponsorBlock] successfully fetched skip segments for $id",
|
||||||
);
|
);
|
||||||
|
|
||||||
await box.put(
|
await SkipSegment.box.put(
|
||||||
id,
|
id,
|
||||||
segments,
|
segments,
|
||||||
);
|
);
|
||||||
return List.castFrom<dynamic, SkipSegment>(segments);
|
return List.castFrom<dynamic, SkipSegment>(segments);
|
||||||
} catch (e, stack) {
|
} catch (e, stack) {
|
||||||
await box.put(id, []);
|
await SkipSegment.box.put(id, []);
|
||||||
Catcher.reportCheckedError(e, stack);
|
Catcher.reportCheckedError(e, stack);
|
||||||
return List.castFrom<dynamic, SkipSegment>([]);
|
return List.castFrom<dynamic, SkipSegment>([]);
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ abstract class PersistedStateNotifier<T> extends StateNotifier<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> initializeBoxes() async {
|
static Future<void> initializeBoxes({required String path}) async {
|
||||||
String? boxName = await read(kKeyBoxName);
|
String? boxName = await read(kKeyBoxName);
|
||||||
|
|
||||||
if (boxName == null) {
|
if (boxName == null) {
|
||||||
@ -73,7 +73,10 @@ abstract class PersistedStateNotifier<T> extends StateNotifier<T> {
|
|||||||
encryptionCipher: HiveAesCipher(base64Url.decode(encryptionKey)),
|
encryptionCipher: HiveAesCipher(base64Url.decode(encryptionKey)),
|
||||||
);
|
);
|
||||||
|
|
||||||
_box = await Hive.openLazyBox("spotube_cache");
|
_box = await Hive.openLazyBox(
|
||||||
|
"spotube_cache",
|
||||||
|
path: path,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
LazyBox get box => encrypted ? _encryptedBox : _box;
|
LazyBox get box => encrypted ? _encryptedBox : _box;
|
||||||
|
Loading…
Reference in New Issue
Block a user