mirror of
https://github.com/jagandeepbrar/lunasea.git
synced 2026-08-30 20:24:25 +00:00
NEW - [Settings/Modules] Add an information/help button with module descriptions and links TWEAKS - [Radarr] Always show the amount of days content will be available instead of limiting it to only content in the next 30 days - [Settings] Moved "Backup & Restore" and "Logs" to "System" section - [Settings] Merged "Customization" and "Modules" sections into "Configuration" - [Settings/Sonarr] Removed the need to enable Sonarr to test the connection - [Settings/Tautulli] Removed the need to enable Tautulli to test the connection FIXES - [IAPs] Ensure all IAPs are marked as "consumed" - [Flutter] Updated packages - [Logging] Updated Sentry to v4 framework to improve capturing fatal/crashing bugs - [Settings/Logs] Hide exception and stack trace buttons when an error is not available - [Sonarr/History] Fixed history fetching the oldest entries, not the newest - [State] Correctly clear state when clearing LunaSea's configuration - [Tautulli/Activity] Fixed consistency of hardware transcoding indicator compared to the web UI - [UI/Divider] Fix consistency of divider width across regular and AMOLED dark theme
95 lines
3.6 KiB
Dart
95 lines
3.6 KiB
Dart
// Imports
|
|
import 'package:hive/hive.dart';
|
|
import 'package:hive_flutter/hive_flutter.dart';
|
|
import 'package:lunasea/core.dart';
|
|
import 'package:lunasea/modules/home/core.dart' show HomeDatabase;
|
|
import 'package:lunasea/modules/search/core.dart' show SearchDatabase;
|
|
import 'package:lunasea/modules/settings/core.dart' show SettingsDatabase;
|
|
import 'package:lunasea/modules/lidarr/core.dart' show LidarrDatabase;
|
|
import 'package:lunasea/modules/radarr/core.dart' show RadarrDatabase;
|
|
import 'package:lunasea/modules/sonarr/core.dart' show SonarrDatabase;
|
|
import 'package:lunasea/modules/nzbget/core.dart' show NZBGetDatabase;
|
|
import 'package:lunasea/modules/sabnzbd/core.dart' show SABnzbdDatabase;
|
|
import 'package:lunasea/modules/ombi/core.dart' show OmbiDatabase;
|
|
import 'package:lunasea/modules/tautulli/core.dart' show TautulliDatabase;
|
|
// Exports
|
|
export 'package:hive/hive.dart';
|
|
export 'package:hive_flutter/hive_flutter.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
|
|
static Future<void> initialize() async {
|
|
await Hive.initFlutter(_DATABASE_PATH);
|
|
_registerAdapters();
|
|
await _openBoxes();
|
|
if(profilesBox.keys.length == 0) setDefaults();
|
|
}
|
|
|
|
/// Deinitialize the database by closing all open hive boxes.
|
|
static Future<void> deinitialize() async => await Hive.close();
|
|
|
|
/// Registers all necessary object adapters for Hive.
|
|
static void _registerAdapters() {
|
|
//Core
|
|
Hive.registerAdapter(IndexerHiveObjectAdapter());
|
|
Hive.registerAdapter(ProfileHiveObjectAdapter());
|
|
//General
|
|
LunaDatabase().registerAdapters();
|
|
HomeDatabase().registerAdapters();
|
|
SearchDatabase().registerAdapters();
|
|
SettingsDatabase().registerAdapters();
|
|
//Automation
|
|
LidarrDatabase().registerAdapters();
|
|
RadarrDatabase().registerAdapters();
|
|
SonarrDatabase().registerAdapters();
|
|
//Clients
|
|
NZBGetDatabase().registerAdapters();
|
|
SABnzbdDatabase().registerAdapters();
|
|
//Monitoring
|
|
OmbiDatabase().registerAdapters();
|
|
TautulliDatabase().registerAdapters();
|
|
}
|
|
|
|
/// Open all Hive boxes for reading.
|
|
static Future<void> _openBoxes() async {
|
|
await Hive.openBox('lunasea');
|
|
await Hive.openBox<IndexerHiveObject>('indexers');
|
|
await Hive.openBox<ProfileHiveObject>('profiles');
|
|
}
|
|
|
|
/// Set the default state for all hive boxes.
|
|
static void setDefaults() {
|
|
//Clear all the boxes
|
|
clearAllBoxes();
|
|
//Set default profile & enabled profile
|
|
profilesBox.put('default', ProfileHiveObject.empty());
|
|
lunaSeaBox.put(LunaDatabaseValue.ENABLED_PROFILE.key, 'default');
|
|
}
|
|
|
|
//Get boxes
|
|
static Box get lunaSeaBox => Hive.box('lunasea');
|
|
static Box get profilesBox => Hive.box<ProfileHiveObject>('profiles');
|
|
static Box get indexersBox => Hive.box<IndexerHiveObject>('indexers');
|
|
|
|
//Clear boxes
|
|
static void clearLunaSeaBox() => lunaSeaBox.deleteAll(lunaSeaBox.keys);
|
|
static void clearProfilesBox() => profilesBox.deleteAll(profilesBox.keys);
|
|
static void clearIndexersBox() => indexersBox.deleteAll(indexersBox.keys);
|
|
static void clearAllBoxes() {
|
|
clearLunaSeaBox();
|
|
clearProfilesBox();
|
|
clearIndexersBox();
|
|
}
|
|
|
|
//Profile values
|
|
static String get currentProfile => lunaSeaBox.get('profile');
|
|
static ProfileHiveObject get currentProfileObject => profilesBox.get(currentProfile);
|
|
}
|