2022-08-18 16:41:59 +02:00
|
|
|
import 'dart:io';
|
|
|
|
|
2023-06-27 19:25:00 +02:00
|
|
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
2022-07-07 20:40:54 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-02-03 18:06:44 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2023-11-14 22:30:27 +02:00
|
|
|
import 'package:immich_mobile/modules/album/providers/album.provider.dart';
|
2023-02-23 20:33:53 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/background_service/background.service.dart';
|
2022-07-06 23:12:55 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/providers/error_backup_list.provider.dart';
|
2023-02-23 20:33:53 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/providers/ios_background_settings.provider.dart';
|
2023-08-12 23:02:58 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/providers/manual_upload.provider.dart';
|
2023-06-27 19:25:00 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/services/backup_verification.service.dart';
|
2023-01-24 01:10:21 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/ui/current_backup_asset_info_box.dart';
|
2023-02-20 07:59:50 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/ui/ios_debug_info_tile.dart';
|
2022-05-06 14:22:23 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/models/backup_state.model.dart';
|
|
|
|
import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
|
2023-06-27 19:25:00 +02:00
|
|
|
import 'package:immich_mobile/modules/settings/providers/app_settings.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/settings/services/app_settings.service.dart';
|
2022-05-06 14:22:23 +02:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2023-06-27 19:25:00 +02:00
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
|
|
|
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
2022-04-03 19:31:45 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/websocket.provider.dart';
|
2022-05-06 14:22:23 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/ui/backup_info_card.dart';
|
2023-06-27 19:25:00 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/confirm_dialog.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/immich_toast.dart';
|
2023-02-23 20:33:53 +02:00
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
2022-08-31 15:08:40 +02:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2023-08-19 00:52:40 +02:00
|
|
|
import 'package:wakelock_plus/wakelock_plus.dart';
|
2022-02-03 18:06:44 +02:00
|
|
|
|
|
|
|
class BackupControllerPage extends HookConsumerWidget {
|
|
|
|
const BackupControllerPage({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-05-06 14:22:23 +02:00
|
|
|
BackUpState backupState = ref.watch(backupProvider);
|
2023-02-23 20:33:53 +02:00
|
|
|
final settings = ref.watch(iOSBackgroundSettingsProvider.notifier).settings;
|
2023-06-27 19:25:00 +02:00
|
|
|
final settingsService = ref.watch(appSettingsServiceProvider);
|
|
|
|
final showBackupFix = Platform.isAndroid &&
|
|
|
|
settingsService.getSetting(AppSettingsEnum.advancedTroubleshooting);
|
2023-11-14 22:30:27 +02:00
|
|
|
final hasAnyAlbum = backupState.selectedBackupAlbums.isNotEmpty;
|
2023-02-23 20:33:53 +02:00
|
|
|
|
2023-03-18 16:55:11 +02:00
|
|
|
final appRefreshDisabled =
|
|
|
|
Platform.isIOS && settings?.appRefreshEnabled != true;
|
2022-08-18 16:41:59 +02:00
|
|
|
bool hasExclusiveAccess =
|
|
|
|
backupState.backupProgress != BackUpProgressEnum.inBackground;
|
2022-06-22 07:23:35 +02:00
|
|
|
bool shouldBackup = backupState.allUniqueAssets.length -
|
2022-08-18 16:41:59 +02:00
|
|
|
backupState.selectedAlbumsBackupAssetsIds.length ==
|
|
|
|
0 ||
|
|
|
|
!hasExclusiveAccess
|
2022-06-22 07:23:35 +02:00
|
|
|
? false
|
|
|
|
: true;
|
2023-06-27 19:25:00 +02:00
|
|
|
final checkInProgress = useState(false);
|
2022-02-03 18:06:44 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
useEffect(
|
|
|
|
() {
|
2023-08-06 04:40:50 +02:00
|
|
|
if (backupState.backupProgress != BackUpProgressEnum.inProgress &&
|
|
|
|
backupState.backupProgress != BackUpProgressEnum.manualInProgress) {
|
2022-07-13 14:23:48 +02:00
|
|
|
ref.watch(backupProvider.notifier).getBackupInfo();
|
|
|
|
}
|
2022-02-13 23:10:42 +02:00
|
|
|
|
2023-02-23 20:33:53 +02:00
|
|
|
// Update the background settings information just to make sure we
|
|
|
|
// have the latest, since the platform channel will not update
|
|
|
|
// automatically
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
ref.watch(iOSBackgroundSettingsProvider.notifier).refresh();
|
|
|
|
}
|
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
ref
|
|
|
|
.watch(websocketProvider.notifier)
|
|
|
|
.stopListenToEvent('on_upload_success');
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2022-02-03 18:06:44 +02:00
|
|
|
|
2023-06-27 19:25:00 +02:00
|
|
|
Future<void> performDeletion(List<Asset> assets) async {
|
|
|
|
try {
|
|
|
|
checkInProgress.value = true;
|
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
|
|
|
msg: "Deleting ${assets.length} assets on the server...",
|
|
|
|
);
|
2023-10-06 09:01:14 +02:00
|
|
|
await ref
|
|
|
|
.read(assetProvider.notifier)
|
|
|
|
.deleteAssets(assets, force: true);
|
2023-06-27 19:25:00 +02:00
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
|
|
|
msg: "Deleted ${assets.length} assets on the server. "
|
|
|
|
"You can now start a manual backup",
|
|
|
|
toastType: ToastType.success,
|
|
|
|
);
|
|
|
|
} finally {
|
|
|
|
checkInProgress.value = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void performBackupCheck() async {
|
|
|
|
try {
|
|
|
|
checkInProgress.value = true;
|
|
|
|
if (backupState.allUniqueAssets.length >
|
|
|
|
backupState.selectedAlbumsBackupAssetsIds.length) {
|
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
|
|
|
msg: "Backup all assets before starting this check!",
|
|
|
|
toastType: ToastType.error,
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final connection = await Connectivity().checkConnectivity();
|
|
|
|
if (connection != ConnectivityResult.wifi) {
|
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
|
|
|
msg: "Make sure to be connected to unmetered Wi-Fi",
|
|
|
|
toastType: ToastType.error,
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2023-08-19 00:52:40 +02:00
|
|
|
WakelockPlus.enable();
|
2023-06-27 19:25:00 +02:00
|
|
|
const limit = 100;
|
|
|
|
final toDelete = await ref
|
|
|
|
.read(backupVerificationServiceProvider)
|
|
|
|
.findWronglyBackedUpAssets(limit: limit);
|
|
|
|
if (toDelete.isEmpty) {
|
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
|
|
|
msg: "Did not find any corrupt asset backups!",
|
|
|
|
toastType: ToastType.success,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
await showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => ConfirmDialog(
|
|
|
|
onOk: () => performDeletion(toDelete),
|
|
|
|
title: "Corrupt backups!",
|
|
|
|
ok: "Delete",
|
|
|
|
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?",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} finally {
|
2023-08-19 00:52:40 +02:00
|
|
|
WakelockPlus.disable();
|
2023-06-27 19:25:00 +02:00
|
|
|
checkInProgress.value = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildCheckCorruptBackups() {
|
|
|
|
return ListTile(
|
|
|
|
leading: Icon(
|
|
|
|
Icons.warning_rounded,
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2023-06-27 19:25:00 +02:00
|
|
|
),
|
|
|
|
title: const Text(
|
|
|
|
"Check for corrupt asset backups",
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14),
|
|
|
|
),
|
|
|
|
isThreeLine: true,
|
|
|
|
subtitle: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
const Text("Run this check only over Wi-Fi and once all assets "
|
|
|
|
"have been backed-up. The procedure might take a few minutes."),
|
|
|
|
ElevatedButton(
|
|
|
|
onPressed: checkInProgress.value ? null : performBackupCheck,
|
|
|
|
child: checkInProgress.value
|
|
|
|
? const CircularProgressIndicator()
|
|
|
|
: const Text("Perform check"),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
ListTile buildAutoBackupController() {
|
2023-03-23 17:25:58 +02:00
|
|
|
final isAutoBackup = backupState.autoBackup;
|
|
|
|
final backUpOption = isAutoBackup
|
2022-07-07 20:40:54 +02:00
|
|
|
? "backup_controller_page_status_on".tr()
|
|
|
|
: "backup_controller_page_status_off".tr();
|
2023-03-23 17:25:58 +02:00
|
|
|
final backupBtnText = isAutoBackup
|
2022-07-07 20:40:54 +02:00
|
|
|
? "backup_controller_page_turn_off".tr()
|
|
|
|
: "backup_controller_page_turn_on".tr();
|
2022-02-03 18:06:44 +02:00
|
|
|
return ListTile(
|
|
|
|
isThreeLine: true,
|
|
|
|
leading: isAutoBackup
|
|
|
|
? Icon(
|
|
|
|
Icons.cloud_done_rounded,
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2022-02-03 18:06:44 +02:00
|
|
|
)
|
|
|
|
: const Icon(Icons.cloud_off_rounded),
|
|
|
|
title: Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
backUpOption,
|
2022-02-03 18:06:44 +02:00
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 14),
|
|
|
|
),
|
|
|
|
subtitle: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2022-07-01 03:08:49 +02:00
|
|
|
if (!isAutoBackup)
|
|
|
|
const Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
"backup_controller_page_desc_backup",
|
2022-07-01 03:08:49 +02:00
|
|
|
style: TextStyle(fontSize: 14),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-04-05 06:37:48 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8.0),
|
2022-08-16 01:53:30 +02:00
|
|
|
child: ElevatedButton(
|
2023-03-23 17:25:58 +02:00
|
|
|
onPressed: () => ref
|
|
|
|
.read(backupProvider.notifier)
|
|
|
|
.setAutoBackup(!isAutoBackup),
|
2022-07-13 14:23:48 +02:00
|
|
|
child: Text(
|
|
|
|
backupBtnText,
|
2022-08-16 01:53:30 +02:00
|
|
|
style: const TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
2022-07-13 14:23:48 +02:00
|
|
|
),
|
2022-04-05 06:37:48 +02:00
|
|
|
),
|
2023-08-19 00:52:40 +02:00
|
|
|
),
|
2022-02-03 18:06:44 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
void showErrorToUser(String msg) {
|
2022-08-18 16:41:59 +02:00
|
|
|
final snackBar = SnackBar(
|
|
|
|
content: Text(
|
|
|
|
msg.tr(),
|
|
|
|
),
|
|
|
|
backgroundColor: Colors.red,
|
|
|
|
);
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
void showBatteryOptimizationInfoToUser() {
|
2022-08-31 15:08:40 +02:00
|
|
|
showDialog<void>(
|
|
|
|
context: context,
|
|
|
|
barrierDismissible: false,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertDialog(
|
|
|
|
title: const Text(
|
|
|
|
'backup_controller_page_background_battery_info_title',
|
|
|
|
).tr(),
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: const Text(
|
|
|
|
'backup_controller_page_background_battery_info_message',
|
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
actions: [
|
2022-10-14 18:15:19 +02:00
|
|
|
ElevatedButton(
|
2022-08-31 15:08:40 +02:00
|
|
|
onPressed: () => launchUrl(
|
2022-09-10 18:46:51 +02:00
|
|
|
Uri.parse('https://dontkillmyapp.com'),
|
|
|
|
mode: LaunchMode.externalApplication,
|
|
|
|
),
|
|
|
|
child: const Text(
|
2022-08-31 15:08:40 +02:00
|
|
|
"backup_controller_page_background_battery_info_link",
|
2022-10-14 18:15:19 +02:00
|
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12),
|
2022-08-31 15:08:40 +02:00
|
|
|
).tr(),
|
|
|
|
),
|
2022-09-10 18:46:51 +02:00
|
|
|
ElevatedButton(
|
|
|
|
child: const Text(
|
2022-08-31 15:08:40 +02:00
|
|
|
'backup_controller_page_background_battery_info_ok',
|
2022-09-10 18:46:51 +02:00
|
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12),
|
2022-08-31 15:08:40 +02:00
|
|
|
).tr(),
|
|
|
|
onPressed: () {
|
2023-11-09 18:19:53 +02:00
|
|
|
context.pop();
|
2022-08-31 15:08:40 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-20 07:59:50 +02:00
|
|
|
Widget buildBackgroundBackupController() {
|
2022-08-18 16:41:59 +02:00
|
|
|
final bool isBackgroundEnabled = backupState.backgroundBackup;
|
|
|
|
final bool isWifiRequired = backupState.backupRequireWifi;
|
|
|
|
final bool isChargingRequired = backupState.backupRequireCharging;
|
2023-11-09 18:19:53 +02:00
|
|
|
final Color activeColor = context.primaryColor;
|
2022-12-08 17:51:36 +02:00
|
|
|
|
|
|
|
String formatBackupDelaySliderValue(double v) {
|
|
|
|
if (v == 0.0) {
|
|
|
|
return 'setting_notifications_notify_seconds'.tr(args: const ['5']);
|
|
|
|
} else if (v == 1.0) {
|
|
|
|
return 'setting_notifications_notify_seconds'.tr(args: const ['30']);
|
|
|
|
} else if (v == 2.0) {
|
|
|
|
return 'setting_notifications_notify_minutes'.tr(args: const ['2']);
|
|
|
|
} else {
|
|
|
|
return 'setting_notifications_notify_minutes'.tr(args: const ['10']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int backupDelayToMilliseconds(double v) {
|
|
|
|
if (v == 0.0) {
|
|
|
|
return 5000;
|
|
|
|
} else if (v == 1.0) {
|
|
|
|
return 30000;
|
|
|
|
} else if (v == 2.0) {
|
|
|
|
return 120000;
|
|
|
|
} else {
|
|
|
|
return 600000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double backupDelayToSliderValue(int ms) {
|
|
|
|
if (ms == 5000) {
|
|
|
|
return 0.0;
|
|
|
|
} else if (ms == 30000) {
|
|
|
|
return 1.0;
|
|
|
|
} else if (ms == 120000) {
|
|
|
|
return 2.0;
|
|
|
|
} else {
|
|
|
|
return 3.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final triggerDelay =
|
|
|
|
useState(backupDelayToSliderValue(backupState.backupTriggerDelay));
|
|
|
|
|
2023-02-20 07:59:50 +02:00
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
ListTile(
|
|
|
|
isThreeLine: true,
|
|
|
|
leading: isBackgroundEnabled
|
|
|
|
? Icon(
|
|
|
|
Icons.cloud_sync_rounded,
|
|
|
|
color: activeColor,
|
|
|
|
)
|
|
|
|
: const Icon(Icons.cloud_sync_rounded),
|
|
|
|
title: Text(
|
|
|
|
isBackgroundEnabled
|
|
|
|
? "backup_controller_page_background_is_on"
|
|
|
|
: "backup_controller_page_background_is_off",
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 14),
|
|
|
|
).tr(),
|
|
|
|
subtitle: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
if (!isBackgroundEnabled)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
2023-02-21 05:40:19 +02:00
|
|
|
child: const Text(
|
|
|
|
"backup_controller_page_background_description",
|
|
|
|
).tr(),
|
2023-02-20 07:59:50 +02:00
|
|
|
),
|
|
|
|
if (isBackgroundEnabled && Platform.isAndroid)
|
2023-02-21 05:40:19 +02:00
|
|
|
SwitchListTile.adaptive(
|
|
|
|
title: const Text("backup_controller_page_background_wifi")
|
|
|
|
.tr(),
|
2023-02-20 07:59:50 +02:00
|
|
|
secondary: Icon(
|
|
|
|
Icons.wifi,
|
|
|
|
color: isWifiRequired ? activeColor : null,
|
|
|
|
),
|
|
|
|
dense: true,
|
|
|
|
activeColor: activeColor,
|
|
|
|
value: isWifiRequired,
|
2023-03-18 16:55:11 +02:00
|
|
|
onChanged: (isChecked) => ref
|
|
|
|
.read(backupProvider.notifier)
|
|
|
|
.configureBackgroundBackup(
|
|
|
|
requireWifi: isChecked,
|
|
|
|
onError: showErrorToUser,
|
|
|
|
onBatteryInfo: showBatteryOptimizationInfoToUser,
|
|
|
|
),
|
2023-02-20 07:59:50 +02:00
|
|
|
),
|
|
|
|
if (isBackgroundEnabled)
|
2023-02-21 05:40:19 +02:00
|
|
|
SwitchListTile.adaptive(
|
|
|
|
title:
|
|
|
|
const Text("backup_controller_page_background_charging")
|
|
|
|
.tr(),
|
2023-02-20 07:59:50 +02:00
|
|
|
secondary: Icon(
|
|
|
|
Icons.charging_station,
|
|
|
|
color: isChargingRequired ? activeColor : null,
|
|
|
|
),
|
|
|
|
dense: true,
|
|
|
|
activeColor: activeColor,
|
|
|
|
value: isChargingRequired,
|
2023-03-18 16:55:11 +02:00
|
|
|
onChanged: (isChecked) => ref
|
|
|
|
.read(backupProvider.notifier)
|
|
|
|
.configureBackgroundBackup(
|
|
|
|
requireCharging: isChecked,
|
|
|
|
onError: showErrorToUser,
|
|
|
|
onBatteryInfo: showBatteryOptimizationInfoToUser,
|
|
|
|
),
|
2022-12-08 17:51:36 +02:00
|
|
|
),
|
2023-02-20 07:59:50 +02:00
|
|
|
if (isBackgroundEnabled && Platform.isAndroid)
|
|
|
|
ListTile(
|
|
|
|
isThreeLine: false,
|
|
|
|
dense: true,
|
|
|
|
title: const Text(
|
|
|
|
'backup_controller_page_background_delay',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
2022-12-08 17:51:36 +02:00
|
|
|
),
|
2023-02-21 05:40:19 +02:00
|
|
|
).tr(
|
|
|
|
args: [formatBackupDelaySliderValue(triggerDelay.value)],
|
|
|
|
),
|
2023-02-20 07:59:50 +02:00
|
|
|
subtitle: Slider(
|
|
|
|
value: triggerDelay.value,
|
2023-03-18 16:55:11 +02:00
|
|
|
onChanged: (double v) => triggerDelay.value = v,
|
2023-02-20 07:59:50 +02:00
|
|
|
onChangeEnd: (double v) => ref
|
|
|
|
.read(backupProvider.notifier)
|
|
|
|
.configureBackgroundBackup(
|
|
|
|
triggerDelay: backupDelayToMilliseconds(v),
|
|
|
|
onError: showErrorToUser,
|
|
|
|
onBatteryInfo: showBatteryOptimizationInfoToUser,
|
|
|
|
),
|
|
|
|
max: 3.0,
|
|
|
|
divisions: 3,
|
|
|
|
label: formatBackupDelaySliderValue(triggerDelay.value),
|
2023-11-09 18:19:53 +02:00
|
|
|
activeColor: context.primaryColor,
|
2023-02-20 07:59:50 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
ElevatedButton(
|
2023-02-21 05:40:19 +02:00
|
|
|
onPressed: () => ref
|
|
|
|
.read(backupProvider.notifier)
|
|
|
|
.configureBackgroundBackup(
|
|
|
|
enabled: !isBackgroundEnabled,
|
|
|
|
onError: showErrorToUser,
|
|
|
|
onBatteryInfo: showBatteryOptimizationInfoToUser,
|
|
|
|
),
|
2023-02-20 07:59:50 +02:00
|
|
|
child: Text(
|
|
|
|
isBackgroundEnabled
|
|
|
|
? "backup_controller_page_background_turn_off"
|
|
|
|
: "backup_controller_page_background_turn_on",
|
2023-02-21 05:40:19 +02:00
|
|
|
style: const TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
2023-02-20 07:59:50 +02:00
|
|
|
).tr(),
|
2022-12-08 17:51:36 +02:00
|
|
|
),
|
2023-02-20 07:59:50 +02:00
|
|
|
],
|
2022-08-18 16:41:59 +02:00
|
|
|
),
|
2023-02-20 07:59:50 +02:00
|
|
|
),
|
2023-02-23 20:33:53 +02:00
|
|
|
if (isBackgroundEnabled && Platform.isIOS)
|
|
|
|
FutureBuilder(
|
|
|
|
future: ref
|
2023-03-18 16:55:11 +02:00
|
|
|
.read(backgroundServiceProvider)
|
|
|
|
.getIOSBackgroundAppRefreshEnabled(),
|
2023-02-23 20:33:53 +02:00
|
|
|
builder: (context, snapshot) {
|
2023-05-21 03:41:34 +02:00
|
|
|
final enabled = snapshot.data;
|
2023-02-23 20:33:53 +02:00
|
|
|
// If it's not enabled, show them some kind of alert that says
|
|
|
|
// background refresh is not enabled
|
2023-03-18 16:55:11 +02:00
|
|
|
if (enabled != null && !enabled) {}
|
2023-02-23 20:33:53 +02:00
|
|
|
// If it's enabled, no need to bother them
|
|
|
|
return Container();
|
|
|
|
},
|
2023-02-20 07:59:50 +02:00
|
|
|
),
|
2023-03-05 21:50:03 +02:00
|
|
|
if (Platform.isIOS && isBackgroundEnabled && settings != null)
|
2023-02-23 20:33:53 +02:00
|
|
|
IosDebugInfoTile(
|
|
|
|
settings: settings,
|
2023-03-18 16:55:11 +02:00
|
|
|
),
|
2023-02-20 07:59:50 +02:00
|
|
|
],
|
2022-08-18 16:41:59 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-23 20:33:53 +02:00
|
|
|
Widget buildBackgroundAppRefreshWarning() {
|
|
|
|
return ListTile(
|
|
|
|
isThreeLine: true,
|
2023-03-18 16:55:11 +02:00
|
|
|
leading: const Icon(
|
|
|
|
Icons.task_outlined,
|
|
|
|
),
|
2023-02-23 20:33:53 +02:00
|
|
|
title: const Text(
|
|
|
|
'backup_controller_page_background_app_refresh_disabled_title',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 14,
|
|
|
|
),
|
|
|
|
).tr(),
|
|
|
|
subtitle: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
|
|
child: const Text(
|
|
|
|
'backup_controller_page_background_app_refresh_disabled_content',
|
|
|
|
).tr(),
|
|
|
|
),
|
2023-03-18 16:55:11 +02:00
|
|
|
ElevatedButton(
|
2023-02-23 20:33:53 +02:00
|
|
|
onPressed: () => openAppSettings(),
|
|
|
|
child: const Text(
|
|
|
|
'backup_controller_page_background_app_refresh_enable_button_text',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
Widget buildSelectedAlbumName() {
|
2022-07-07 20:40:54 +02:00
|
|
|
var text = "backup_controller_page_backup_selected".tr();
|
2022-05-06 14:22:23 +02:00
|
|
|
var albums = ref.watch(backupProvider).selectedBackupAlbums;
|
|
|
|
|
|
|
|
if (albums.isNotEmpty) {
|
|
|
|
for (var album in albums) {
|
|
|
|
if (album.name == "Recent" || album.name == "Recents") {
|
2022-07-07 20:40:54 +02:00
|
|
|
text += "${album.name} (${'backup_all'.tr()}), ";
|
2022-05-06 14:22:23 +02:00
|
|
|
} else {
|
|
|
|
text += "${album.name}, ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8.0),
|
|
|
|
child: Text(
|
|
|
|
text.trim().substring(0, text.length - 2),
|
2022-06-22 07:23:35 +02:00
|
|
|
style: TextStyle(
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2022-07-13 14:23:48 +02:00
|
|
|
fontSize: 12,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8.0),
|
|
|
|
child: Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
"backup_controller_page_none_selected".tr(),
|
2022-06-22 07:23:35 +02:00
|
|
|
style: TextStyle(
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2022-07-13 14:23:48 +02:00
|
|
|
fontSize: 12,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
Widget buildExcludedAlbumName() {
|
2022-07-07 20:40:54 +02:00
|
|
|
var text = "backup_controller_page_excluded".tr();
|
2022-05-06 14:22:23 +02:00
|
|
|
var albums = ref.watch(backupProvider).excludedBackupAlbums;
|
|
|
|
|
|
|
|
if (albums.isNotEmpty) {
|
|
|
|
for (var album in albums) {
|
|
|
|
text += "${album.name}, ";
|
|
|
|
}
|
|
|
|
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8.0),
|
|
|
|
child: Text(
|
|
|
|
text.trim().substring(0, text.length - 2),
|
2022-06-22 07:23:35 +02:00
|
|
|
style: TextStyle(
|
2022-07-13 14:23:48 +02:00
|
|
|
color: Colors.red[300],
|
|
|
|
fontSize: 12,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
2022-07-01 03:08:49 +02:00
|
|
|
return const SizedBox();
|
2022-05-06 14:22:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
buildFolderSelectionTile() {
|
2022-05-06 14:22:23 +02:00
|
|
|
return Card(
|
|
|
|
shape: RoundedRectangleBorder(
|
2023-02-13 07:05:31 +02:00
|
|
|
borderRadius: BorderRadius.circular(20),
|
|
|
|
side: BorderSide(
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.isDarkTheme
|
2023-02-21 05:40:19 +02:00
|
|
|
? const Color.fromARGB(255, 56, 56, 56)
|
2023-02-13 07:05:31 +02:00
|
|
|
: Colors.black12,
|
2022-05-06 14:22:23 +02:00
|
|
|
width: 1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
elevation: 0,
|
|
|
|
borderOnForeground: false,
|
|
|
|
child: ListTile(
|
|
|
|
minVerticalPadding: 15,
|
2022-07-13 14:23:48 +02:00
|
|
|
title: const Text(
|
|
|
|
"backup_controller_page_albums",
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
|
|
|
|
).tr(),
|
2022-05-06 14:22:23 +02:00
|
|
|
subtitle: Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
const Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
"backup_controller_page_to_backup",
|
2022-08-16 01:53:30 +02:00
|
|
|
style: TextStyle(fontSize: 12),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-11-21 14:13:14 +02:00
|
|
|
buildSelectedAlbumName(),
|
2023-08-19 00:52:40 +02:00
|
|
|
buildExcludedAlbumName(),
|
2022-05-06 14:22:23 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2022-08-16 01:53:30 +02:00
|
|
|
trailing: ElevatedButton(
|
2023-11-14 22:30:27 +02:00
|
|
|
onPressed: () async {
|
|
|
|
await context.autoPush(const BackupAlbumSelectionRoute());
|
|
|
|
// waited until returning from selection
|
|
|
|
await ref
|
|
|
|
.read(backupProvider.notifier)
|
|
|
|
.backupAlbumSelectionDone();
|
|
|
|
// waited until backup albums are stored in DB
|
|
|
|
ref.read(albumProvider.notifier).getDeviceAlbums();
|
2023-03-18 16:55:11 +02:00
|
|
|
},
|
2022-08-16 01:53:30 +02:00
|
|
|
child: const Text(
|
|
|
|
"backup_controller_page_select",
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 12,
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
2022-08-16 01:53:30 +02:00
|
|
|
).tr(),
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-06 23:12:55 +02:00
|
|
|
void startBackup() {
|
|
|
|
ref.watch(errorBackupListProvider.notifier).empty();
|
2022-08-18 16:41:59 +02:00
|
|
|
if (ref.watch(backupProvider).backupProgress !=
|
|
|
|
BackUpProgressEnum.inBackground) {
|
|
|
|
ref.watch(backupProvider.notifier).startBackupProcess();
|
|
|
|
}
|
2022-07-06 23:12:55 +02:00
|
|
|
}
|
|
|
|
|
2023-02-13 07:05:31 +02:00
|
|
|
Widget buildBackupButton() {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 24,
|
|
|
|
),
|
|
|
|
child: Container(
|
2023-08-12 23:02:58 +02:00
|
|
|
child: backupState.backupProgress == BackUpProgressEnum.inProgress ||
|
|
|
|
backupState.backupProgress ==
|
|
|
|
BackUpProgressEnum.manualInProgress
|
2023-02-13 07:05:31 +02:00
|
|
|
? ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
foregroundColor: Colors.grey[50],
|
|
|
|
backgroundColor: Colors.red[300],
|
|
|
|
// padding: const EdgeInsets.all(14),
|
|
|
|
),
|
|
|
|
onPressed: () {
|
2023-08-12 23:02:58 +02:00
|
|
|
if (backupState.backupProgress ==
|
|
|
|
BackUpProgressEnum.manualInProgress) {
|
|
|
|
ref.read(manualUploadProvider.notifier).cancelBackup();
|
|
|
|
} else {
|
|
|
|
ref.read(backupProvider.notifier).cancelBackup();
|
|
|
|
}
|
2023-02-13 07:05:31 +02:00
|
|
|
},
|
|
|
|
child: const Text(
|
|
|
|
"backup_controller_page_cancel",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
).tr(),
|
|
|
|
)
|
|
|
|
: ElevatedButton(
|
|
|
|
onPressed: shouldBackup ? startBackup : null,
|
|
|
|
child: const Text(
|
|
|
|
"backup_controller_page_start_backup",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildBackgroundBackupInfo() {
|
2023-03-18 16:55:11 +02:00
|
|
|
return const ListTile(
|
|
|
|
leading: Icon(Icons.info_outline_rounded),
|
|
|
|
title: Text(
|
|
|
|
"Background backup is currently running, cannot start manual backup",
|
|
|
|
),
|
|
|
|
);
|
2023-02-13 07:05:31 +02:00
|
|
|
}
|
|
|
|
|
2022-02-03 18:06:44 +02:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2022-05-06 14:22:23 +02:00
|
|
|
elevation: 0,
|
2022-02-03 18:06:44 +02:00
|
|
|
title: const Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
"backup_controller_page_backup",
|
2022-05-06 14:22:23 +02:00
|
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-02-03 18:06:44 +02:00
|
|
|
leading: IconButton(
|
2022-07-13 14:23:48 +02:00
|
|
|
onPressed: () {
|
|
|
|
ref.watch(websocketProvider.notifier).listenUploadEvent();
|
2023-11-09 18:19:53 +02:00
|
|
|
context.autoPop(true);
|
2022-07-13 14:23:48 +02:00
|
|
|
},
|
|
|
|
splashRadius: 24,
|
|
|
|
icon: const Icon(
|
|
|
|
Icons.arrow_back_ios_rounded,
|
|
|
|
),
|
|
|
|
),
|
2022-02-03 18:06:44 +02:00
|
|
|
),
|
|
|
|
body: Padding(
|
2022-07-06 23:12:55 +02:00
|
|
|
padding: const EdgeInsets.only(left: 16.0, right: 16, bottom: 32),
|
2022-02-03 18:06:44 +02:00
|
|
|
child: ListView(
|
|
|
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
2023-11-14 22:30:27 +02:00
|
|
|
children: hasAnyAlbum
|
|
|
|
? [
|
|
|
|
buildFolderSelectionTile(),
|
|
|
|
BackupInfoCard(
|
|
|
|
title: "backup_controller_page_total".tr(),
|
|
|
|
subtitle: "backup_controller_page_total_sub".tr(),
|
|
|
|
info: ref.watch(backupProvider).availableAlbums.isEmpty
|
|
|
|
? "..."
|
|
|
|
: "${backupState.allUniqueAssets.length}",
|
|
|
|
),
|
|
|
|
BackupInfoCard(
|
|
|
|
title: "backup_controller_page_backup".tr(),
|
|
|
|
subtitle: "backup_controller_page_backup_sub".tr(),
|
|
|
|
info: ref.watch(backupProvider).availableAlbums.isEmpty
|
|
|
|
? "..."
|
|
|
|
: "${backupState.selectedAlbumsBackupAssetsIds.length}",
|
|
|
|
),
|
|
|
|
BackupInfoCard(
|
|
|
|
title: "backup_controller_page_remainder".tr(),
|
|
|
|
subtitle: "backup_controller_page_remainder_sub".tr(),
|
|
|
|
info: ref.watch(backupProvider).availableAlbums.isEmpty
|
|
|
|
? "..."
|
|
|
|
: "${backupState.allUniqueAssets.length - backupState.selectedAlbumsBackupAssetsIds.length}",
|
|
|
|
),
|
|
|
|
const Divider(),
|
|
|
|
buildAutoBackupController(),
|
|
|
|
const Divider(),
|
|
|
|
AnimatedSwitcher(
|
|
|
|
duration: const Duration(milliseconds: 500),
|
|
|
|
child: Platform.isIOS
|
|
|
|
? (appRefreshDisabled
|
|
|
|
? buildBackgroundAppRefreshWarning()
|
|
|
|
: buildBackgroundBackupController())
|
|
|
|
: buildBackgroundBackupController(),
|
|
|
|
),
|
|
|
|
if (showBackupFix) const Divider(),
|
|
|
|
if (showBackupFix) buildCheckCorruptBackups(),
|
|
|
|
const Divider(),
|
|
|
|
const Divider(),
|
|
|
|
const CurrentUploadingAssetInfoBox(),
|
|
|
|
if (!hasExclusiveAccess) buildBackgroundBackupInfo(),
|
|
|
|
buildBackupButton(),
|
|
|
|
]
|
|
|
|
: [buildFolderSelectionTile()],
|
2022-02-03 18:06:44 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|