clean main function

This commit is contained in:
otsmr 2026-04-26 11:45:05 +02:00
parent c6d13a44e9
commit 5b5140ec7c

View file

@ -28,7 +28,6 @@ import 'package:twonly/src/services/user.service.dart';
import 'package:twonly/src/utils/avatars.dart'; import 'package:twonly/src/utils/avatars.dart';
import 'package:twonly/src/utils/log.dart'; import 'package:twonly/src/utils/log.dart';
import 'package:twonly/src/utils/secure_storage.dart'; import 'package:twonly/src/utils/secure_storage.dart';
import 'package:twonly/src/utils/storage.dart';
/// This function is used to initialized the absolute minimum so it /// This function is used to initialized the absolute minimum so it
/// can also be used by the backend without the UI was loaded. /// can also be used by the backend without the UI was loaded.
@ -58,6 +57,7 @@ void main() async {
var userExists = false; var userExists = false;
var storageError = false; var storageError = false;
try { try {
userExists = await userService.tryInit(); userExists = await userService.tryInit();
} catch (e) { } catch (e) {
@ -65,8 +65,9 @@ void main() async {
storageError = true; storageError = true;
} }
final dbFile = File('${AppEnvironment.supportDir}/twonly.sqlite'); final dbExists = File(
final dbExists = dbFile.existsSync(); '${AppEnvironment.supportDir}/twonly.sqlite',
).existsSync();
if (Platform.isIOS && userExists) { if (Platform.isIOS && userExists) {
if (!dbExists) { if (!dbExists) {
@ -76,6 +77,10 @@ void main() async {
} }
} }
final settingsController = SettingsChangeProvider()..loadSettings();
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
await initFileDownloader();
if (userExists) { if (userExists) {
if (userService.currentUser.allowErrorTrackingViaSentry) { if (userService.currentUser.allowErrorTrackingViaSentry) {
AppState.allowErrorTrackingViaSentry = true; AppState.allowErrorTrackingViaSentry = true;
@ -90,30 +95,7 @@ void main() async {
unawaited(performTwonlySafeBackup()); unawaited(performTwonlySafeBackup());
unawaited(initializeBackgroundTaskManager()); unawaited(initializeBackgroundTaskManager());
} else if (!storageError) {
if (!dbExists) {
Log.info(
'User is not yet registered and no database found. Ensuring clean state.',
);
await deleteLocalUserData();
} else {
Log.error(
'User not found in secure storage, but database exists. Skipping destructive wipe.',
);
}
} else {
Log.error(
'Storage error occurred and database exists. Skipping wipe to prevent data loss.',
);
}
final settingsController = SettingsChangeProvider()..loadSettings();
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
await initFileDownloader();
if (userExists) {
await runMigrations(); await runMigrations();
await twonlyDB.messagesDao.purgeMessageTable(); await twonlyDB.messagesDao.purgeMessageTable();