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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
517 changed files with 4520 additions and 9514 deletions

View file

@ -39,10 +39,8 @@ final backgroundServiceProvider = Provider((ref) => BackgroundService());
/// Background backup service
class BackgroundService {
static const String _portNameLock = "immichLock";
static const MethodChannel _foregroundChannel =
MethodChannel('immich/foregroundChannel');
static const MethodChannel _backgroundChannel =
MethodChannel('immich/backgroundChannel');
static const MethodChannel _foregroundChannel = MethodChannel('immich/foregroundChannel');
static const MethodChannel _backgroundChannel = MethodChannel('immich/backgroundChannel');
static const notifyInterval = Duration(milliseconds: 400);
bool _isBackgroundInitialized = false;
CancellationToken? _cancellationToken;
@ -56,8 +54,7 @@ class BackgroundService {
int _assetsToUploadCount = 0;
String _lastPrintedDetailContent = "";
String? _lastPrintedDetailTitle;
late final ThrottleProgressUpdate _throttledNotifiy =
ThrottleProgressUpdate(_updateProgress, notifyInterval);
late final ThrottleProgressUpdate _throttledNotifiy = ThrottleProgressUpdate(_updateProgress, notifyInterval);
late final ThrottleProgressUpdate _throttledDetailNotify =
ThrottleProgressUpdate(_updateDetailProgress, notifyInterval);
@ -74,10 +71,8 @@ class BackgroundService {
Future<bool> enableService({bool immediate = false}) async {
try {
final callback = PluginUtilities.getCallbackHandle(_nativeEntry)!;
final String title =
"backup_background_service_default_notification".tr();
final bool ok = await _foregroundChannel
.invokeMethod('enable', [callback.toRawHandle(), title, immediate]);
final String title = "backup_background_service_default_notification".tr();
final bool ok = await _foregroundChannel.invokeMethod('enable', [callback.toRawHandle(), title, immediate]);
return ok;
} catch (error) {
return false;
@ -133,8 +128,7 @@ class BackgroundService {
return true;
}
try {
return await _foregroundChannel
.invokeMethod('isIgnoringBatteryOptimizations');
return await _foregroundChannel.invokeMethod('isIgnoringBatteryOptimizations');
} catch (error) {
return false;
}
@ -183,8 +177,7 @@ class BackgroundService {
}) async {
try {
if (_isBackgroundInitialized && _errorGracePeriodExceeded) {
return await _backgroundChannel
.invokeMethod('showError', [title, content, individualTag]);
return await _backgroundChannel.invokeMethod('showError', [title, content, individualTag]);
}
} catch (error) {
debugPrint("[_showErrorNotification] failed to communicate with plugin");
@ -240,8 +233,7 @@ class BackgroundService {
final bs = tempRp.asBroadcastStream();
while (_wantsLockTime == lockTime) {
other.send(tempSp);
final dynamic answer = await bs.first
.timeout(const Duration(seconds: 3), onTimeout: () => null);
final dynamic answer = await bs.first.timeout(const Duration(seconds: 3), onTimeout: () => null);
if (_wantsLockTime != lockTime) {
break;
}
@ -257,8 +249,7 @@ class BackgroundService {
} else if (answer == false) {
// other isolate is still active
}
final dynamic isFinished = await bs.first
.timeout(const Duration(seconds: 3), onTimeout: () => false);
final dynamic isFinished = await bs.first.timeout(const Duration(seconds: 3), onTimeout: () => false);
if (isFinished == true) {
break;
}
@ -358,9 +349,7 @@ class BackgroundService {
);
HttpSSLOptions.apply();
ref
.read(apiServiceProvider)
.setAccessToken(Store.get(StoreKey.accessToken));
ref.read(apiServiceProvider).setAccessToken(Store.get(StoreKey.accessToken));
await ref.read(authServiceProvider).setOpenApiServiceEndpoint();
if (kDebugMode) {
debugPrint(
@ -368,12 +357,8 @@ class BackgroundService {
);
}
final selectedAlbums = await ref
.read(backupAlbumRepositoryProvider)
.getAllBySelection(BackupSelection.select);
final excludedAlbums = await ref
.read(backupAlbumRepositoryProvider)
.getAllBySelection(BackupSelection.exclude);
final selectedAlbums = await ref.read(backupAlbumRepositoryProvider).getAllBySelection(BackupSelection.select);
final excludedAlbums = await ref.read(backupAlbumRepositoryProvider).getAllBySelection(BackupSelection.exclude);
if (selectedAlbums.isEmpty) {
return true;
}
@ -392,9 +377,7 @@ class BackgroundService {
final backupAlbums = [...selectedAlbums, ...excludedAlbums];
backupAlbums.sortBy((e) => e.id);
final dbAlbums = await ref
.read(backupAlbumRepositoryProvider)
.getAll(sort: BackupAlbumSort.id);
final dbAlbums = await ref.read(backupAlbumRepositoryProvider).getAll(sort: BackupAlbumSort.id);
final List<int> toDelete = [];
final List<BackupAlbum> toUpsert = [];
// stores the most recent `lastBackup` per album but always keeps the `selection` from the most recent DB state
@ -403,9 +386,7 @@ class BackgroundService {
backupAlbums,
compare: (BackupAlbum a, BackupAlbum b) => a.id.compareTo(b.id),
both: (BackupAlbum a, BackupAlbum b) {
a.lastBackup = a.lastBackup.isAfter(b.lastBackup)
? a.lastBackup
: b.lastBackup;
a.lastBackup = a.lastBackup.isAfter(b.lastBackup) ? a.lastBackup : b.lastBackup;
toUpsert.add(a);
return true;
},
@ -419,9 +400,7 @@ class BackgroundService {
return false;
}
// Android should check for new assets added while performing backup
} while (Platform.isAndroid &&
true ==
await _backgroundChannel.invokeMethod<bool>("hasContentChanged"));
} while (Platform.isAndroid && true == await _backgroundChannel.invokeMethod<bool>("hasContentChanged"));
return true;
}
@ -432,10 +411,8 @@ class BackgroundService {
List<BackupAlbum> excludedAlbums,
) async {
_errorGracePeriodExceeded = _isErrorGracePeriodExceeded(settingsService);
final bool notifyTotalProgress = settingsService
.getSetting<bool>(AppSettingsEnum.backgroundBackupTotalProgress);
final bool notifySingleProgress = settingsService
.getSetting<bool>(AppSettingsEnum.backgroundBackupSingleProgress);
final bool notifyTotalProgress = settingsService.getSetting<bool>(AppSettingsEnum.backgroundBackupTotalProgress);
final bool notifySingleProgress = settingsService.getSetting<bool>(AppSettingsEnum.backgroundBackupSingleProgress);
if (_canceledBySystem) {
return false;
@ -489,10 +466,8 @@ class BackgroundService {
onSuccess: (result) => _onAssetUploaded(
shouldNotify: notifyTotalProgress,
),
onProgress: (bytes, totalBytes) =>
_onProgress(bytes, totalBytes, shouldNotify: notifySingleProgress),
onCurrentAsset: (asset) =>
_onSetCurrentBackupAsset(asset, shouldNotify: notifySingleProgress),
onProgress: (bytes, totalBytes) => _onProgress(bytes, totalBytes, shouldNotify: notifySingleProgress),
onCurrentAsset: (asset) => _onSetCurrentBackupAsset(asset, shouldNotify: notifySingleProgress),
onError: _onBackupError,
isBackground: true,
);
@ -527,8 +502,7 @@ class BackgroundService {
}
void _updateDetailProgress(String? title, int progress, int total) {
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 || _lastPrintedDetailTitle != title) {
_lastPrintedDetailContent = msg;
@ -557,8 +531,8 @@ class BackgroundService {
void _onBackupError(ErrorUploadAsset errorAssetInfo) {
_showErrorNotification(
title: "backup_background_service_upload_failure_notification"
.tr(namedArgs: {'filename': errorAssetInfo.fileName}),
title:
"backup_background_service_upload_failure_notification".tr(namedArgs: {'filename': errorAssetInfo.fileName}),
individualTag: errorAssetInfo.id,
);
}
@ -571,16 +545,14 @@ class BackgroundService {
return;
}
_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;
}
bool _isErrorGracePeriodExceeded(AppSettingsService appSettingsService) {
final int value = appSettingsService
.getSetting(AppSettingsEnum.uploadErrorNotificationGracePeriod);
final int value = appSettingsService.getSetting(AppSettingsEnum.uploadErrorNotificationGracePeriod);
if (value == 0) {
return true;
} else if (value == 5) {