Extract db functions out of MyApp

This commit is contained in:
Ming Ming 2021-04-17 16:42:57 +08:00
parent 0b6f399570
commit 5b918b81d4
9 changed files with 14 additions and 21 deletions

View file

@ -29,7 +29,7 @@ class AppDb {
/// Open the database /// Open the database
static Future<Database> _open() async { static Future<Database> _open() async {
final dbFactory = platform.MyApp.getDbFactory(); final dbFactory = platform.getDbFactory();
return dbFactory.open(dbName, version: 1, onUpgradeNeeded: (event) { return dbFactory.open(dbName, version: 1, onUpgradeNeeded: (event) {
final db = event.database; final db = event.database;
if (event.oldVersion < 1) { if (event.oldVersion < 1) {

View file

@ -8,9 +8,8 @@ import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/metadata_task_manager.dart'; import 'package:nc_photos/metadata_task_manager.dart';
import 'package:nc_photos/mobile/platform.dart'
if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform;
import 'package:nc_photos/pref.dart'; import 'package:nc_photos/pref.dart';
import 'package:nc_photos/widget/my_app.dart';
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
@ -21,7 +20,7 @@ void main() async {
_initKiwi(); _initKiwi();
_initEquatable(); _initEquatable();
runApp(platform.MyApp()); runApp(MyApp());
} }
void _initLog() { void _initLog() {

4
lib/mobile/db_util.dart Normal file
View file

@ -0,0 +1,4 @@
import 'package:idb_sqflite/idb_sqflite.dart';
import 'package:sqflite/sqflite.dart';
IdbFactory getDbFactory() => getIdbFactorySqflite(databaseFactory);

View file

@ -1,7 +0,0 @@
import 'package:idb_sqflite/idb_sqflite.dart';
import 'package:nc_photos/widget/my_app.dart' as itf;
import 'package:sqflite/sqflite.dart';
class MyApp extends itf.MyApp {
static IdbFactory getDbFactory() => getIdbFactorySqflite(databaseFactory);
}

View file

@ -1,3 +1,3 @@
export 'db_util.dart';
export 'downloader.dart'; export 'downloader.dart';
export 'metadata_loader.dart'; export 'metadata_loader.dart';
export 'my_app.dart';

4
lib/web/db_util.dart Normal file
View file

@ -0,0 +1,4 @@
import 'package:idb_shim/idb_browser.dart';
import 'package:idb_shim/idb_shim.dart';
IdbFactory getDbFactory() => getIdbFactory();

View file

@ -1,7 +0,0 @@
import 'package:idb_shim/idb_browser.dart';
import 'package:idb_shim/idb_shim.dart';
import 'package:nc_photos/widget/my_app.dart' as itf;
class MyApp extends itf.MyApp {
static IdbFactory getDbFactory() => getIdbFactory();
}

View file

@ -1,3 +1,3 @@
export 'db_util.dart';
export 'downloader.dart'; export 'downloader.dart';
export 'metadata_loader.dart'; export 'metadata_loader.dart';
export 'my_app.dart';

View file

@ -14,7 +14,7 @@ import 'package:nc_photos/widget/sign_in.dart';
import 'package:nc_photos/widget/splash.dart'; import 'package:nc_photos/widget/splash.dart';
import 'package:nc_photos/widget/viewer.dart'; import 'package:nc_photos/widget/viewer.dart';
abstract class MyApp extends StatelessWidget implements SnackBarHandler { class MyApp extends StatelessWidget implements SnackBarHandler {
MyApp() { MyApp() {
SnackBarManager().registerHandler(this); SnackBarManager().registerHandler(this);
} }