2020-05-02 17:16:59 +05:30
|
|
|
import 'dart:async';
|
|
|
|
|
2020-08-14 04:34:32 +05:30
|
|
|
import 'package:computer/computer.dart';
|
2020-03-25 01:29:36 +05:30
|
|
|
import 'package:flutter/material.dart';
|
2020-05-02 21:58:54 +05:30
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
import 'package:photos/core/constants.dart';
|
2020-05-05 01:38:20 +05:30
|
|
|
import 'package:photos/core/configuration.dart';
|
2020-10-03 23:26:18 +05:30
|
|
|
import 'package:photos/services/favorites_service.dart';
|
|
|
|
import 'package:photos/services/folder_service.dart';
|
|
|
|
import 'package:photos/services/memories_service.dart';
|
|
|
|
import 'package:photos/file_sync_manager.dart';
|
2020-05-05 01:38:20 +05:30
|
|
|
import 'package:photos/ui/home_widget.dart';
|
2020-05-02 17:16:59 +05:30
|
|
|
import 'package:sentry/sentry.dart';
|
2020-05-04 01:57:06 +05:30
|
|
|
import 'package:super_logging/super_logging.dart';
|
2020-05-02 21:58:54 +05:30
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
|
2020-08-22 04:58:52 +05:30
|
|
|
final _logger = Logger("main");
|
2020-03-25 01:29:36 +05:30
|
|
|
|
|
|
|
void main() async {
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
2020-05-17 18:09:38 +05:30
|
|
|
await SuperLogging.main(LogConfig(
|
2020-05-02 21:58:54 +05:30
|
|
|
body: _main,
|
|
|
|
logDirPath: (await getTemporaryDirectory()).path + "/logs",
|
|
|
|
enableInDebugMode: true,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2020-05-25 19:02:09 +05:30
|
|
|
void _main() async {
|
2020-08-14 04:34:32 +05:30
|
|
|
Computer().turnOn(
|
|
|
|
workersCount: 4,
|
|
|
|
areLogsEnabled: false,
|
|
|
|
);
|
2020-05-25 19:02:09 +05:30
|
|
|
await Configuration.instance.init();
|
2020-10-03 23:26:18 +05:30
|
|
|
await FileSyncManager.instance.init();
|
2020-07-21 17:49:55 +05:30
|
|
|
await MemoriesService.instance.init();
|
2020-10-03 23:26:18 +05:30
|
|
|
await FavoritesService.instance.init();
|
2020-06-16 00:08:08 +05:30
|
|
|
_sync();
|
2020-05-02 17:16:59 +05:30
|
|
|
|
2020-05-02 21:58:54 +05:30
|
|
|
final SentryClient sentry = new SentryClient(dsn: SENTRY_DSN);
|
2020-05-02 17:16:59 +05:30
|
|
|
|
|
|
|
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-06-16 00:08:08 +05:30
|
|
|
void _sync() async {
|
2020-07-10 23:38:26 +05:30
|
|
|
FolderSharingService.instance.sync().catchError((e) {
|
2020-08-22 04:58:52 +05:30
|
|
|
_logger.warning(e);
|
2020-07-10 23:38:26 +05:30
|
|
|
});
|
2020-10-03 23:26:18 +05:30
|
|
|
FileSyncManager.instance.sync().catchError((e) {
|
2020-08-22 04:58:52 +05:30
|
|
|
_logger.warning(e);
|
2020-07-10 23:47:51 +05:30
|
|
|
});
|
2020-06-16 00:08:08 +05:30
|
|
|
}
|
|
|
|
|
2020-05-02 21:58:54 +05:30
|
|
|
void _sendErrorToSentry(SentryClient sentry, Object error, StackTrace stack) {
|
2020-08-22 04:58:52 +05:30
|
|
|
_logger.shout("Uncaught error", error, stack);
|
2020-05-02 17:16:59 +05:30
|
|
|
try {
|
|
|
|
sentry.captureException(
|
|
|
|
exception: error,
|
2020-05-02 21:58:54 +05:30
|
|
|
stackTrace: stack,
|
2020-05-02 17:16:59 +05:30
|
|
|
);
|
|
|
|
print('Error sent to sentry.io: $error');
|
|
|
|
} catch (e) {
|
|
|
|
print('Sending report to sentry.io failed: $e');
|
|
|
|
print('Original error: $error');
|
|
|
|
}
|
2020-03-25 01:29:36 +05:30
|
|
|
}
|
2020-03-27 21:37:55 +05:30
|
|
|
|
2020-04-27 18:32:29 +05:30
|
|
|
class MyApp extends StatelessWidget with WidgetsBindingObserver {
|
2020-08-07 21:28:15 +05:30
|
|
|
final _title = 'ente';
|
2020-04-05 14:01:01 +05:30
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-04-27 18:32:29 +05:30
|
|
|
WidgetsBinding.instance.addObserver(this);
|
|
|
|
|
2020-04-14 21:06:18 +05:30
|
|
|
return MaterialApp(
|
|
|
|
title: _title,
|
2020-08-25 11:30:19 +05:30
|
|
|
theme: ThemeData.dark().copyWith(
|
|
|
|
hintColor: Colors.grey,
|
|
|
|
accentColor: Colors.pink[400],
|
|
|
|
buttonColor: Colors.pink,
|
2020-09-18 00:33:21 +05:30
|
|
|
toggleableActiveColor: Colors.pink[400],
|
2020-08-25 11:30:19 +05:30
|
|
|
),
|
2020-05-05 01:33:06 +05:30
|
|
|
home: HomeWidget(_title),
|
2020-04-05 14:01:01 +05:30
|
|
|
);
|
|
|
|
}
|
2020-04-27 18:32:29 +05:30
|
|
|
|
|
|
|
@override
|
|
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
|
|
if (state == AppLifecycleState.resumed) {
|
2020-06-16 00:08:08 +05:30
|
|
|
_sync();
|
2020-04-27 18:32:29 +05:30
|
|
|
}
|
|
|
|
}
|
2020-04-05 14:01:01 +05:30
|
|
|
}
|