mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-04-21 03:32:06 +00:00
Fix #56 manuall backup crashes the app on iOS
This commit is contained in:
parent
f73f65a117
commit
fb4f2c80f0
3 changed files with 108 additions and 29 deletions
|
|
@ -262,6 +262,8 @@
|
|||
"services":"Services",
|
||||
"tracking_warning_info":"One-way sync yo update the chapter progress in tracking services. Set up tracking for individual entries from their tracking button.",
|
||||
"use_page_tap_zones":"Use page tap zones" ,
|
||||
"manage_trackers":"Manage trackers"
|
||||
"manage_trackers":"Manage trackers",
|
||||
"restore":"Restore",
|
||||
"backups":"Backups"
|
||||
|
||||
}
|
||||
|
|
@ -243,7 +243,7 @@
|
|||
"create_backup_subtitle":"Peut être utilisé pour restaurer la bibliothèque actuelle",
|
||||
"restore_backup":"Restaurer une sauvegarde",
|
||||
"restore_backup_subtitle":"Restaurer la bibliothèque à partir d'un fichier de sauvegarde",
|
||||
"automatic_backups":"Sauvegarders automatiques",
|
||||
"automatic_backups":"Sauvegardes automatiques",
|
||||
"backup_frequency":"Fréquence de sauvegarde",
|
||||
"backup_location":"Dossier de sauvegarde",
|
||||
"backup_options":"Options de sauvegarde",
|
||||
|
|
@ -262,5 +262,7 @@
|
|||
"services":"Services",
|
||||
"tracking_warning_info":"Synchronisation à sens unique pour mettre à jour la progression du chapitre dans les services de suivi. Configurez le suivi des entrées individuelles à partir de leur boutton de suivi.",
|
||||
"use_page_tap_zones":"Utiliser les zones tactiles",
|
||||
"manage_trackers":"Gérer les suivis"
|
||||
"manage_trackers":"Gérer les suivis",
|
||||
"restore":"Restaurer",
|
||||
"backups":"Sauvegardes"
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:io';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
|
@ -8,13 +9,16 @@ import 'package:mangayomi/modules/more/backup_and_restore/providers/backup.dart'
|
|||
import 'package:mangayomi/modules/more/backup_and_restore/providers/restore.dart';
|
||||
import 'package:mangayomi/providers/l10n_providers.dart';
|
||||
import 'package:mangayomi/utils/colors.dart';
|
||||
import 'package:mangayomi/utils/extensions.dart';
|
||||
import 'package:mangayomi/utils/media_query.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
class BackupAndRestore extends ConsumerWidget {
|
||||
const BackupAndRestore({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final isIOS = Platform.isIOS;
|
||||
final backupFrequency = ref.watch(backupFrequencyStateProvider);
|
||||
final backupFrequencyOptions =
|
||||
ref.watch(backupFrequencyOptionsStateProvider);
|
||||
|
|
@ -39,9 +43,7 @@ class BackupAndRestore extends ConsumerWidget {
|
|||
return StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
return AlertDialog(
|
||||
title: Text(
|
||||
l10n.create_backup_dialog_title,
|
||||
),
|
||||
title: Text(l10n.create_backup_dialog_title),
|
||||
content: SizedBox(
|
||||
width: mediaWidth(context, 0.8),
|
||||
child: ListView.builder(
|
||||
|
|
@ -79,14 +81,21 @@ class BackupAndRestore extends ConsumerWidget {
|
|||
)),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
String? result = await FilePicker.platform
|
||||
.getDirectoryPath();
|
||||
|
||||
if (result != null && context.mounted) {
|
||||
if (isIOS) {
|
||||
ref.watch(doBackUpProvider(
|
||||
list: indexList,
|
||||
path: result,
|
||||
path: autoBackupLocation.$1,
|
||||
context: context));
|
||||
} else {
|
||||
final result = await FilePicker.platform
|
||||
.getDirectoryPath();
|
||||
|
||||
if (result != null && context.mounted) {
|
||||
ref.watch(doBackUpProvider(
|
||||
list: indexList,
|
||||
path: result,
|
||||
context: context));
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
|
|
@ -249,22 +258,25 @@ class BackupAndRestore extends ConsumerWidget {
|
|||
style: TextStyle(fontSize: 11, color: secondaryColor(context)),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
onTap: () async {
|
||||
String? result = await FilePicker.platform.getDirectoryPath();
|
||||
if (!isIOS)
|
||||
ListTile(
|
||||
onTap: () async {
|
||||
String? result = await FilePicker.platform.getDirectoryPath();
|
||||
|
||||
if (result != null) {
|
||||
ref.read(autoBackupLocationStateProvider.notifier).set(result);
|
||||
}
|
||||
},
|
||||
title: Text(l10n.backup_location),
|
||||
subtitle: Text(
|
||||
autoBackupLocation.$2.isEmpty
|
||||
? autoBackupLocation.$1
|
||||
: autoBackupLocation.$2,
|
||||
style: TextStyle(fontSize: 11, color: secondaryColor(context)),
|
||||
if (result != null) {
|
||||
ref
|
||||
.read(autoBackupLocationStateProvider.notifier)
|
||||
.set(result);
|
||||
}
|
||||
},
|
||||
title: Text(l10n.backup_location),
|
||||
subtitle: Text(
|
||||
autoBackupLocation.$2.isEmpty
|
||||
? autoBackupLocation.$1
|
||||
: autoBackupLocation.$2,
|
||||
style: TextStyle(fontSize: 11, color: secondaryColor(context)),
|
||||
),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
onTap: () {
|
||||
final list = _getList(context);
|
||||
|
|
@ -342,15 +354,14 @@ class BackupAndRestore extends ConsumerWidget {
|
|||
style: TextStyle(fontSize: 11, color: secondaryColor(context)),
|
||||
),
|
||||
),
|
||||
ListBackupFilesFromDirectory(directory: autoBackupLocation.$1),
|
||||
ListTile(
|
||||
title: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outline_rounded,
|
||||
color: secondaryColor(context),
|
||||
),
|
||||
Icon(Icons.info_outline_rounded,
|
||||
color: secondaryColor(context)),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
@ -387,3 +398,67 @@ List<String> _getBackupFrequencyList(BuildContext context) {
|
|||
l10n.weekly
|
||||
];
|
||||
}
|
||||
|
||||
class ListBackupFilesFromDirectory extends ConsumerWidget {
|
||||
final String directory;
|
||||
const ListBackupFilesFromDirectory({super.key, required this.directory});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final files = Directory(directory)
|
||||
.listSync()
|
||||
.where((element) =>
|
||||
element.path.contains('mangayomi_') &&
|
||||
element.path.endsWith('.backup'))
|
||||
.toList()
|
||||
.reversed
|
||||
.toList();
|
||||
return files.isNotEmpty
|
||||
? SizedBox(
|
||||
height: 200,
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 15, vertical: 5),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(context.l10n.backups,
|
||||
style: TextStyle(
|
||||
fontSize: 13, color: primaryColor(context))),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: files.length,
|
||||
itemBuilder: (_, index) {
|
||||
final file = files[index];
|
||||
final name =
|
||||
'mangayomi_${file.path.substringAfter('mangayomi_')}';
|
||||
return ListTile(
|
||||
title: Text(name),
|
||||
trailing: PopupMenuButton(itemBuilder: (context) {
|
||||
return [
|
||||
PopupMenuItem<int>(
|
||||
value: 0, child: Text(context.l10n.share)),
|
||||
PopupMenuItem<int>(
|
||||
value: 1, child: Text(context.l10n.restore)),
|
||||
];
|
||||
}, onSelected: (value) {
|
||||
if (value == 0) {
|
||||
Share.shareXFiles([XFile(file.path)], text: name);
|
||||
} else if (value == 1) {
|
||||
ref.watch(doRestoreProvider(
|
||||
path: file.path, context: context));
|
||||
}
|
||||
}),
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Container();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue