ente/lib/main.dart

106 lines
3 KiB
Dart
Raw Normal View History

2020-05-02 11:46:59 +00:00
import 'dart:async';
2020-08-13 23:04:32 +00:00
import 'package:computer/computer.dart';
2020-03-24 19:59:36 +00:00
import 'package:flutter/material.dart';
2021-01-08 17:11:32 +00:00
import 'package:in_app_purchase/in_app_purchase.dart';
2020-05-02 16:28:54 +00:00
import 'package:path_provider/path_provider.dart';
import 'package:photos/core/constants.dart';
import 'package:photos/core/configuration.dart';
2021-01-08 06:38:45 +00:00
import 'package:photos/services/billing_service.dart';
import 'package:photos/services/collections_service.dart';
2020-10-03 17:56:18 +00:00
import 'package:photos/services/memories_service.dart';
2020-10-03 17:58:26 +00:00
import 'package:photos/services/sync_service.dart';
import 'package:photos/ui/home_widget.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';
2020-08-21 23:28:52 +00:00
final _logger = Logger("main");
2020-03-24 19:59:36 +00:00
void main() async {
WidgetsFlutterBinding.ensureInitialized();
2020-11-19 18:22:30 +00:00
SuperLogging.logDirPath = (await getTemporaryDirectory()).path + "/logs";
SuperLogging.enableInDebugMode = true;
2020-11-30 10:33:22 +00:00
SuperLogging.maxLogFiles = 5;
2020-11-19 18:22:30 +00:00
await SuperLogging.main(_main);
2020-05-02 16:28:54 +00:00
}
void _main() async {
2020-08-13 23:04:32 +00:00
Computer().turnOn(
workersCount: 4,
areLogsEnabled: false,
);
2021-01-08 17:11:32 +00:00
InAppPurchaseConnection.enablePendingPurchases();
await Configuration.instance.init();
await CollectionsService.instance.init();
2020-10-03 17:58:26 +00:00
await SyncService.instance.init();
2020-07-21 12:19:55 +00:00
await MemoriesService.instance.init();
2021-01-08 06:38:45 +00:00
await BillingService.instance.init();
_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),
);
}
void _sync() async {
2020-10-12 20:34:34 +00:00
SyncService.instance.sync().catchError((e, s) {
_logger.severe("Sync error", e, s);
2020-07-10 18:17:51 +00:00
});
}
2020-05-02 16:28:54 +00:00
void _sendErrorToSentry(SentryClient sentry, Object error, StackTrace stack) {
2020-08-21 23:28:52 +00:00
_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-08-07 15:58:15 +00:00
final _title = 'ente';
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,
2020-12-03 19:36:18 +00:00
theme: ThemeData(
2020-12-12 00:31:06 +00:00
fontFamily: 'Ubuntu',
2020-12-03 19:36:18 +00:00
brightness: Brightness.dark,
2020-08-25 06:00:19 +00:00
hintColor: Colors.grey,
accentColor: Colors.pink[400],
buttonColor: Colors.pink,
2020-10-09 23:46:51 +00:00
buttonTheme: ButtonThemeData().copyWith(
buttonColor: Colors.pink,
),
2020-09-17 19:03:21 +00:00
toggleableActiveColor: Colors.pink[400],
2020-08-25 06:00:19 +00:00
),
2020-05-04 20:03:06 +00:00
home: 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-11-30 10:47:06 +00:00
_logger.info("App resumed");
_sync();
2020-04-27 13:02:29 +00:00
}
}
2020-04-05 08:31:01 +00:00
}