diff --git a/Makefile b/Makefile index c96ea52..c147295 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,12 @@ clean-container: build-container pub-get-container: build-container ./flutterw pub get +test: pub-get-container + ./flutterw test + +build-builders: build-container + ./flutterw pub run build_runner build --delete-conflicting-outputs + build-android-release-container: pub-get-container ./flutterw build apk --release diff --git a/TODO.md b/TODO.md index e8b971b..9e405df 100644 --- a/TODO.md +++ b/TODO.md @@ -19,10 +19,10 @@ - [X] Create UnitSpec.toStringLiteral, like Formula.toStringLiteral - [X] Make Formula and UnitSpec subclasses of FormulaElement. Change return type of functions that return Object to FormulaElement if necessary. - [X] Define toStringLiteral in FormulaElement. -- Database file location: - - [ ] In linux, the sqlite database file will be located following rules at https://specifications.freedesktop.org/basedir/latest/ - - [ ] In Windows, the sqlite database file will be in %appdata%/Roaming - - [ ] In Macos, the sqlite database file will be in ~/Library/Application Support +- [X] Database file location: + - [X] In linux, the sqlite database file will be located following rules at https://specifications.freedesktop.org/basedir/latest/ + - [X] In Windows, the sqlite database file will be in %appdata%/Roaming + - [X] In Macos, the sqlite database file will be in ~/Library/Application Support - [ ] Initialize database at startup - [ ] If the database is empty, sugest to use a default corpus - [ ] If the user choose to use the default corpus, populate de database with the default corpus (load defaultcorpus, and the use toStringLiteral) diff --git a/lib/database/formulas_database.dart b/lib/database/formulas_database.dart index 4254503..2502ac6 100644 --- a/lib/database/formulas_database.dart +++ b/lib/database/formulas_database.dart @@ -48,9 +48,22 @@ class FormulasDatabase extends _$FormulasDatabase { LazyDatabase _openConnection() { return LazyDatabase(() async { - // For native platforms (Linux, Windows, macOS, Android, iOS) - final dbFolder = await getApplicationDocumentsDirectory(); - final file = File(p.join(dbFolder.path, 'formulas.sqlite')); + // Determine the platform-specific database directory + Directory dbDirectory; + + if (Platform.isLinux || Platform.isWindows || Platform.isMacOS) { + final appSupportDir = await getApplicationSupportDirectory(); + dbDirectory = Directory(p.join(appSupportDir.path, 'd4rt_formulas')); + } else { + dbDirectory = await getApplicationDocumentsDirectory(); + } + + // Ensure the directory exists + await dbDirectory.create(recursive: true); + + // Create the database file in the platform-specific directory + final file = File(p.join(dbDirectory.path, 'formulas.sqlite')); return NativeDatabase.createInBackground(file); }); -} \ No newline at end of file +} + diff --git a/pubspec.lock b/pubspec.lock index b18c678..8b23f76 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -266,7 +266,7 @@ packages: source: hosted version: "1.3.3" ffi: - dependency: transitive + dependency: "direct main" description: name: ffi sha256: d07d37192dbf97461359c1518788f203b0c9102cfd2c35a716b823741219542c @@ -1078,7 +1078,7 @@ packages: source: hosted version: "1.2.1" xdg_directories: - dependency: transitive + dependency: "direct main" description: name: xdg_directories sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15" diff --git a/pubspec.yaml b/pubspec.yaml index 6bf20be..b51444d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,6 +47,8 @@ dependencies: path_provider: ^2.1.1 path: ^1.8.3 get_it: ^8.0.2 + xdg_directories: ^1.0.0 + ffi: ^2.0.1 collection: any dev_dependencies: