chore: bump line length to 120 (#20191)

This commit is contained in:
shenlong
2025-07-25 08:07:22 +05:30
committed by GitHub
parent 977c9b96ba
commit ad65e9011a
517 changed files with 4520 additions and 9514 deletions

View File

@@ -34,8 +34,7 @@ import 'package:logging/logging.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:photo_manager/photo_manager.dart' show PMProgressHandler;
final backupProvider =
StateNotifierProvider<BackupNotifier, BackUpState>((ref) {
final backupProvider = StateNotifierProvider<BackupNotifier, BackUpState>((ref) {
return BackupNotifier(
ref.watch(backupServiceProvider),
ref.watch(serverInfoServiceProvider),
@@ -74,8 +73,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
autoBackup: Store.get(StoreKey.autoBackup, false),
backgroundBackup: Store.get(StoreKey.backgroundBackup, false),
backupRequireWifi: Store.get(StoreKey.backupRequireWifi, true),
backupRequireCharging:
Store.get(StoreKey.backupRequireCharging, false),
backupRequireCharging: Store.get(StoreKey.backupRequireCharging, false),
backupTriggerDelay: Store.get(StoreKey.backupTriggerDelay, 5000),
serverInfo: const ServerDiskInfo(
diskAvailable: "0",
@@ -124,16 +122,14 @@ class BackupNotifier extends StateNotifier<BackUpState> {
removeExcludedAlbumForBackup(album);
}
state = state
.copyWith(selectedBackupAlbums: {...state.selectedBackupAlbums, album});
state = state.copyWith(selectedBackupAlbums: {...state.selectedBackupAlbums, album});
}
void addExcludedAlbumForBackup(AvailableAlbum album) {
if (state.selectedBackupAlbums.contains(album)) {
removeAlbumForBackup(album);
}
state = state
.copyWith(excludedBackupAlbums: {...state.excludedBackupAlbums, album});
state = state.copyWith(excludedBackupAlbums: {...state.excludedBackupAlbums, album});
}
void removeAlbumForBackup(AvailableAlbum album) {
@@ -180,10 +176,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
required void Function() onBatteryInfo,
}) async {
assert(
enabled != null ||
requireWifi != null ||
requireCharging != null ||
triggerDelay != null,
enabled != null || requireWifi != null || requireCharging != null || triggerDelay != null,
);
final bool wasEnabled = state.backgroundBackup;
final bool wasWifi = state.backupRequireWifi;
@@ -257,9 +250,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
for (Album album in albums) {
AvailableAlbum availableAlbum = AvailableAlbum(
album: album,
assetCount: await ref
.read(albumMediaRepositoryProvider)
.getAssetCount(album.localId!),
assetCount: await ref.read(albumMediaRepositoryProvider).getAssetCount(album.localId!),
);
availableAlbums.add(availableAlbum);
@@ -268,10 +259,8 @@ class BackupNotifier extends StateNotifier<BackUpState> {
}
state = state.copyWith(availableAlbums: availableAlbums);
final List<BackupAlbum> excludedBackupAlbums =
await _backupAlbumService.getAllBySelection(BackupSelection.exclude);
final List<BackupAlbum> selectedBackupAlbums =
await _backupAlbumService.getAllBySelection(BackupSelection.select);
final List<BackupAlbum> excludedBackupAlbums = await _backupAlbumService.getAllBySelection(BackupSelection.exclude);
final List<BackupAlbum> selectedBackupAlbums = await _backupAlbumService.getAllBySelection(BackupSelection.select);
final Set<AvailableAlbum> selectedAlbums = {};
for (final BackupAlbum ba in selectedBackupAlbums) {
@@ -281,8 +270,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
selectedAlbums.add(
AvailableAlbum(
album: albumAsset,
assetCount:
await _albumMediaRepository.getAssetCount(albumAsset.localId!),
assetCount: await _albumMediaRepository.getAssetCount(albumAsset.localId!),
lastBackup: ba.lastBackup,
),
);
@@ -299,9 +287,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
excludedAlbums.add(
AvailableAlbum(
album: albumAsset,
assetCount: await ref
.read(albumMediaRepositoryProvider)
.getAssetCount(albumAsset.localId!),
assetCount: await ref.read(albumMediaRepositoryProvider).getAssetCount(albumAsset.localId!),
lastBackup: ba.lastBackup,
),
);
@@ -335,17 +321,13 @@ class BackupNotifier extends StateNotifier<BackUpState> {
final Set<BackupCandidate> assetsFromExcludedAlbums = {};
for (final album in state.selectedBackupAlbums) {
final assetCount = await ref
.read(albumMediaRepositoryProvider)
.getAssetCount(album.album.localId!);
final assetCount = await ref.read(albumMediaRepositoryProvider).getAssetCount(album.album.localId!);
if (assetCount == 0) {
continue;
}
final assets = await ref
.read(albumMediaRepositoryProvider)
.getAssets(album.album.localId!);
final assets = await ref.read(albumMediaRepositoryProvider).getAssets(album.album.localId!);
// Add album's name to the asset info
for (final asset in assets) {
@@ -370,17 +352,13 @@ class BackupNotifier extends StateNotifier<BackUpState> {
}
for (final album in state.excludedBackupAlbums) {
final assetCount = await ref
.read(albumMediaRepositoryProvider)
.getAssetCount(album.album.localId!);
final assetCount = await ref.read(albumMediaRepositoryProvider).getAssetCount(album.album.localId!);
if (assetCount == 0) {
continue;
}
final assets = await ref
.read(albumMediaRepositoryProvider)
.getAssets(album.album.localId!);
final assets = await ref.read(albumMediaRepositoryProvider).getAssets(album.album.localId!);
for (final asset in assets) {
assetsFromExcludedAlbums.add(
@@ -389,8 +367,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
}
}
final Set<BackupCandidate> allUniqueAssets =
assetsFromSelectedAlbums.difference(assetsFromExcludedAlbums);
final Set<BackupCandidate> allUniqueAssets = assetsFromSelectedAlbums.difference(assetsFromExcludedAlbums);
final allAssetsInDatabase = await _backupService.getDeviceBackupAsset();
@@ -399,11 +376,9 @@ class BackupNotifier extends StateNotifier<BackUpState> {
}
// Find asset that were backup from selected albums
final Set<String> selectedAlbumsBackupAssets =
Set.from(allUniqueAssets.map((e) => e.asset.localId));
final Set<String> selectedAlbumsBackupAssets = Set.from(allUniqueAssets.map((e) => e.asset.localId));
selectedAlbumsBackupAssets
.removeWhere((assetId) => !allAssetsInDatabase.contains(assetId));
selectedAlbumsBackupAssets.removeWhere((assetId) => !allAssetsInDatabase.contains(assetId));
// Remove duplicated asset from all unique assets
allUniqueAssets.removeWhere(
@@ -459,8 +434,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
final candidates = selected.followedBy(excluded).toList();
candidates.sortBy((e) => e.id);
final savedBackupAlbums =
await _backupAlbumService.getAll(sort: BackupAlbumSort.id);
final savedBackupAlbums = await _backupAlbumService.getAll(sort: BackupAlbumSort.id);
final List<int> toDelete = [];
final List<BackupAlbum> toUpsert = [];
@@ -469,8 +443,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
candidates,
compare: (BackupAlbum a, BackupAlbum b) => a.id.compareTo(b.id),
both: (BackupAlbum a, BackupAlbum b) {
b.lastBackup =
a.lastBackup.isAfter(b.lastBackup) ? a.lastBackup : b.lastBackup;
b.lastBackup = a.lastBackup.isAfter(b.lastBackup) ? a.lastBackup : b.lastBackup;
toUpsert.add(b);
return true;
},
@@ -569,8 +542,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
state = state.copyWith(
allUniqueAssets: state.allUniqueAssets
.where(
(candidate) =>
candidate.asset.localId != result.candidate.asset.localId,
(candidate) => candidate.asset.localId != result.candidate.asset.localId,
)
.toSet(),
);
@@ -587,21 +559,13 @@ class BackupNotifier extends StateNotifier<BackUpState> {
);
}
if (state.allUniqueAssets.length -
state.selectedAlbumsBackupAssetsIds.length ==
0) {
final latestAssetBackup = state.allUniqueAssets
.map((candidate) => candidate.asset.fileModifiedAt)
.reduce(
if (state.allUniqueAssets.length - state.selectedAlbumsBackupAssetsIds.length == 0) {
final latestAssetBackup = state.allUniqueAssets.map((candidate) => candidate.asset.fileModifiedAt).reduce(
(v, e) => e.isAfter(v) ? e : v,
);
state = state.copyWith(
selectedBackupAlbums: state.selectedBackupAlbums
.map((e) => e.copyWith(lastBackup: latestAssetBackup))
.toSet(),
excludedBackupAlbums: state.excludedBackupAlbums
.map((e) => e.copyWith(lastBackup: latestAssetBackup))
.toSet(),
selectedBackupAlbums: state.selectedBackupAlbums.map((e) => e.copyWith(lastBackup: latestAssetBackup)).toSet(),
excludedBackupAlbums: state.excludedBackupAlbums.map((e) => e.copyWith(lastBackup: latestAssetBackup)).toSet(),
backupProgress: BackUpProgressEnum.done,
progressInPercentage: 0.0,
progressInFileSize: "0 B / 0 B",
@@ -696,10 +660,8 @@ class BackupNotifier extends StateNotifier<BackUpState> {
}
Future<void> resumeBackup() async {
final List<BackupAlbum> selectedBackupAlbums =
await _backupAlbumService.getAllBySelection(BackupSelection.select);
final List<BackupAlbum> excludedBackupAlbums =
await _backupAlbumService.getAllBySelection(BackupSelection.exclude);
final List<BackupAlbum> selectedBackupAlbums = await _backupAlbumService.getAllBySelection(BackupSelection.select);
final List<BackupAlbum> excludedBackupAlbums = await _backupAlbumService.getAllBySelection(BackupSelection.exclude);
Set<AvailableAlbum> selectedAlbums = state.selectedBackupAlbums;
Set<AvailableAlbum> excludedAlbums = state.excludedBackupAlbums;
if (selectedAlbums.isNotEmpty) {

View File

@@ -4,8 +4,7 @@ import 'package:immich_mobile/domain/services/local_album.service.dart';
import 'package:immich_mobile/infrastructure/repositories/local_album.repository.dart';
import 'package:immich_mobile/providers/infrastructure/album.provider.dart';
final backupAlbumProvider =
StateNotifierProvider<BackupAlbumNotifier, List<LocalAlbum>>(
final backupAlbumProvider = StateNotifierProvider<BackupAlbumNotifier, List<LocalAlbum>>(
(ref) => BackupAlbumNotifier(
ref.watch(localAlbumServiceProvider),
),
@@ -19,8 +18,7 @@ class BackupAlbumNotifier extends StateNotifier<List<LocalAlbum>> {
final LocalAlbumService _localAlbumService;
Future<void> getAll() async {
state =
await _localAlbumService.getAll(sortBy: {SortLocalAlbumsBy.assetCount});
state = await _localAlbumService.getAll(sortBy: {SortLocalAlbumsBy.assetCount});
}
Future<void> selectAlbum(LocalAlbum album) async {
@@ -42,9 +40,8 @@ class BackupAlbumNotifier extends StateNotifier<List<LocalAlbum>> {
state = state
.map(
(currentAlbum) => currentAlbum.id == album.id
? currentAlbum.copyWith(backupSelection: BackupSelection.none)
: currentAlbum,
(currentAlbum) =>
currentAlbum.id == album.id ? currentAlbum.copyWith(backupSelection: BackupSelection.none) : currentAlbum,
)
.toList();
}

View File

@@ -23,8 +23,7 @@ class BackupVerification extends _$BackupVerification {
state = true;
final backupState = ref.read(backupProvider);
if (backupState.allUniqueAssets.length >
backupState.selectedAlbumsBackupAssetsIds.length) {
if (backupState.allUniqueAssets.length > backupState.selectedAlbumsBackupAssetsIds.length) {
if (context.mounted) {
ImmichToast.show(
context: context,
@@ -48,9 +47,7 @@ class BackupVerification extends _$BackupVerification {
WakelockPlus.enable();
const limit = 100;
final toDelete = await ref
.read(backupVerificationServiceProvider)
.findWronglyBackedUpAssets(limit: limit);
final toDelete = await ref.read(backupVerificationServiceProvider).findWronglyBackedUpAssets(limit: limit);
if (toDelete.isEmpty) {
if (context.mounted) {
ImmichToast.show(
@@ -67,8 +64,7 @@ class BackupVerification extends _$BackupVerification {
onOk: () => _performDeletion(context, toDelete),
title: "Corrupt backups!",
ok: "Delete",
content:
"Found ${toDelete.length} (max $limit at once) corrupt asset backups. "
content: "Found ${toDelete.length} (max $limit at once) corrupt asset backups. "
"Run the check again to find more.\n"
"Do you want to delete the corrupt asset backups now?",
),

View File

@@ -31,8 +31,7 @@ class EnqueueStatus {
}
@override
String toString() =>
'EnqueueStatus(enqueueCount: $enqueueCount, totalCount: $totalCount)';
String toString() => 'EnqueueStatus(enqueueCount: $enqueueCount, totalCount: $totalCount)';
}
class DriftUploadStatus {
@@ -198,8 +197,7 @@ class DriftBackupState {
}
}
final driftBackupProvider =
StateNotifierProvider<ExpBackupNotifier, DriftBackupState>((ref) {
final driftBackupProvider = StateNotifierProvider<ExpBackupNotifier, DriftBackupState>((ref) {
return ExpBackupNotifier(
ref.watch(driftBackupServiceProvider),
ref.watch(uploadServiceProvider),
@@ -235,8 +233,7 @@ class ExpBackupNotifier extends StateNotifier<DriftBackupState> {
/// Remove upload item from state
void _removeUploadItem(String taskId) {
if (state.uploadItems.containsKey(taskId)) {
final updatedItems =
Map<String, DriftUploadStatus>.from(state.uploadItems);
final updatedItems = Map<String, DriftUploadStatus>.from(state.uploadItems);
updatedItems.remove(taskId);
state = state.copyWith(uploadItems: updatedItems);
}

View File

@@ -17,7 +17,6 @@ class ErrorBackupListNotifier extends StateNotifier<Set<ErrorUploadAsset>> {
}
}
final errorBackupListProvider =
StateNotifierProvider<ErrorBackupListNotifier, Set<ErrorUploadAsset>>(
final errorBackupListProvider = StateNotifierProvider<ErrorBackupListNotifier, Set<ErrorUploadAsset>>(
(ref) => ErrorBackupListNotifier(),
);

View File

@@ -15,21 +15,17 @@ class IOSBackgroundSettings {
});
}
class IOSBackgroundSettingsNotifier
extends StateNotifier<IOSBackgroundSettings?> {
class IOSBackgroundSettingsNotifier extends StateNotifier<IOSBackgroundSettings?> {
final BackgroundService _service;
IOSBackgroundSettingsNotifier(this._service) : super(null);
IOSBackgroundSettings? get settings => state;
Future<IOSBackgroundSettings> refresh() async {
final lastFetchTime =
await _service.getIOSBackupLastRun(IosBackgroundTask.fetch);
final lastProcessingTime =
await _service.getIOSBackupLastRun(IosBackgroundTask.processing);
final lastFetchTime = await _service.getIOSBackupLastRun(IosBackgroundTask.fetch);
final lastProcessingTime = await _service.getIOSBackupLastRun(IosBackgroundTask.processing);
int numberOfProcesses = await _service.getIOSBackupNumberOfProcesses();
final appRefreshEnabled =
await _service.getIOSBackgroundAppRefreshEnabled();
final appRefreshEnabled = await _service.getIOSBackgroundAppRefreshEnabled();
// If this is enabled and there are no background processes,
// the user just enabled app refresh in Settings.
@@ -53,7 +49,6 @@ class IOSBackgroundSettingsNotifier
}
}
final iOSBackgroundSettingsProvider = StateNotifierProvider<
IOSBackgroundSettingsNotifier, IOSBackgroundSettings?>(
final iOSBackgroundSettingsProvider = StateNotifierProvider<IOSBackgroundSettingsNotifier, IOSBackgroundSettings?>(
(ref) => IOSBackgroundSettingsNotifier(ref.watch(backgroundServiceProvider)),
);

View File

@@ -31,8 +31,7 @@ import 'package:logging/logging.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:photo_manager/photo_manager.dart' show PMProgressHandler;
final manualUploadProvider =
StateNotifierProvider<ManualUploadNotifier, ManualUploadState>((ref) {
final manualUploadProvider = StateNotifierProvider<ManualUploadNotifier, ManualUploadState>((ref) {
return ManualUploadNotifier(
ref.watch(localNotificationService),
ref.watch(backupProvider.notifier),
@@ -82,8 +81,7 @@ class ManualUploadNotifier extends StateNotifier<ManualUploadState> {
String? _lastPrintedDetailTitle;
static const notifyInterval = Duration(milliseconds: 500);
late final ThrottleProgressUpdate _throttledNotifiy =
ThrottleProgressUpdate(_updateProgress, notifyInterval);
late final ThrottleProgressUpdate _throttledNotifiy = ThrottleProgressUpdate(_updateProgress, notifyInterval);
late final ThrottleProgressUpdate _throttledDetailNotify =
ThrottleProgressUpdate(_updateDetailProgress, notifyInterval);
@@ -106,11 +104,9 @@ class ManualUploadNotifier extends StateNotifier<ManualUploadState> {
void _updateDetailProgress(String? title, int progress, int total) {
// Guard against throttling calling this method after the upload is done
if (_backupProvider.backupProgress == BackUpProgressEnum.manualInProgress) {
final String msg =
total > 0 ? humanReadableBytesProgress(progress, total) : "";
final String msg = total > 0 ? humanReadableBytesProgress(progress, total) : "";
// only update if message actually differs (to stop many useless notification updates on large assets or slow connections)
if (msg != _lastPrintedDetailContent ||
title != _lastPrintedDetailTitle) {
if (msg != _lastPrintedDetailContent || title != _lastPrintedDetailTitle) {
_lastPrintedDetailContent = msg;
_lastPrintedDetailTitle = title;
_localNotificationService.showOrUpdateManualUploadStatus(
@@ -184,9 +180,8 @@ class ManualUploadNotifier extends StateNotifier<ManualUploadState> {
_throttledNotifiy();
}
if (state.showDetailedNotification) {
_throttledDetailNotify.title =
"backup_background_service_current_upload_notification"
.tr(namedArgs: {'filename': currentUploadAsset.fileName});
_throttledDetailNotify.title = "backup_background_service_current_upload_notification"
.tr(namedArgs: {'filename': currentUploadAsset.fileName});
_throttledDetailNotify.progress = 0;
_throttledDetailNotify.total = 0;
}
@@ -200,8 +195,7 @@ class ManualUploadNotifier extends StateNotifier<ManualUploadState> {
if (ref.read(galleryPermissionNotifier.notifier).hasPermission) {
await ref.read(fileMediaRepositoryProvider).clearFileCache();
final allAssetsFromDevice =
allManualUploads.where((e) => e.isLocal && !e.isRemote).toList();
final allAssetsFromDevice = allManualUploads.where((e) => e.isLocal && !e.isRemote).toList();
if (allAssetsFromDevice.length != allManualUploads.length) {
_log.warning(
@@ -209,14 +203,11 @@ class ManualUploadNotifier extends StateNotifier<ManualUploadState> {
);
}
final selectedBackupAlbums =
await _backupAlbumService.getAllBySelection(BackupSelection.select);
final excludedBackupAlbums = await _backupAlbumService
.getAllBySelection(BackupSelection.exclude);
final selectedBackupAlbums = await _backupAlbumService.getAllBySelection(BackupSelection.select);
final excludedBackupAlbums = await _backupAlbumService.getAllBySelection(BackupSelection.exclude);
// Get candidates from selected albums and excluded albums
Set<BackupCandidate> candidates =
await _backupService.buildUploadCandidates(
Set<BackupCandidate> candidates = await _backupService.buildUploadCandidates(
selectedBackupAlbums,
excludedBackupAlbums,
useTimeFilter: false,
@@ -260,13 +251,11 @@ class ManualUploadNotifier extends StateNotifier<ManualUploadState> {
}
// Show detailed asset if enabled in settings or if a single asset is uploaded
bool showDetailedNotification =
ref.read(appSettingsServiceProvider).getSetting<bool>(
AppSettingsEnum.backgroundBackupSingleProgress,
) ||
state.totalAssetsToUpload == 1;
state =
state.copyWith(showDetailedNotification: showDetailedNotification);
bool showDetailedNotification = ref.read(appSettingsServiceProvider).getSetting<bool>(
AppSettingsEnum.backgroundBackupSingleProgress,
) ||
state.totalAssetsToUpload == 1;
state = state.copyWith(showDetailedNotification: showDetailedNotification);
final pmProgressHandler = Platform.isIOS ? PMProgressHandler() : null;
final bool ok = await ref.read(backupServiceProvider).backupAsset(
@@ -297,8 +286,7 @@ class ManualUploadNotifier extends StateNotifier<ManualUploadState> {
presentBanner: true,
);
hasErrors = true;
} else if (state.successfulUploads == 0 ||
(!ok && !state.cancelToken.isCancelled)) {
} else if (state.successfulUploads == 0 || (!ok && !state.cancelToken.isCancelled)) {
await _localNotificationService.showOrUpdateManualUploadStatus(
"backup_manual_title".tr(),
"failed".tr(),
@@ -334,8 +322,7 @@ class ManualUploadNotifier extends StateNotifier<ManualUploadState> {
final appState = ref.read(appStateProvider.notifier).getAppState();
// The app is currently in background. Perform the necessary cleanups which
// are on-hold for upload completion
if (appState != AppLifeCycleEnum.active &&
appState != AppLifeCycleEnum.resumed) {
if (appState != AppLifeCycleEnum.active && appState != AppLifeCycleEnum.resumed) {
ref.read(backupProvider.notifier).cancelBackup();
}
}
@@ -364,8 +351,7 @@ class ManualUploadNotifier extends StateNotifier<ManualUploadState> {
) async {
// assumes the background service is currently running and
// waits until it has stopped to start the backup.
final bool hasLock =
await ref.read(backgroundServiceProvider).acquireLock();
final bool hasLock = await ref.read(backgroundServiceProvider).acquireLock();
if (!hasLock) {
debugPrint("[uploadAssets] could not acquire lock, exiting");
ImmichToast.show(