mirror of
https://github.com/jagandeepbrar/lunasea.git
synced 2026-08-31 20:52:32 +00:00
NEW - [-Arr/Releases] Match torrent seeder colours to the web GUI - [Firebase/Analytics] Added analytics for breadcrumb tracking in crashes - [Logger] Utilize a new, custom built on-device logging system - [Logger] Compact/delete old log entries once the log count passes 100 - [Logger] Exported logs are now in JSON format - [Routing] Protect all module routes by showing a "Not Enabled" screen when the module is not enabled - [Settings/System] Added toggle to disable Firebase Analytics - [Tautulli/Activity] Show custom season titles from Plex's new TV agent TWEAKS - [Radarr/Files] Add languages to file block - [Radarr/Files] Small changes to table titles - [System/Logs] Reimplemented logger view - [System/Logs] Removed viewing the stack trace within the application (still viewable within the exported logs) - [System/Logs] Added the exception to the expanded table instead of a separate dialog popup - [Tautulli/Activity] Minor UI tweaks including showing the full season title and italicizing the episode title - [UI/Navbar] Jump instead of animate to page when tapping a navbar item FIXES - [Firebase/Crashes] Do not log DioError/networking exceptions - [Flutter] Updated packages - [Flutter] Upgrade all Comet.Tools packages to null-safety/NNBD - [Radarr/Releases] Negative format scores were not being shown - [Share] The sharesheet could break after the first time it was opened - [Strings] Safe-guard many substring operations - [Tautulli/Activity] Play/paused/buffering icon was not properly left aligned to the text - [Tautulli/Users] User images would not be fetched on newer versions of Tautulli - [UI/UX] Modal scroll controller was not being attached to the ListView in a bottom modal sheet - [UI/UX] Do not log errors when network images fail to load - [UI/UX] Prevent attempting to load background images that are passed an empty URL - [URLs] Safe-guard launching specific invalid URLs
88 lines
3.2 KiB
Dart
88 lines
3.2 KiB
Dart
import 'package:hive/hive.dart';
|
|
import 'package:hive_flutter/hive_flutter.dart';
|
|
import 'package:lunasea/core.dart';
|
|
import 'package:lunasea/modules.dart';
|
|
|
|
class Database {
|
|
static const String _DATABASE_PATH = 'database';
|
|
|
|
/// Initialize the database.
|
|
///
|
|
/// - Initializes Hive database path
|
|
/// - Register all adapters
|
|
/// - Open all boxes
|
|
/// - Set default database state of necessary
|
|
Future<void> initialize() async {
|
|
await Hive.initFlutter(_DATABASE_PATH);
|
|
_registerAdapters();
|
|
await _openBoxes();
|
|
if(profilesBox.keys.length == 0) setDefaults(clearEverything: true);
|
|
}
|
|
|
|
/// Deinitialize the database by closing all open hive boxes.
|
|
Future<void> deinitialize() async => await Hive.close();
|
|
|
|
/// Registers all necessary object adapters for Hive.
|
|
void _registerAdapters() {
|
|
//General
|
|
LunaDatabase().registerAdapters();
|
|
DashboardDatabase().registerAdapters();
|
|
SearchDatabase().registerAdapters();
|
|
//Automation
|
|
LidarrDatabase().registerAdapters();
|
|
RadarrDatabase().registerAdapters();
|
|
SonarrDatabase().registerAdapters();
|
|
//Clients
|
|
NZBGetDatabase().registerAdapters();
|
|
SABnzbdDatabase().registerAdapters();
|
|
//Monitoring
|
|
TautulliDatabase().registerAdapters();
|
|
}
|
|
|
|
/// Open all Hive boxes for reading.
|
|
Future<void> _openBoxes() async {
|
|
await Hive.openBox('alerts');
|
|
await Hive.openBox<IndexerHiveObject>('indexers');
|
|
await Hive.openBox<LunaLogHiveObject>('logs');
|
|
await Hive.openBox('lunasea');
|
|
await Hive.openBox<ProfileHiveObject>('profiles');
|
|
}
|
|
|
|
/// Set the default state for all hive boxes.
|
|
void setDefaults({ bool clearEverything = false }) {
|
|
//Clear all the boxes
|
|
clearAllBoxes(clearEverything: clearEverything);
|
|
//Set default profile & enabled profile
|
|
profilesBox.put('default', ProfileHiveObject.empty());
|
|
lunaSeaBox.put(LunaDatabaseValue.ENABLED_PROFILE.key, 'default');
|
|
}
|
|
|
|
//Get boxes
|
|
static Box get alertsBox => Hive.box('alerts');
|
|
static Box<IndexerHiveObject> get indexersBox => Hive.box<IndexerHiveObject>('indexers');
|
|
static Box<LunaLogHiveObject> get logsBox => Hive.box<LunaLogHiveObject>('logs');
|
|
static Box get lunaSeaBox => Hive.box('lunasea');
|
|
static Box<ProfileHiveObject> get profilesBox => Hive.box<ProfileHiveObject>('profiles');
|
|
|
|
//Clear boxes
|
|
void clearAlertsBox() => alertsBox.deleteAll(alertsBox.keys);
|
|
void clearIndexersBox() => indexersBox.deleteAll(indexersBox.keys);
|
|
void clearLogsBox() => logsBox.deleteAll(logsBox.keys);
|
|
void clearLunaSeaBox() => lunaSeaBox.deleteAll(lunaSeaBox.keys);
|
|
void clearProfilesBox() => profilesBox.deleteAll(profilesBox.keys);
|
|
|
|
void clearAllBoxes({ bool clearEverything = false }) {
|
|
clearLunaSeaBox();
|
|
clearProfilesBox();
|
|
clearIndexersBox();
|
|
if(clearEverything) {
|
|
clearAlertsBox();
|
|
clearLogsBox();
|
|
}
|
|
}
|
|
|
|
//Profile values
|
|
static String get currentProfile => lunaSeaBox.get('profile');
|
|
static ProfileHiveObject get currentProfileObject => profilesBox.get(currentProfile);
|
|
}
|