2021-04-10 06:28:12 +02:00
|
|
|
import 'package:equatable/equatable.dart';
|
|
|
|
import 'package:event_bus/event_bus.dart';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/gestures.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import 'package:kiwi/kiwi.dart';
|
|
|
|
import 'package:logging/logging.dart';
|
2021-04-16 10:45:17 +02:00
|
|
|
import 'package:nc_photos/k.dart' as k;
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/metadata_task_manager.dart';
|
|
|
|
import 'package:nc_photos/pref.dart';
|
2021-04-17 10:42:57 +02:00
|
|
|
import 'package:nc_photos/widget/my_app.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
|
|
|
|
void main() async {
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
_initLog();
|
|
|
|
await _initPref();
|
|
|
|
_initBloc();
|
|
|
|
_initKiwi();
|
|
|
|
_initEquatable();
|
|
|
|
|
2021-04-17 10:42:57 +02:00
|
|
|
runApp(MyApp());
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void _initLog() {
|
|
|
|
if (kDebugMode) {
|
|
|
|
debugPrintGestureArenaDiagnostics = true;
|
|
|
|
}
|
2021-04-20 12:53:41 +02:00
|
|
|
Logger.root.level = kReleaseMode ? Level.WARNING : Level.ALL;
|
2021-04-10 06:28:12 +02:00
|
|
|
Logger.root.onRecord.listen((record) {
|
|
|
|
// dev.log(
|
|
|
|
// "${record.level.name} ${record.time}: ${record.message}",
|
|
|
|
// time: record.time,
|
|
|
|
// sequenceNumber: record.sequenceNumber,
|
|
|
|
// level: record.level.value,
|
|
|
|
// name: record.loggerName,
|
|
|
|
// );
|
|
|
|
String msg =
|
|
|
|
"[${record.loggerName}] ${record.level.name} ${record.time}: ${record.message}";
|
|
|
|
if (record.error != null) {
|
|
|
|
msg += " (throw: ${record.error.runtimeType} { ${record.error} })";
|
|
|
|
}
|
|
|
|
if (record.stackTrace != null) {
|
|
|
|
msg += "\nStack Trace:\n${record.stackTrace}";
|
|
|
|
}
|
|
|
|
debugPrint(msg);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-16 10:45:17 +02:00
|
|
|
Future<void> _initPref() async {
|
|
|
|
await Pref.init();
|
|
|
|
if (Pref.inst().getLastVersion(null) == null) {
|
|
|
|
if (Pref.inst().getSetupProgress(null) == null) {
|
|
|
|
// new install
|
|
|
|
await Pref.inst().setLastVersion(k.version);
|
|
|
|
} else {
|
|
|
|
// v6 is the last version without saving the version number in pref
|
|
|
|
await Pref.inst().setLastVersion(6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-10 06:28:12 +02:00
|
|
|
|
|
|
|
void _initBloc() {
|
|
|
|
Bloc.observer = _BlocObserver();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _initKiwi() {
|
|
|
|
final kiwi = KiwiContainer();
|
|
|
|
kiwi.registerInstance<EventBus>(EventBus());
|
|
|
|
kiwi.registerInstance<MetadataTaskManager>(MetadataTaskManager());
|
|
|
|
}
|
|
|
|
|
|
|
|
void _initEquatable() {
|
|
|
|
EquatableConfig.stringify = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
class _BlocObserver extends BlocObserver {
|
|
|
|
@override
|
|
|
|
onChange(BlocBase bloc, Change change) {
|
|
|
|
super.onChange(bloc, change);
|
|
|
|
_log.finer("${bloc.runtimeType} $change");
|
|
|
|
}
|
|
|
|
|
|
|
|
static final _log = Logger("_BlocObserver");
|
|
|
|
}
|