Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

added encryption feature to backups + refined backup logic

a5xwin541d71f65c76
diff --git a/mobile/apps/auth/.gitignore b/mobile/apps/auth/.gitignore
index c13b96038b..a30c484588 100644
--- a/mobile/apps/auth/.gitignore
+++ b/mobile/apps/auth/.gitignore
@@ -8,6 +8,7 @@
.buildlog/
.history
.svn/
+android/app/build/
# Editors
.vscode/
diff --git a/mobile/apps/auth/android/app/build.gradle b/mobile/apps/auth/android/app/build.gradle
index 86dbed264e..4633c502f3 100644
--- a/mobile/apps/auth/android/app/build.gradle
+++ b/mobile/apps/auth/android/app/build.gradle
@@ -30,7 +30,7 @@ if (keystorePropertiesFile.exists()) {
android {
namespace "io.ente.auth"
- compileSdk 34
+ compileSdk 36
ndkVersion flutter.ndkVersion
compileOptions {
@@ -60,7 +60,7 @@ android {
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 21
- targetSdkVersion 34
+ targetSdkVersion 35
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
diff --git a/mobile/apps/auth/lib/l10n/arb/app_en.arb b/mobile/apps/auth/lib/l10n/arb/app_en.arb
index f0ae7db124..775705601b 100644
--- a/mobile/apps/auth/lib/l10n/arb/app_en.arb
+++ b/mobile/apps/auth/lib/l10n/arb/app_en.arb
@@ -525,11 +525,12 @@
"backupLocation": "Backup Location",
"backupLocationDescription": "Select a folder to save backups. Backups run automatically when entries are added, deleted, or edited.",
"currentLocation": "Current Location:",
- "notSetPleaseChooseLocation": "Not set. Please choose a location.",
- "chooseLocation": "Choose Location",
+ "changeLocation": "Change Backup Location",
"securityNotice": "Security Notice",
"backupSecurityNotice": "This encrypted backup holds your 2FA keys. If lost, you may not be able to recover your accounts. Keep it safe!",
"locationUpdatedAndBackupCreated": "Location updated and initial backup created!",
"initialBackupCreated": "Initial backup created!",
- "pleaseChooseBackupLocation": "Please choose a backup location."
+ "pleaseChooseBackupLocation": "Please choose a backup location.",
+ "passwordTooShort": "Password must be at least 8 characters long.",
+ "noDefaultBackupFolder": "Could not create default backup folder."
}
\ No newline at end of file
diff --git a/mobile/apps/auth/lib/services/local_backup_service.dart b/mobile/apps/auth/lib/services/local_backup_service.dart
index ef3b15bd1e..587ad5f1db 100644
--- a/mobile/apps/auth/lib/services/local_backup_service.dart
+++ b/mobile/apps/auth/lib/services/local_backup_service.dart
@@ -14,16 +14,22 @@ class LocalBackupService {
LocalBackupService._privateConstructor();
LocalBackupService._privateConstructor();
+ static const int _maxBackups = 2;
+
// to create an encrypted backup file if the toggle is on
Future<void> triggerAutomaticBackup() async {
try {
final prefs = await SharedPreferences.getInstance();
final isEnabled = prefs.getBool('isAutoBackupEnabled') ?? false;
- if (!isEnabled) return;
+ if (!isEnabled) {
+ return;
+ }
final backupPath = prefs.getString('autoBackupPath');
- if (backupPath == null) return;
+ if (backupPath == null) {
+ return;
+ }
const storage = FlutterSecureStorage();
final password = await storage.read(key: 'autoBackupPassword');
@@ -36,7 +42,9 @@ class LocalBackupService {
final plainTextContent = await CodeStore.instance.getCodesForExport();
- if (plainTextContent.trim().isEmpty) return;
+ if (plainTextContent.trim().isEmpty) {
+ return;
+ }
final kekSalt = CryptoUtil.getSaltToDeriveKey();
final derivedKeyResult = await CryptoUtil.deriveSensitiveKey(
@@ -68,16 +76,80 @@ class LocalBackupService {
final now = DateTime.now();
final formatter = DateFormat('yyyy-MM-dd_HH-mm-ss');
final formattedDate = formatter.format(now);
- final fileName = 'ente-auth-auto-backup-$formattedDate.txt';
+ final fileName = 'ente-auth-auto-backup-$formattedDate.json';
final filePath = '$backupPath/$fileName';
final backupFile = File(filePath);
await backupFile.writeAsString(encryptedJson);
+ await _manageOldBackups(backupPath);
_logger.info('Automatic encrypted backup successful! Saved to: $filePath');
} catch (e, s) {
_logger.severe('Silent error during automatic backup', e, s);
}
}
+
+ Future<void> _manageOldBackups(String backupPath) async {
+ try {
+ _logger.info("Checking for old backups to clean up...");
+ final directory = Directory(backupPath);
+
+ // fetch all filenames in the folder, filter out ente backup files
+ final files = directory.listSync()
+ .where((entity) =>
+ entity is File &&
+ entity.path.split('/').last.startsWith('ente-auth-auto-backup-'),)
+ .map((entity) => entity as File)
+ .toList();
+
+ // sort the fetched files in asc order (oldest first because the name is a timestamp)
+ files.sort((a, b) => a.path.compareTo(b.path));
+
+ // if we have more files than our limit, delete the oldest ones (current limit=_maxBackups)
+ while (files.length > _maxBackups) {
+ // remove the oldest file (at index 0) from the list
+ final fileToDelete = files.removeAt(0);
+ // and delete it from the device's storage..
+ await fileToDelete.delete();
+ _logger.info('Deleted old backup: ${fileToDelete.path}');
+}
+_logger.info('Backup count is now ${files.length}. Cleanup complete.');
+ } catch (e, s) {
+ _logger.severe('Error during old backup cleanup', e, s);
+ }
+ }
+
+ Future<void> deleteAllBackupsIn(String path) async {
+ try {
+ _logger.info("Deleting all backups in old location: $path");
+ final directory = Directory(path);
+
+ if (!await directory.exists()) {
+ _logger.warning("Old backup directory not found. Nothing to delete.");
+ return;
+ }
+
+ final files = directory.listSync()
+ .where((entity) =>
+ entity is File &&
+ entity.path.split('/').last.startsWith('ente-auth-auto-backup-'),)
+ .map((entity) => entity as File)
+ .toList();
+
+ if (files.isEmpty) {
+ _logger.info("No old backup files found to delete.");
+ return;
+ }
+
+ for (final file in files) {
+ await file.delete();
+ _logger.info('Deleted: ${file.path}');
+ }
+ _logger.info("Successfully cleaned up old backup location.");
+
+ } catch (e, s) {
+ _logger.severe('Error during full backup cleanup of old directory', e, s);
+ }
+ }
}
\ No newline at end of file
diff --git a/mobile/apps/auth/lib/store/code_store.dart b/mobile/apps/auth/lib/store/code_store.dart
index 7da780c53a..3192299f10 100644
--- a/mobile/apps/auth/lib/store/code_store.dart
+++ b/mobile/apps/auth/lib/store/code_store.dart
@@ -65,6 +65,27 @@ class CodeStore {
return true;
}
+ Future<void> updateCode(Code originalCode, Code updatedCode, {bool shouldSync = true}) async {
+ if (updatedCode.generatedID == null) return;
+
+ await _authenticatorService.updateEntry(
+ updatedCode.generatedID!,
+ updatedCode.toOTPAuthUrlFormat(),
+ shouldSync,
+ _authenticatorService.getAccountMode(),
+ );
+ Bus.instance.fire(CodesUpdatedEvent());
+
+ final bool isMajorChange = originalCode.issuer != updatedCode.issuer ||
+ originalCode.account != updatedCode.account ||
+ originalCode.secret != updatedCode.secret ||
+ originalCode.display.note != updatedCode.display.note;
+
+ if (isMajorChange) {
+ LocalBackupService.instance.triggerAutomaticBackup().ignore();
+ }
+ }
+
Future<List<Code>> getAllCodes({
AccountMode? accountMode,
bool sortCodes = true,
@@ -96,7 +117,6 @@ class CodeStore {
}
if (sortCodes) {
- // sort codes by issuer,account
codes.sort((firstCode, secondCode) {
if (secondCode.isPinned && !firstCode.isPinned) return 1;
if (!secondCode.isPinned && firstCode.isPinned) return -1;
@@ -122,12 +142,15 @@ class CodeStore {
AccountMode? accountMode,
List<Code>? existingAllCodes,
}) async {
+
final mode = accountMode ?? _authenticatorService.getAccountMode();
final allCodes = existingAllCodes ?? (await getAllCodes(accountMode: mode));
bool isExistingCode = false;
bool hasSameCode = false;
+
for (final existingCode in allCodes) {
if (existingCode.hasError) continue;
+
if (code.generatedID != null &&
existingCode.generatedID == code.generatedID) {
isExistingCode = true;
@@ -156,9 +179,9 @@ class CodeStore {
shouldSync,
mode,
);
+ LocalBackupService.instance.triggerAutomaticBackup().ignore();
}
Bus.instance.fire(CodesUpdatedEvent());
- LocalBackupService.instance.triggerAutomaticBackup().ignore();
return result;
}
@@ -217,7 +240,6 @@ class CodeStore {
'importingCode: genID ${eachCode.generatedID} & isAlreadyPresent $alreadyPresent',
);
if (!alreadyPresent) {
- // Avoid conflict with generatedID of online codes
eachCode.generatedID = null;
final AddResult result = await CodeStore.instance.addCode(
eachCode,
@@ -250,16 +272,6 @@ class CodeStore {
return data;
}
-
-
-
-
-
-
-
-
-
-
}
enum AddResult {
diff --git a/mobile/apps/auth/lib/ui/code_widget.dart b/mobile/apps/auth/lib/ui/code_widget.dart
index be9c2b8a69..a6f156228a 100644
--- a/mobile/apps/auth/lib/ui/code_widget.dart
+++ b/mobile/apps/auth/lib/ui/code_widget.dart
@@ -478,7 +478,7 @@ class _CodeWidgetState extends State<CodeWidget> {
_getCurrentOTP(),
confirmationMessage: context.l10n.copiedToClipboard,
);
- _udateCodeMetadata().ignore();
+ _updateCodeMetadata().ignore();
}
void _copyNextToClipboard() {
@@ -486,10 +486,10 @@ class _CodeWidgetState extends State<CodeWidget> {
_getNextTotp(),
confirmationMessage: context.l10n.copiedNextToClipboard,
);
- _udateCodeMetadata().ignore();
+ _updateCodeMetadata().ignore();
}
- Future<void> _udateCodeMetadata() async {
+ Future<void> _updateCodeMetadata() async {
if (widget.sortKey == null) return;
Future.delayed(const Duration(milliseconds: 100), () {
if (mounted) {
@@ -502,7 +502,7 @@ class _CodeWidgetState extends State<CodeWidget> {
lastUsedAt: DateTime.now().microsecondsSinceEpoch,
),
);
- unawaited(CodeStore.instance.addCode(code));
+ unawaited(CodeStore.instance.updateCode(widget.code, code));
}
}
});
@@ -568,7 +568,7 @@ class _CodeWidgetState extends State<CodeWidget> {
),
);
if (code != null) {
- await CodeStore.instance.addCode(code);
+ await CodeStore.instance.updateCode(widget.code, code);
}
}
@@ -615,7 +615,7 @@ class _CodeWidgetState extends State<CodeWidget> {
display: display.copyWith(pinned: !currentlyPinned),
);
unawaited(
- CodeStore.instance.addCode(code).then(
+ CodeStore.instance.updateCode(widget.code,code).then(
(value) => showToast(
context,
!currentlyPinned
@@ -694,7 +694,7 @@ class _CodeWidgetState extends State<CodeWidget> {
final Code code = widget.code.copyWith(
display: display.copyWith(trashed: true),
);
- await CodeStore.instance.addCode(code);
+ await CodeStore.instance.updateCode(widget.code, code);
} catch (e) {
logger.severe('Failed to trash code: ${e.toString()}');
showGenericErrorDialog(context: context, error: e).ignore();
@@ -718,7 +718,7 @@ class _CodeWidgetState extends State<CodeWidget> {
final Code code = widget.code.copyWith(
display: display.copyWith(trashed: false),
);
- await CodeStore.instance.addCode(code);
+ await CodeStore.instance.updateCode(widget.code, code);
} catch (e) {
logger.severe('Failed to restore code: ${e.toString()}');
if (mounted) {
diff --git a/mobile/apps/auth/lib/ui/home_page.dart b/mobile/apps/auth/lib/ui/home_page.dart
index e9fc15eb80..fef19bde21 100644
--- a/mobile/apps/auth/lib/ui/home_page.dart
+++ b/mobile/apps/auth/lib/ui/home_page.dart
@@ -150,6 +150,7 @@ class _HomePageState extends State<HomePage> {
}
void _loadCodes() {
+ debugPrint("[HOME_DEBUG] _loadCodes triggered!");
CodeStore.instance.getAllCodes().then((codes) {
_allCodes = codes;
hasTrashedCodes = false;
diff --git a/mobile/apps/auth/lib/ui/settings/data/import/encrypted_ente_import.dart b/mobile/apps/auth/lib/ui/settings/data/import/encrypted_ente_import.dart
index 4b055d2cf9..5bde23c72a 100644
--- a/mobile/apps/auth/lib/ui/settings/data/import/encrypted_ente_import.dart
+++ b/mobile/apps/auth/lib/ui/settings/data/import/encrypted_ente_import.dart
@@ -5,7 +5,6 @@ import 'dart:io';
import 'package:ente_auth/l10n/l10n.dart';
import 'package:ente_auth/models/code.dart';
import 'package:ente_auth/models/export/ente.dart';
-import 'package:ente_auth/services/authenticator_service.dart';
import 'package:ente_auth/store/code_store.dart';
import 'package:ente_auth/ui/components/buttons/button_widget.dart';
import 'package:ente_auth/ui/components/dialog_widget.dart';
@@ -46,7 +45,7 @@ Future<void> showEncryptedImportInstruction(BuildContext context) async {
if (result?.action != null && result!.action != ButtonAction.cancel) {
if (result.action == ButtonAction.first) {
await _pickEnteJsonFile(context);
- } else {}
+ }
}
}
@@ -58,6 +57,9 @@ Future<void> _decryptExportData(
final l10n = context.l10n;
bool isPasswordIncorrect = false;
int? importedCodeCount;
+
+ bool importHasRun = false;
+
await showTextInputDialog(
context,
title: l10n.passwordForDecryptingExport,
@@ -67,6 +69,11 @@ Future<void> _decryptExportData(
alwaysShowSuccessState: false,
showOnlyLoadingState: true,
onSubmit: (String password) async {
+ if (importHasRun) {
+ return;
+ }
+ importHasRun = true;
+
if (password.isEmpty) {
showToast(context, l10n.passwordEmptyError);
Future.delayed(const Duration(seconds: 0), () {
@@ -78,6 +85,7 @@ Future<void> _decryptExportData(
final progressDialog = createProgressDialog(context, l10n.pleaseWait);
try {
await progressDialog.show();
+
final derivedKey = await CryptoUtil.deriveKey(
utf8.encode(password),
CryptoUtil.base642bin(enteAuthExport.kdfParams.salt),
@@ -85,7 +93,6 @@ Future<void> _decryptExportData(
enteAuthExport.kdfParams.opsLimit,
);
Uint8List? decryptedContent;
- // Encrypt the key with this derived key
try {
decryptedContent = await CryptoUtil.decryptData(
CryptoUtil.base642bin(enteAuthExport.encryptedData),
@@ -99,27 +106,62 @@ Future<void> _decryptExportData(
}
if (isPasswordIncorrect) {
await progressDialog.hide();
-
Future.delayed(const Duration(seconds: 0), () {
_decryptExportData(context, enteAuthExport, password: password);
});
return;
}
+
String content = utf8.decode(decryptedContent!);
List<String> splitCodes = content.split("\n");
- final parsedCodes = [];
- for (final code in splitCodes) {
+
+ final List<Code> parsedCodes = [];
+ for (final line in splitCodes) {
+ if (line.trim().isEmpty) continue;
try {
- parsedCodes.add(Code.fromOTPAuthUrl(code));
+ String otpUrl = jsonDecode(line);
+ parsedCodes.add(Code.fromOTPAuthUrl(otpUrl));
} catch (e) {
Logger('EncryptedText').severe("Could not parse code", e);
}
}
- for (final code in parsedCodes) {
- await CodeStore.instance.addCode(code, shouldSync: false);
+
+ final List<Code> codesInApp = await CodeStore.instance.getAllCodes();
+ final Map<String, Code> appCodesBySecret = { for (var code in codesInApp) code.secret: code };
+ final List<Code> codesToImportAsNew = [];
+ final List<Code> codesToUpdate = [];
+ final Set<String> processedSecrets = {};
+
+ for (final codeFromFile in parsedCodes) {
+ if (processedSecrets.contains(codeFromFile.secret)) {
+ continue;
+ }
+ processedSecrets.add(codeFromFile.secret);
+ if (appCodesBySecret.containsKey(codeFromFile.secret)) {
+ final originalCodeInApp = appCodesBySecret[codeFromFile.secret]!;
+ final updatedCode = codeFromFile.copyWith();
+ updatedCode.generatedID = originalCodeInApp.generatedID;
+ codesToUpdate.add(updatedCode);
+ } else {
+ codesToImportAsNew.add(codeFromFile);
+ }
+ }
+
+
+ if (codesToUpdate.isNotEmpty) {
+ for (final codeToUpdate in codesToUpdate) {
+ final originalCode = appCodesBySecret[codeToUpdate.secret]!;
+ await CodeStore.instance.updateCode(originalCode, codeToUpdate, shouldSync: false);
+ }
}
- unawaited(AuthenticatorService.instance.onlineSync());
- importedCodeCount = parsedCodes.length;
+ if (codesToImportAsNew.isNotEmpty) {
+ for (final newCode in codesToImportAsNew) {
+ await CodeStore.instance.addCode(newCode, shouldSync: false);
+ }
+ }
+
+ importedCodeCount = codesToImportAsNew.length + codesToUpdate.length;
+
await progressDialog.hide();
} catch (e, s) {
await progressDialog.hide();
@@ -153,4 +195,4 @@ Future<void> _pickEnteJsonFile(BuildContext context) async {
context.l10n.importFailureDescNew,
);
}
-}
+}
\ No newline at end of file
diff --git a/mobile/apps/auth/lib/ui/settings/data/local_backup_settings_page.dart b/mobile/apps/auth/lib/ui/settings/data/local_backup_settings_page.dart
index 449e3ce9b0..1a1aa5d5c9 100644
--- a/mobile/apps/auth/lib/ui/settings/data/local_backup_settings_page.dart
+++ b/mobile/apps/auth/lib/ui/settings/data/local_backup_settings_page.dart
@@ -1,3 +1,6 @@
+import 'dart:io';
+
+import 'package:ente_auth/ente_theme_data.dart';
import 'package:ente_auth/l10n/l10n.dart';
import 'package:ente_auth/services/local_backup_service.dart';
import 'package:ente_auth/theme/ente_theme.dart';
@@ -5,6 +8,7 @@ import 'package:ente_auth/utils/dialog_util.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
+import 'package:path_provider/path_provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
class LocalBackupSettingsPage extends StatefulWidget {
@@ -34,25 +38,41 @@ class _LocalBackupSettingsPageState extends State<LocalBackupSettingsPage> {
});
}
+ Future<String> _getDefaultBackupPath() async {
+ Directory? dir;
+ if (Platform.isAndroid) {
+ dir = await getExternalStorageDirectory();
+ //so default path would be /storage/emulated/0/Android/data/io.ente.auth/files/Downloads
+ return '${dir!.path}/Downloads/EnteAuthBackups';
+ } else {
+ // Fallback for iOS and other platforms
+ dir = await getDownloadsDirectory();
+ return '${dir!.path}/EnteAuthBackups';
+ }
+}
+
// opens directory picker
Future<void> _pickAndSaveBackupLocation() async {
- String? directoryPath = await FilePicker.platform.getDirectoryPath();
-
- if (directoryPath != null) {
+ //to fetch the current backup path
final prefs = await SharedPreferences.getInstance();
- await prefs.setString('autoBackupPath', directoryPath);
- setState(() {
- _backupPath = directoryPath;
- });
- await LocalBackupService.instance.triggerAutomaticBackup(); //whenever backup path is set, we trigger
- final l10n = context.l10n;
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(
- content: Text(l10n.locationUpdatedAndBackupCreated),),
- );
+ String? directoryPath = await FilePicker.platform.getDirectoryPath();
+
+ if (directoryPath != null) {
+ await prefs.setString('autoBackupPath', directoryPath);
+ setState(() {
+ _backupPath = directoryPath;
+ });
+
+ await LocalBackupService.instance.triggerAutomaticBackup();
+ final l10n = context.l10n;
+ ScaffoldMessenger.of(context).showSnackBar(
+ SnackBar(
+ content: Text(l10n.locationUpdatedAndBackupCreated),
+ ),
+ );
+ }
}
-}
Future<void> _showSetPasswordDialog() async {
final l10n = context.l10n;
@@ -63,21 +83,48 @@ Future<void> _showSetPasswordDialog() async {
hintText: l10n.enterPassword,
isPasswordInput: true,
onSubmit: (String password) async {
- if (password.length < 8) {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('Password must be at least 8 characters long.')),
- );
- return;
- }
-
- // to store the backup password securely
- const storage = FlutterSecureStorage();
- await storage.write(key: 'autoBackupPassword', value: password);
-
+ if (password.length < 8) {
+ ScaffoldMessenger.of(context).showSnackBar(
+ SnackBar(
+ content: Text(l10n.passwordTooShort),
+ ),
+ );
+ return;
+}
+ const storage = FlutterSecureStorage();
+ await storage.write(key: 'autoBackupPassword', value: password);
+ final prefs = await SharedPreferences.getInstance();
+ await prefs.setBool('isAutoBackupEnabled', true);
+
+ String? finalBackupPath = _backupPath;
+
+ if (finalBackupPath == null) {
+ try {
+ finalBackupPath = await _getDefaultBackupPath();
+ await Directory(finalBackupPath).create(recursive: true);
+ await prefs.setString('autoBackupPath', finalBackupPath);
+ } catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('Backup password saved successfully!')),
- );
- },
+ SnackBar(
+ content: Text(l10n.noDefaultBackupFolder),
+ ),
+);
+
+ await prefs.setBool('isAutoBackupEnabled', false);
+ return;
+ }
+ }
+
+ setState(() {
+ _isBackupEnabled = true;
+ _backupPath = finalBackupPath;
+ });
+
+ await LocalBackupService.instance.triggerAutomaticBackup();
+ScaffoldMessenger.of(context).showSnackBar(
+ SnackBar(content: Text(l10n.initialBackupCreated)),
+);
+},
);
}
@@ -88,7 +135,8 @@ Future<void> _showSetPasswordDialog() async {
appBar: AppBar(
title: Text(l10n.localBackupSettingsTitle),
),
- body: Padding(
+ body: SingleChildScrollView(
+ child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -100,36 +148,26 @@ Future<void> _showSetPasswordDialog() async {
l10n.enableAutomaticBackups,
style: getEnteTextTheme(context).largeBold,
),
- Switch(
- value: _isBackupEnabled,
- activeColor: Colors.white,
- onChanged: (value) async {
- final l10n = context.l10n;
- final prefs = await SharedPreferences.getInstance();
- await prefs.setBool('isAutoBackupEnabled', value);
- setState(() {
- _isBackupEnabled = value;
- });
-
- if (value == true) { //if toggle was on: trigger backup
- if (_backupPath != null) { //ensuring path was set
- await LocalBackupService.instance.triggerAutomaticBackup();
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(
- content: Text(l10n.initialBackupCreated),),
- );
- }
- else {
- // we ask user to set a backup location
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(
- content:
- Text(l10n.pleaseChooseBackupLocation),),
- );
- }
- }
- },
- ),
+ Switch.adaptive(
+ value: _isBackupEnabled,
+ activeColor: Theme.of(context).colorScheme.enteTheme.colorScheme.primary400,
+ activeTrackColor: Theme.of(context).colorScheme.enteTheme.colorScheme.primary300,
+ inactiveTrackColor: Theme.of(context).colorScheme.enteTheme.colorScheme.fillMuted,
+ materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
+ onChanged: (value) async {
+ final prefs = await SharedPreferences.getInstance();
+
+ if (value == true) {
+ //when toggle is ON, show password dialog
+ await _showSetPasswordDialog();
+ } else {
+ await prefs.setBool('isAutoBackupEnabled', false);
+ setState(() {
+ _isBackupEnabled = false;
+ });
+ }
+},
+),
],
),
const SizedBox(height: 20),
@@ -158,35 +196,43 @@ Future<void> _showSetPasswordDialog() async {
style: getEnteTextTheme(context).body,
),
const SizedBox(height: 4),
- Text(
- _backupPath ?? l10n.notSetPleaseChooseLocation,
- style: getEnteTextTheme(context).small.copyWith(
- color: _backupPath != null
- ? null
- : Colors.grey,
- ),
- ),
+if (_backupPath != null)
+ Text(
+ _backupPath!,
+ style: getEnteTextTheme(context).small,
+ )
+else
+ FutureBuilder<String>(
+ future: _getDefaultBackupPath(),
+ builder: (context, snapshot) {
+ if (snapshot.connectionState == ConnectionState.waiting) {
+ return Text(
+ "Loading default location...",
+ style: getEnteTextTheme(context).small.copyWith(color: Colors.grey),
+ );
+ } else if (snapshot.hasError) {
+ return Text(
+ "Could not determine location.",
+ style: getEnteTextTheme(context).small.copyWith(color: Colors.red),
+ );
+
+ } else {
+ return Text(
+ snapshot.data ?? '',
+ style: getEnteTextTheme(context).small.copyWith(color: Colors.grey),
+ );
+ }
+ },
+ ),
const SizedBox(height: 30),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _pickAndSaveBackupLocation,
- child: Text(l10n.chooseLocation),
+ child: Text(l10n.changeLocation),
),
),
- const SizedBox(height: 10),
- SizedBox(
- width: double.infinity,
- child: ElevatedButton(
- style: ElevatedButton.styleFrom(
- backgroundColor: Theme.of(context).colorScheme.secondary,
- foregroundColor: Theme.of(context).colorScheme.onSecondary,
- ),
- onPressed: _showSetPasswordDialog,
- child: const Text('Set Backup Password'),
- ),
- ),
],
),
@@ -239,6 +285,7 @@ Future<void> _showSetPasswordDialog() async {
],
),
),
+ ),
);
}
}
\ No newline at end of file
diff --git a/mobile/apps/auth/pubspec.lock b/mobile/apps/auth/pubspec.lock
index 24dcf85ffe..e3e1aab62a 100644
--- a/mobile/apps/auth/pubspec.lock
+++ b/mobile/apps/auth/pubspec.lock
@@ -1083,9 +1083,9 @@ packages:
dependency: "direct main"
description:
path: "."
- ref: "91e4d1a9c55b28bf93425d1f12faf410efc1e48d"
- resolved-ref: "91e4d1a9c55b28bf93425d1f12faf410efc1e48d"
- url: "https://github.com/Sayegh7/move_to_background"
+ ref: v2-only
+ resolved-ref: "0cdfeed654d79636eff0c57110f3f6ad5801ba2f"
+ url: "https://github.com/ente-io/move_to_background.git"
source: git
version: "1.0.2"
native_dio_adapter:
diff --git a/mobile/apps/auth/pubspec.yaml b/mobile/apps/auth/pubspec.yaml
index 03afdaad57..e2db74feb5 100644
--- a/mobile/apps/auth/pubspec.yaml
+++ b/mobile/apps/auth/pubspec.yaml
@@ -78,10 +78,10 @@ dependencies:
local_auth_darwin: ^1.2.2
logging: ^1.0.1
modal_bottom_sheet: ^3.0.0
- move_to_background: # no package updates on pub.dev
+ move_to_background: # no updates in git, replace package
git:
- url: https://github.com/Sayegh7/move_to_background
- ref: 91e4d1a9c55b28bf93425d1f12faf410efc1e48d
+ url: https://github.com/ente-io/move_to_background.git
+ ref: v2-only
native_dio_adapter: ^1.4.0
otp: ^3.1.1
package_info_plus: ^8.0.2