ente/lib/main.dart

84 lines
2.2 KiB
Dart
Raw Normal View History

2020-05-02 11:46:59 +00:00
import 'dart:async';
2020-03-24 19:59:36 +00:00
import 'package:flutter/material.dart';
2020-05-02 16:28:54 +00:00
import 'package:path_provider/path_provider.dart';
import 'package:photos/core/constants.dart';
2020-05-01 18:20:12 +00:00
import 'core/configuration.dart';
import 'photo_loader.dart';
import 'photo_sync_manager.dart';
import 'ui/home_widget.dart';
import 'package:provider/provider.dart';
2020-05-02 11:46:59 +00:00
import 'package:sentry/sentry.dart';
import 'package:super_logging/super_logging.dart';
2020-05-02 16:28:54 +00:00
import 'package:logging/logging.dart';
final logger = Logger("main");
2020-03-24 19:59:36 +00:00
void main() async {
WidgetsFlutterBinding.ensureInitialized();
2020-05-02 16:28:54 +00:00
SuperLogging.main(LogConfig(
body: _main,
sentryDsn: SENTRY_DSN,
logDirPath: (await getTemporaryDirectory()).path + "/logs",
enableInDebugMode: true,
));
}
void _main() {
WidgetsFlutterBinding.ensureInitialized();
2020-04-30 15:09:41 +00:00
Configuration.instance.init();
PhotoSyncManager.instance.sync();
2020-05-02 11:46:59 +00:00
2020-05-02 16:28:54 +00:00
final SentryClient sentry = new SentryClient(dsn: SENTRY_DSN);
2020-05-02 11:46:59 +00:00
FlutterError.onError = (FlutterErrorDetails details) async {
FlutterError.dumpErrorToConsole(details, forceReport: true);
_sendErrorToSentry(sentry, details.exception, details.stack);
};
runZoned(
() => runApp(MyApp()),
onError: (Object error, StackTrace stackTrace) =>
_sendErrorToSentry(sentry, error, stackTrace),
);
}
2020-05-02 16:28:54 +00:00
void _sendErrorToSentry(SentryClient sentry, Object error, StackTrace stack) {
logger.shout("Uncaught error", error, stack);
2020-05-02 11:46:59 +00:00
try {
sentry.captureException(
exception: error,
2020-05-02 16:28:54 +00:00
stackTrace: stack,
2020-05-02 11:46:59 +00:00
);
print('Error sent to sentry.io: $error');
} catch (e) {
print('Sending report to sentry.io failed: $e');
print('Original error: $error');
}
2020-03-24 19:59:36 +00:00
}
2020-03-27 16:07:55 +00:00
2020-04-27 13:02:29 +00:00
class MyApp extends StatelessWidget with WidgetsBindingObserver {
2020-05-01 18:20:12 +00:00
final _title = 'Photos';
2020-04-05 08:31:01 +00:00
@override
Widget build(BuildContext context) {
2020-04-27 13:02:29 +00:00
WidgetsBinding.instance.addObserver(this);
2020-04-14 15:36:18 +00:00
return MaterialApp(
title: _title,
theme: ThemeData.dark(),
home: ChangeNotifierProvider<PhotoLoader>.value(
value: PhotoLoader.instance,
child: HomeWidget(_title),
),
2020-04-05 08:31:01 +00:00
);
}
2020-04-27 13:02:29 +00:00
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
2020-04-30 15:09:41 +00:00
PhotoSyncManager.instance.sync();
2020-04-27 13:02:29 +00:00
}
}
2020-04-05 08:31:01 +00:00
}