Add platform-specific database directory logic and update Makefile targets

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
Your Name 2026-02-11 09:39:40 +01:00
parent 692ad41502
commit c63a215212
5 changed files with 31 additions and 10 deletions

View file

@ -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

View file

@ -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)

View file

@ -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);
});
}
}

View file

@ -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"

View file

@ -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: