diff --git a/lib/database/app_database.dart b/lib/database/app_database.dart index a68a0f02..9bcbe0d6 100644 --- a/lib/database/app_database.dart +++ b/lib/database/app_database.dart @@ -197,8 +197,29 @@ class AppDatabase extends _$AppDatabase { LazyDatabase _openConnection() { return LazyDatabase(() async { - final dbFolder = await getApplicationDocumentsDirectory(); + final Directory dbFolder; + if (Platform.isAndroid || Platform.isIOS) { + dbFolder = await getApplicationDocumentsDirectory(); + } else { + dbFolder = await getApplicationSupportDirectory(); + } + final file = File(p.join(dbFolder.path, 'plezy_downloads.db')); + + // Ensure directory exists + if (!await file.parent.exists()) { + await file.parent.create(recursive: true); + } + + // Migrate from old location on desktop (was in Documents subfolder) + if (!Platform.isAndroid && !Platform.isIOS && !await file.exists()) { + final oldFolder = await getApplicationDocumentsDirectory(); + final oldFile = File(p.join(oldFolder.path, 'plezy_downloads.db')); + if (await oldFile.exists()) { + await oldFile.rename(file.path); + } + } + return NativeDatabase(file); }); }