diff --git a/mobile/lib/constants/hive_box.dart b/mobile/lib/constants/hive_box.dart deleted file mode 100644 index d14498909..000000000 --- a/mobile/lib/constants/hive_box.dart +++ /dev/null @@ -1,37 +0,0 @@ -// Access token -const String userInfoBox = "immichBoxUserInfo"; // Box -const String accessTokenKey = "immichBoxAccessTokenKey"; // Key 1 -const String deviceIdKey = 'immichBoxDeviceIdKey'; // Key 2 -const String isLoggedInKey = 'immichIsLoggedInKey'; // Key 3 -const String serverEndpointKey = 'immichBoxServerEndpoint'; // Key 4 -const String assetEtagKey = 'immichAssetEtagKey'; // Key 5 -const String userIdKey = 'immichUserIdKey'; // Key 6 - -// Login Info -const String hiveLoginInfoBox = "immichLoginInfoBox"; // Box -const String savedLoginInfoKey = "immichSavedLoginInfoKey"; // Key 1 - -// Backup Info -const String hiveBackupInfoBox = "immichBackupAlbumInfoBox"; // Box -const String backupInfoKey = "immichBackupAlbumInfoKey"; // Key 1 - -// Github Release Info -const String hiveGithubReleaseInfoBox = "immichGithubReleaseInfoBox"; // Box -const String githubReleaseInfoKey = "immichGithubReleaseInfoKey"; // Key 1 - -// User Setting Info -const String userSettingInfoBox = "immichUserSettingInfoBox"; - -// Background backup Info -const String backgroundBackupInfoBox = "immichBackgroundBackupInfoBox"; // Box -const String backupFailedSince = "immichBackupFailedSince"; // Key 1 -const String backupRequireWifi = "immichBackupRequireWifi"; // Key 2 -const String backupRequireCharging = "immichBackupRequireCharging"; // Key 3 -const String backupTriggerDelay = "immichBackupTriggerDelay"; // Key 4 - -// Duplicate asset -const String duplicatedAssetsBox = "immichDuplicatedAssetsBox"; // Box -const String duplicatedAssetsKey = "immichDuplicatedAssetsKey"; // Key 1 - -// In app logger -const String immichLoggerBox = "immichInAppLogger"; // Box \ No newline at end of file diff --git a/mobile/lib/main.dart b/mobile/lib/main.dart index 97a886a92..dda5bd604 100644 --- a/mobile/lib/main.dart +++ b/mobile/lib/main.dart @@ -6,17 +6,13 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_displaymode/flutter_displaymode.dart'; -import 'package:hive_flutter/hive_flutter.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:immich_mobile/constants/locales.dart'; import 'package:immich_mobile/modules/backup/background_service/background.service.dart'; import 'package:immich_mobile/modules/backup/models/backup_album.model.dart'; import 'package:immich_mobile/modules/backup/models/duplicated_asset.model.dart'; -import 'package:immich_mobile/modules/backup/models/hive_backup_albums.model.dart'; -import 'package:immich_mobile/modules/backup/models/hive_duplicated_assets.model.dart'; import 'package:immich_mobile/modules/backup/providers/backup.provider.dart'; import 'package:immich_mobile/modules/backup/providers/ios_background_settings.provider.dart'; -import 'package:immich_mobile/modules/login/models/hive_saved_login_info.model.dart'; import 'package:immich_mobile/modules/login/providers/authentication.provider.dart'; import 'package:immich_mobile/modules/onboarding/providers/gallery_permission.provider.dart'; import 'package:immich_mobile/modules/settings/providers/notification_permission.provider.dart'; @@ -25,7 +21,6 @@ import 'package:immich_mobile/routing/tab_navigation_observer.dart'; import 'package:immich_mobile/shared/models/album.dart'; import 'package:immich_mobile/shared/models/asset.dart'; import 'package:immich_mobile/shared/models/exif_info.dart'; -import 'package:immich_mobile/shared/models/immich_logger_message.model.dart'; import 'package:immich_mobile/shared/models/logger_message.model.dart'; import 'package:immich_mobile/shared/models/store.dart'; import 'package:immich_mobile/shared/models/user.dart'; @@ -50,18 +45,11 @@ void main() async { final db = await loadDb(); await initApp(); - await migrateHiveToStoreIfNecessary(); - await migrateJsonCacheIfNecessary(); await migrateDatabaseIfNeeded(db); runApp(getMainWidget(db)); } Future initApp() async { - await Hive.initFlutter(); - Hive.registerAdapter(HiveSavedLoginInfoAdapter()); - Hive.registerAdapter(HiveBackupAlbumsAdapter()); - Hive.registerAdapter(HiveDuplicatedAssetsAdapter()); - Hive.registerAdapter(ImmichLoggerMessageAdapter()); await EasyLocalization.ensureInitialized(); if (kReleaseMode && Platform.isAndroid) { diff --git a/mobile/lib/modules/album/services/album_cache.service.dart b/mobile/lib/modules/album/services/album_cache.service.dart deleted file mode 100644 index 5e3815aab..000000000 --- a/mobile/lib/modules/album/services/album_cache.service.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:immich_mobile/shared/models/album.dart'; -import 'package:immich_mobile/shared/services/json_cache.dart'; - -@Deprecated("only kept to remove its files after migration") -class _BaseAlbumCacheService extends JsonCache> { - _BaseAlbumCacheService(super.cacheFileName); - - @override - void put(List data) {} - - @override - Future?> get() => Future.value(null); -} - -@Deprecated("only kept to remove its files after migration") -class AlbumCacheService extends _BaseAlbumCacheService { - AlbumCacheService() : super("album_cache"); -} - -@Deprecated("only kept to remove its files after migration") -class SharedAlbumCacheService extends _BaseAlbumCacheService { - SharedAlbumCacheService() : super("shared_album_cache"); -} diff --git a/mobile/lib/modules/backup/models/hive_backup_albums.model.dart b/mobile/lib/modules/backup/models/hive_backup_albums.model.dart deleted file mode 100644 index e00d08359..000000000 --- a/mobile/lib/modules/backup/models/hive_backup_albums.model.dart +++ /dev/null @@ -1,105 +0,0 @@ -import 'dart:convert'; - -import 'package:collection/collection.dart'; -import 'package:hive/hive.dart'; - -part 'hive_backup_albums.model.g.dart'; - -@HiveType(typeId: 1) -class HiveBackupAlbums { - @HiveField(0) - List selectedAlbumIds; - - @HiveField(1) - List excludedAlbumsIds; - - @HiveField(2, defaultValue: []) - List lastSelectedBackupTime; - - @HiveField(3, defaultValue: []) - List lastExcludedBackupTime; - - HiveBackupAlbums({ - required this.selectedAlbumIds, - required this.excludedAlbumsIds, - required this.lastSelectedBackupTime, - required this.lastExcludedBackupTime, - }); - - @override - String toString() => - 'HiveBackupAlbums(selectedAlbumIds: $selectedAlbumIds, excludedAlbumsIds: $excludedAlbumsIds)'; - - HiveBackupAlbums copyWith({ - List? selectedAlbumIds, - List? excludedAlbumsIds, - List? lastSelectedBackupTime, - List? lastExcludedBackupTime, - }) { - return HiveBackupAlbums( - selectedAlbumIds: selectedAlbumIds ?? this.selectedAlbumIds, - excludedAlbumsIds: excludedAlbumsIds ?? this.excludedAlbumsIds, - lastSelectedBackupTime: - lastSelectedBackupTime ?? this.lastSelectedBackupTime, - lastExcludedBackupTime: - lastExcludedBackupTime ?? this.lastExcludedBackupTime, - ); - } - - /// Returns a deep copy to allow safe modification without changing the global - /// state of [HiveBackupAlbums] before actually saving the changes - HiveBackupAlbums deepCopy() { - return HiveBackupAlbums( - selectedAlbumIds: selectedAlbumIds.toList(), - excludedAlbumsIds: excludedAlbumsIds.toList(), - lastSelectedBackupTime: lastSelectedBackupTime.toList(), - lastExcludedBackupTime: lastExcludedBackupTime.toList(), - ); - } - - Map toMap() { - final result = {}; - - result.addAll({'selectedAlbumIds': selectedAlbumIds}); - result.addAll({'excludedAlbumsIds': excludedAlbumsIds}); - result.addAll({'lastSelectedBackupTime': lastSelectedBackupTime}); - result.addAll({'lastExcludedBackupTime': lastExcludedBackupTime}); - - return result; - } - - factory HiveBackupAlbums.fromMap(Map map) { - return HiveBackupAlbums( - selectedAlbumIds: List.from(map['selectedAlbumIds']), - excludedAlbumsIds: List.from(map['excludedAlbumsIds']), - lastSelectedBackupTime: - List.from(map['lastSelectedBackupTime']), - lastExcludedBackupTime: - List.from(map['lastExcludedBackupTime']), - ); - } - - String toJson() => json.encode(toMap()); - - factory HiveBackupAlbums.fromJson(String source) => - HiveBackupAlbums.fromMap(json.decode(source)); - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - final listEquals = const DeepCollectionEquality().equals; - - return other is HiveBackupAlbums && - listEquals(other.selectedAlbumIds, selectedAlbumIds) && - listEquals(other.excludedAlbumsIds, excludedAlbumsIds) && - listEquals(other.lastSelectedBackupTime, lastSelectedBackupTime) && - listEquals(other.lastExcludedBackupTime, lastExcludedBackupTime); - } - - @override - int get hashCode => - selectedAlbumIds.hashCode ^ - excludedAlbumsIds.hashCode ^ - lastSelectedBackupTime.hashCode ^ - lastExcludedBackupTime.hashCode; -} diff --git a/mobile/lib/modules/backup/models/hive_backup_albums.model.g.dart b/mobile/lib/modules/backup/models/hive_backup_albums.model.g.dart deleted file mode 100644 index 8ddc98146..000000000 --- a/mobile/lib/modules/backup/models/hive_backup_albums.model.g.dart +++ /dev/null @@ -1,52 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'hive_backup_albums.model.dart'; - -// ************************************************************************** -// TypeAdapterGenerator -// ************************************************************************** - -class HiveBackupAlbumsAdapter extends TypeAdapter { - @override - final int typeId = 1; - - @override - HiveBackupAlbums read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return HiveBackupAlbums( - selectedAlbumIds: (fields[0] as List).cast(), - excludedAlbumsIds: (fields[1] as List).cast(), - lastSelectedBackupTime: - fields[2] == null ? [] : (fields[2] as List).cast(), - lastExcludedBackupTime: - fields[3] == null ? [] : (fields[3] as List).cast(), - ); - } - - @override - void write(BinaryWriter writer, HiveBackupAlbums obj) { - writer - ..writeByte(4) - ..writeByte(0) - ..write(obj.selectedAlbumIds) - ..writeByte(1) - ..write(obj.excludedAlbumsIds) - ..writeByte(2) - ..write(obj.lastSelectedBackupTime) - ..writeByte(3) - ..write(obj.lastExcludedBackupTime); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is HiveBackupAlbumsAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} diff --git a/mobile/lib/modules/backup/models/hive_duplicated_assets.model.dart b/mobile/lib/modules/backup/models/hive_duplicated_assets.model.dart deleted file mode 100644 index 6313be8f9..000000000 --- a/mobile/lib/modules/backup/models/hive_duplicated_assets.model.dart +++ /dev/null @@ -1,57 +0,0 @@ -import 'dart:convert'; - -import 'package:collection/collection.dart'; -import 'package:hive/hive.dart'; - -part 'hive_duplicated_assets.model.g.dart'; - -@HiveType(typeId: 2) -class HiveDuplicatedAssets { - @HiveField(0, defaultValue: []) - List duplicatedAssetIds; - - HiveDuplicatedAssets({ - required this.duplicatedAssetIds, - }); - - HiveDuplicatedAssets copyWith({ - List? duplicatedAssetIds, - }) { - return HiveDuplicatedAssets( - duplicatedAssetIds: duplicatedAssetIds ?? this.duplicatedAssetIds, - ); - } - - Map toMap() { - return { - 'duplicatedAssetIds': duplicatedAssetIds, - }; - } - - factory HiveDuplicatedAssets.fromMap(Map map) { - return HiveDuplicatedAssets( - duplicatedAssetIds: List.from(map['duplicatedAssetIds']), - ); - } - - String toJson() => json.encode(toMap()); - - factory HiveDuplicatedAssets.fromJson(String source) => - HiveDuplicatedAssets.fromMap(json.decode(source)); - - @override - String toString() => - 'HiveDuplicatedAssets(duplicatedAssetIds: $duplicatedAssetIds)'; - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - final listEquals = const DeepCollectionEquality().equals; - - return other is HiveDuplicatedAssets && - listEquals(other.duplicatedAssetIds, duplicatedAssetIds); - } - - @override - int get hashCode => duplicatedAssetIds.hashCode; -} diff --git a/mobile/lib/modules/backup/models/hive_duplicated_assets.model.g.dart b/mobile/lib/modules/backup/models/hive_duplicated_assets.model.g.dart deleted file mode 100644 index 20f655498..000000000 --- a/mobile/lib/modules/backup/models/hive_duplicated_assets.model.g.dart +++ /dev/null @@ -1,42 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'hive_duplicated_assets.model.dart'; - -// ************************************************************************** -// TypeAdapterGenerator -// ************************************************************************** - -class HiveDuplicatedAssetsAdapter extends TypeAdapter { - @override - final int typeId = 2; - - @override - HiveDuplicatedAssets read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return HiveDuplicatedAssets( - duplicatedAssetIds: - fields[0] == null ? [] : (fields[0] as List).cast(), - ); - } - - @override - void write(BinaryWriter writer, HiveDuplicatedAssets obj) { - writer - ..writeByte(1) - ..writeByte(0) - ..write(obj.duplicatedAssetIds); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is HiveDuplicatedAssetsAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} diff --git a/mobile/lib/modules/login/models/hive_saved_login_info.model.dart b/mobile/lib/modules/login/models/hive_saved_login_info.model.dart deleted file mode 100644 index 456dbadbf..000000000 --- a/mobile/lib/modules/login/models/hive_saved_login_info.model.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:hive/hive.dart'; - -part 'hive_saved_login_info.model.g.dart'; - -@HiveType(typeId: 0) -class HiveSavedLoginInfo { - @HiveField(0) - String email; // DEPRECATED - - @HiveField(1) - String password; // DEPRECATED - - @HiveField(2) - String serverUrl; - - @HiveField(4, defaultValue: "") - String accessToken; - - HiveSavedLoginInfo({ - required this.email, - required this.password, - required this.serverUrl, - required this.accessToken, - }); -} diff --git a/mobile/lib/modules/login/models/hive_saved_login_info.model.g.dart b/mobile/lib/modules/login/models/hive_saved_login_info.model.g.dart deleted file mode 100644 index c86ccdfa4..000000000 --- a/mobile/lib/modules/login/models/hive_saved_login_info.model.g.dart +++ /dev/null @@ -1,50 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'hive_saved_login_info.model.dart'; - -// ************************************************************************** -// TypeAdapterGenerator -// ************************************************************************** - -class HiveSavedLoginInfoAdapter extends TypeAdapter { - @override - final int typeId = 0; - - @override - HiveSavedLoginInfo read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return HiveSavedLoginInfo( - email: fields[0] as String, - password: fields[1] as String, - serverUrl: fields[2] as String, - accessToken: fields[4] == null ? '' : fields[4] as String, - ); - } - - @override - void write(BinaryWriter writer, HiveSavedLoginInfo obj) { - writer - ..writeByte(4) - ..writeByte(0) - ..write(obj.email) - ..writeByte(1) - ..write(obj.password) - ..writeByte(2) - ..write(obj.serverUrl) - ..writeByte(4) - ..write(obj.accessToken); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is HiveSavedLoginInfoAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} diff --git a/mobile/lib/shared/models/immich_logger_message.model.dart b/mobile/lib/shared/models/immich_logger_message.model.dart deleted file mode 100644 index ae22d9780..000000000 --- a/mobile/lib/shared/models/immich_logger_message.model.dart +++ /dev/null @@ -1,34 +0,0 @@ -import 'package:hive/hive.dart'; - -part 'immich_logger_message.model.g.dart'; - -@HiveType(typeId: 3) -class ImmichLoggerMessage { - @HiveField(0) - String message; - - @HiveField(1, defaultValue: "INFO") - String level; - - @HiveField(2) - DateTime createdAt; - - @HiveField(3) - String? context1; - - @HiveField(4) - String? context2; - - ImmichLoggerMessage({ - required this.message, - required this.level, - required this.createdAt, - required this.context1, - required this.context2, - }); - - @override - String toString() { - return 'InAppLoggerMessage(message: $message, level: $level, createdAt: $createdAt)'; - } -} diff --git a/mobile/lib/shared/models/immich_logger_message.model.g.dart b/mobile/lib/shared/models/immich_logger_message.model.g.dart deleted file mode 100644 index 314d16507..000000000 --- a/mobile/lib/shared/models/immich_logger_message.model.g.dart +++ /dev/null @@ -1,53 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'immich_logger_message.model.dart'; - -// ************************************************************************** -// TypeAdapterGenerator -// ************************************************************************** - -class ImmichLoggerMessageAdapter extends TypeAdapter { - @override - final int typeId = 3; - - @override - ImmichLoggerMessage read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return ImmichLoggerMessage( - message: fields[0] as String, - level: fields[1] == null ? 'INFO' : fields[1] as String, - createdAt: fields[2] as DateTime, - context1: fields[3] as String?, - context2: fields[4] as String?, - ); - } - - @override - void write(BinaryWriter writer, ImmichLoggerMessage obj) { - writer - ..writeByte(5) - ..writeByte(0) - ..write(obj.message) - ..writeByte(1) - ..write(obj.level) - ..writeByte(2) - ..write(obj.createdAt) - ..writeByte(3) - ..write(obj.context1) - ..writeByte(4) - ..write(obj.context2); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is ImmichLoggerMessageAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} diff --git a/mobile/lib/shared/services/asset_cache.service.dart b/mobile/lib/shared/services/asset_cache.service.dart deleted file mode 100644 index 759c61f0b..000000000 --- a/mobile/lib/shared/services/asset_cache.service.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:immich_mobile/shared/models/asset.dart'; -import 'package:immich_mobile/shared/services/json_cache.dart'; - -@Deprecated("only kept to remove its files after migration") -class AssetCacheService extends JsonCache> { - AssetCacheService() : super("asset_cache"); - - @override - void put(List data) {} - - @override - Future?> get() => Future.value(null); -} diff --git a/mobile/lib/shared/services/json_cache.dart b/mobile/lib/shared/services/json_cache.dart deleted file mode 100644 index d51b7cee6..000000000 --- a/mobile/lib/shared/services/json_cache.dart +++ /dev/null @@ -1,36 +0,0 @@ -import 'dart:io'; - -import 'package:path_provider/path_provider.dart'; - -@Deprecated("only kept to remove its files after migration") -abstract class JsonCache { - final String cacheFileName; - - JsonCache(this.cacheFileName); - - Future _getCacheFile() async { - final basePath = await getTemporaryDirectory(); - final basePathName = basePath.path; - - final file = File("$basePathName/$cacheFileName.bin"); - - return file; - } - - Future isValid() async { - final file = await _getCacheFile(); - return await file.exists(); - } - - Future invalidate() async { - try { - final file = await _getCacheFile(); - await file.delete(); - } on FileSystemException { - // file is already deleted - } - } - - void put(T data); - Future get(); -} diff --git a/mobile/lib/utils/migration.dart b/mobile/lib/utils/migration.dart index a74c8427a..56e9ba8df 100644 --- a/mobile/lib/utils/migration.dart +++ b/mobile/lib/utils/migration.dart @@ -1,151 +1,9 @@ -// ignore_for_file: deprecated_member_use_from_same_package - import 'dart:async'; -import 'package:flutter/cupertino.dart'; -import 'package:hive/hive.dart'; -import 'package:immich_mobile/constants/hive_box.dart'; -import 'package:immich_mobile/modules/album/services/album_cache.service.dart'; -import 'package:immich_mobile/modules/backup/models/backup_album.model.dart'; -import 'package:immich_mobile/modules/backup/models/duplicated_asset.model.dart'; -import 'package:immich_mobile/modules/backup/models/hive_backup_albums.model.dart'; -import 'package:immich_mobile/modules/backup/models/hive_duplicated_assets.model.dart'; -import 'package:immich_mobile/modules/login/models/hive_saved_login_info.model.dart'; -import 'package:immich_mobile/modules/settings/services/app_settings.service.dart'; -import 'package:immich_mobile/shared/models/immich_logger_message.model.dart'; import 'package:immich_mobile/shared/models/store.dart'; -import 'package:immich_mobile/shared/services/asset_cache.service.dart'; import 'package:immich_mobile/utils/db.dart'; import 'package:isar/isar.dart'; -Future migrateHiveToStoreIfNecessary() async { - await _migrateHiveBoxIfNecessary(userInfoBox, _migrateHiveUserInfoBox); - await _migrateHiveBoxIfNecessary( - backgroundBackupInfoBox, - _migrateHiveBackgroundBackupInfoBox, - ); - await _migrateHiveBoxIfNecessary(hiveBackupInfoBox, _migrateBackupInfoBox); - await _migrateHiveBoxIfNecessary( - duplicatedAssetsBox, - _migrateDuplicatedAssetsBox, - ); - await _migrateHiveBoxIfNecessary( - hiveGithubReleaseInfoBox, - _migrateReleaseInfoBox, - ); - - await _migrateHiveBoxIfNecessary(hiveLoginInfoBox, _migrateLoginInfoBox); - await _migrateHiveBoxIfNecessary( - immichLoggerBox, - (Box box) => box.deleteFromDisk(), - ); - await _migrateHiveBoxIfNecessary(userSettingInfoBox, _migrateAppSettingsBox); -} - -FutureOr _migrateReleaseInfoBox(Box box) => - _migrateKey(box, githubReleaseInfoKey, StoreKey.githubReleaseInfo); - -Future _migrateLoginInfoBox(Box box) async { - final HiveSavedLoginInfo? info = box.get(savedLoginInfoKey); - if (info != null) { - await Store.put(StoreKey.serverUrl, info.serverUrl); - await Store.put(StoreKey.accessToken, info.accessToken); - } -} - -Future _migrateHiveUserInfoBox(Box box) async { - await _migrateKey(box, assetEtagKey, StoreKey.assetETag); - if (Store.tryGet(StoreKey.deviceId) == null) { - await _migrateKey(box, deviceIdKey, StoreKey.deviceId); - } - await _migrateKey(box, serverEndpointKey, StoreKey.serverEndpoint); -} - -Future _migrateHiveBackgroundBackupInfoBox(Box box) async { - await _migrateKey(box, backupFailedSince, StoreKey.backupFailedSince); - await _migrateKey(box, backupRequireWifi, StoreKey.backupRequireWifi); - await _migrateKey(box, backupRequireCharging, StoreKey.backupRequireCharging); - await _migrateKey(box, backupTriggerDelay, StoreKey.backupTriggerDelay); -} - -FutureOr _migrateBackupInfoBox(Box box) { - final HiveBackupAlbums? infos = box.get(backupInfoKey); - if (infos != null) { - final Isar? db = Isar.getInstance(); - if (db == null) { - throw Exception("_migrateBackupInfoBox could not load database"); - } - List albums = []; - for (int i = 0; i < infos.selectedAlbumIds.length; i++) { - final album = BackupAlbum( - infos.selectedAlbumIds[i], - infos.lastSelectedBackupTime[i], - BackupSelection.select, - ); - albums.add(album); - } - for (int i = 0; i < infos.excludedAlbumsIds.length; i++) { - final album = BackupAlbum( - infos.excludedAlbumsIds[i], - infos.lastExcludedBackupTime[i], - BackupSelection.exclude, - ); - albums.add(album); - } - return db.writeTxn(() => db.backupAlbums.putAll(albums)); - } -} - -FutureOr _migrateDuplicatedAssetsBox(Box box) { - final HiveDuplicatedAssets? duplicatedAssets = box.get(duplicatedAssetsKey); - if (duplicatedAssets != null) { - final Isar? db = Isar.getInstance(); - if (db == null) { - throw Exception("_migrateBackupInfoBox could not load database"); - } - final duplicatedAssetIds = duplicatedAssets.duplicatedAssetIds - .map((id) => DuplicatedAsset(id)) - .toList(); - return db.writeTxn(() => db.duplicatedAssets.putAll(duplicatedAssetIds)); - } -} - -Future _migrateAppSettingsBox(Box box) async { - for (AppSettingsEnum s in AppSettingsEnum.values) { - if (s.hiveKey != null) { - await _migrateKey(box, s.hiveKey!, s.storeKey); - } - } -} - -Future _migrateHiveBoxIfNecessary( - String boxName, - FutureOr Function(Box) migrate, -) async { - try { - if (await Hive.boxExists(boxName)) { - final box = await Hive.openBox(boxName); - await migrate(box); - await box.deleteFromDisk(); - } - } catch (e) { - debugPrint("Error while migrating $boxName $e"); - } -} - -FutureOr _migrateKey(Box box, String hiveKey, StoreKey key) { - final T? value = box.get(hiveKey); - if (value != null) { - return Store.put(key, value); - } -} - -Future migrateJsonCacheIfNecessary() async { - await AlbumCacheService().invalidate(); - await SharedAlbumCacheService().invalidate(); - await AssetCacheService().invalidate(); -} - Future migrateDatabaseIfNeeded(Isar db) async { final int version = Store.get(StoreKey.version, 1); switch (version) { diff --git a/mobile/pubspec.lock b/mobile/pubspec.lock index 218666cc4..9e25b5341 100644 --- a/mobile/pubspec.lock +++ b/mobile/pubspec.lock @@ -511,30 +511,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.2.0" - hive: - dependency: "direct main" - description: - name: hive - sha256: "8dcf6db979d7933da8217edcec84e9df1bdb4e4edc7fc77dbd5aa74356d6d941" - url: "https://pub.dev" - source: hosted - version: "2.2.3" - hive_flutter: - dependency: "direct main" - description: - name: hive_flutter - sha256: dca1da446b1d808a51689fb5d0c6c9510c0a2ba01e22805d492c73b68e33eecc - url: "https://pub.dev" - source: hosted - version: "1.1.0" - hive_generator: - dependency: "direct dev" - description: - name: hive_generator - sha256: "65998cc4d2cd9680a3d9709d893d2f6bb15e6c1f92626c3f1fa650b4b3281521" - url: "https://pub.dev" - source: hosted - version: "2.0.0" hooks_riverpod: dependency: "direct main" description: @@ -1152,14 +1128,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.6" - source_helper: - dependency: transitive - description: - name: source_helper - sha256: "3b67aade1d52416149c633ba1bb36df44d97c6b51830c2198e934e3fca87ca1f" - url: "https://pub.dev" - source: hosted - version: "1.3.3" source_span: dependency: transitive description: diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yaml index 28c9f5511..2ceb307ec 100644 --- a/mobile/pubspec.yaml +++ b/mobile/pubspec.yaml @@ -16,8 +16,6 @@ dependencies: photo_manager: ^2.5.0 flutter_hooks: ^0.18.6 hooks_riverpod: ^2.2.0 - hive: ^2.2.1 - hive_flutter: ^1.1.0 cached_network_image: ^3.2.2 intl: ^0.18.0 auto_route: ^5.0.1 @@ -59,7 +57,6 @@ dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^2.0.1 - hive_generator: ^2.0.0 build_runner: ^2.2.1 auto_route_generator: ^5.0.2 flutter_launcher_icons: "^0.9.2"