Skip to content
This repository was archived by the owner on May 22, 2024. It is now read-only.

Commit 9696797

Browse files
committed
🐛 Try to fix crash on launch on some iOS devices
1 parent 1e65bb5 commit 9696797

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

lib/app/src/migrations.dart

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,26 @@ Future<void> _fromV12ToV13() async {
2323
if (appAccount != null && appAccount.isNotEmpty) {
2424
String? newAppAccount;
2525
if (appAccount.contains('"apiType":"Pronote"')) {
26-
newAppAccount = appAccount.replaceAll('"apiType":"Pronote"', '"apiType":"pronote"');
26+
newAppAccount =
27+
appAccount.replaceAll('"apiType":"Pronote"', '"apiType":"pronote"');
2728
} else if (appAccount.contains('"apiType":"EcoleDirecte"')) {
28-
newAppAccount = appAccount.replaceAll('"apiType":"EcoleDirecte"', '"apiType":"ecoleDirecte"');
29+
newAppAccount = appAccount.replaceAll(
30+
'"apiType":"EcoleDirecte"', '"apiType":"ecoleDirecte"');
2931
}
3032
if (newAppAccount != null) {
3133
await KVS.write(key: "appAccount", value: newAppAccount);
3234
}
3335
}
36+
3437
// As the logging system changed, the `logs.txt` file is no longer useful.
3538
final directory = await FileStorage.getAppDirectory();
3639
final File file = File("${directory.path}/logs.txt");
3740
if (await file.exists()) {
38-
await file.delete();
41+
try {
42+
await file.delete();
43+
} catch (e) {
44+
Logger.error(e);
45+
}
3946
}
4047
// There was an issue with new logs that can be corrupted.
4148
// In order to get the new system working, the old `logs` folder
@@ -49,7 +56,8 @@ Future<void> _fromV12ToV13() async {
4956
}
5057
await KVS.write(key: "logsReset0", value: "true");
5158
} catch (e) {
52-
Logger.log("BACKWARD COMPATIBILITY", "Error while deleting logs folder: $e");
59+
Logger.log(
60+
"BACKWARD COMPATIBILITY", "Error while deleting logs folder: $e");
5361
}
5462
}
5563
// Logging is done in another check because the logs would have been removed
@@ -72,7 +80,8 @@ Future<void> _fromV13ToV14() async {
7280
// await LogsManager.deleteLogs();
7381
await KVS.write(key: "logsReset2", value: "true");
7482
} catch (e) {
75-
Logger.log("BACKWARD COMPATIBILITY", "Error while deleting logs folder: $e");
83+
Logger.log(
84+
"BACKWARD COMPATIBILITY", "Error while deleting logs folder: $e");
7685
}
7786
}
7887
// Logging is done in another check because the logs would have been removed
@@ -89,8 +98,12 @@ Future<void> _fromV14ToV15() async {
8998
final bool fullReset0 = (await KVS.read(key: "fullReset0")) == "true";
9099
if (!fullReset0) {
91100
await KVS.deleteAll();
92-
final Directory dir = await FileStorage.getAppDirectory();
93-
dir.deleteSync(recursive: true);
94-
await KVS.write(key: "fullReset0", value: "true");
101+
try {
102+
final Directory dir = await FileStorage.getAppDirectory();
103+
dir.deleteSync(recursive: true);
104+
await KVS.write(key: "fullReset0", value: "true");
105+
} catch (e) {
106+
Logger.error(e);
107+
}
95108
}
96109
}

lib/core/src/utilities/file_storage.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class FileStorage {
2929
/// Get the directory of the app storage.
3030
static Future<Directory> getAppDirectory({bool downloads = false}) async {
3131
if (!kIsWeb) {
32-
final Directory appDirectory = await getApplicationDocumentsDirectory();
32+
final Directory appDirectory = await getApplicationSupportDirectory();
3333
final Directory documentsDirectory =
3434
(Platform.isLinux || Platform.isWindows) ? Directory("${appDirectory.path}/yNotesApp/") : appDirectory;
3535
final Directory downloadsDirectory = Directory("${documentsDirectory.path}/downloads/");

0 commit comments

Comments
 (0)