2021-09-23 19:25:03 +02:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2021-10-31 12:52:58 +01:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2021-11-16 17:06:07 +01:00
|
|
|
import 'package:timeago/timeago.dart';
|
2021-09-23 19:25:03 +02:00
|
|
|
|
|
|
|
import 'app.dart';
|
|
|
|
import 'app_config.dart';
|
2021-11-16 17:06:07 +01:00
|
|
|
import 'l10n/timeago/pl.dart';
|
2021-11-12 17:01:17 +01:00
|
|
|
import 'pages/log_console/log_console_page_store.dart';
|
2021-09-23 19:25:03 +02:00
|
|
|
import 'stores/accounts_store.dart';
|
|
|
|
import 'stores/config_store.dart';
|
|
|
|
|
|
|
|
Future<void> mainCommon(AppConfig appConfig) async {
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
final logConsoleStore = LogConsolePageStore();
|
2021-10-31 12:52:58 +01:00
|
|
|
final sharedPrefs = await SharedPreferences.getInstance();
|
2021-09-23 19:25:03 +02:00
|
|
|
|
|
|
|
_setupLogger(appConfig, logConsoleStore);
|
2021-11-16 17:06:07 +01:00
|
|
|
_setupTimeago();
|
2021-09-23 19:25:03 +02:00
|
|
|
|
2021-10-31 12:52:58 +01:00
|
|
|
final configStore = ConfigStore.load(sharedPrefs);
|
2021-09-23 19:25:03 +02:00
|
|
|
final accountsStore = await AccountsStore.load();
|
|
|
|
|
|
|
|
runApp(
|
|
|
|
MultiProvider(
|
|
|
|
providers: [
|
2021-10-31 12:52:58 +01:00
|
|
|
Provider.value(value: configStore),
|
2021-09-23 19:25:03 +02:00
|
|
|
ChangeNotifierProvider.value(value: accountsStore),
|
|
|
|
Provider.value(value: logConsoleStore),
|
|
|
|
],
|
|
|
|
child: const MyApp(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _setupLogger(AppConfig appConfig, LogConsolePageStore logConsoleStore) {
|
|
|
|
Logger.root.level = Level.ALL;
|
|
|
|
|
|
|
|
Logger.root.onRecord.listen((logRecord) {
|
|
|
|
// ignore: avoid_print
|
|
|
|
print(logRecord);
|
|
|
|
logConsoleStore.addLog(logRecord);
|
|
|
|
});
|
|
|
|
|
|
|
|
final flutterErrorLogger = Logger('FlutterError');
|
|
|
|
|
|
|
|
FlutterError.onError = (details) {
|
|
|
|
if (appConfig.debugMode) {
|
|
|
|
FlutterError.dumpErrorToConsole(details);
|
|
|
|
} else {
|
|
|
|
flutterErrorLogger.warning(
|
|
|
|
details.summary.name,
|
|
|
|
details.exception,
|
|
|
|
details.stack,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2021-11-16 17:06:07 +01:00
|
|
|
|
|
|
|
void _setupTimeago() {
|
|
|
|
setLocaleMessages('ar', ArMessages());
|
|
|
|
setLocaleMessages('ar_short', ArShortMessages());
|
|
|
|
setLocaleMessages('az', AzMessages());
|
|
|
|
setLocaleMessages('az_short', AzShortMessages());
|
|
|
|
setLocaleMessages('ca', CaMessages());
|
|
|
|
setLocaleMessages('ca_short', CaShortMessages());
|
|
|
|
setLocaleMessages('cs', CsMessages());
|
|
|
|
setLocaleMessages('cs_short', CsShortMessages());
|
|
|
|
setLocaleMessages('da', DaMessages());
|
|
|
|
setLocaleMessages('da_short', DaShortMessages());
|
|
|
|
setLocaleMessages('de', DeMessages());
|
|
|
|
setLocaleMessages('de_short', DeShortMessages());
|
|
|
|
setLocaleMessages('dv', DvMessages());
|
|
|
|
setLocaleMessages('dv_short', DvShortMessages());
|
|
|
|
setLocaleMessages('en', EnMessages());
|
|
|
|
setLocaleMessages('en_short', EnShortMessages());
|
|
|
|
setLocaleMessages('es', EsMessages());
|
|
|
|
setLocaleMessages('es_short', EsShortMessages());
|
|
|
|
setLocaleMessages('fa', FaMessages());
|
|
|
|
setLocaleMessages('fr', FrMessages());
|
|
|
|
setLocaleMessages('fr_short', FrShortMessages());
|
|
|
|
setLocaleMessages('gr', GrMessages());
|
|
|
|
setLocaleMessages('gr_short', GrShortMessages());
|
|
|
|
setLocaleMessages('he', HeMessages());
|
|
|
|
setLocaleMessages('he_short', HeShortMessages());
|
|
|
|
setLocaleMessages('hi', HiMessages());
|
|
|
|
setLocaleMessages('hi_short', HiShortMessages());
|
|
|
|
setLocaleMessages('id', IdMessages());
|
|
|
|
setLocaleMessages('it', ItMessages());
|
|
|
|
setLocaleMessages('it_short', ItShortMessages());
|
|
|
|
setLocaleMessages('ja', JaMessages());
|
|
|
|
setLocaleMessages('km', KmMessages());
|
|
|
|
setLocaleMessages('km_short', KmShortMessages());
|
|
|
|
setLocaleMessages('ko', KoMessages());
|
|
|
|
setLocaleMessages('ku', KuMessages());
|
|
|
|
setLocaleMessages('ku_short', KuShortMessages());
|
|
|
|
setLocaleMessages('mn', MnMessages());
|
|
|
|
setLocaleMessages('mn_short', MnShortMessages());
|
|
|
|
setLocaleMessages('nl', NlMessages());
|
|
|
|
setLocaleMessages('nl_short', NlShortMessages());
|
|
|
|
setLocaleMessages('pl', PlMessages());
|
|
|
|
setLocaleMessages('pl_short', PlShortMessages());
|
|
|
|
setLocaleMessages('ro', RoMessages());
|
|
|
|
setLocaleMessages('ro_short', RoShortMessages());
|
|
|
|
setLocaleMessages('ru', RuMessages());
|
|
|
|
setLocaleMessages('ru_short', RuShortMessages());
|
|
|
|
setLocaleMessages('rw', RwMessages());
|
|
|
|
setLocaleMessages('rw_short', RwShortMessages());
|
|
|
|
setLocaleMessages('sv', SvMessages());
|
|
|
|
setLocaleMessages('sv_short', SvShortMessages());
|
|
|
|
setLocaleMessages('ta', TaMessages());
|
|
|
|
setLocaleMessages('th', ThMessages());
|
|
|
|
setLocaleMessages('th_short', ThShortMessages());
|
|
|
|
setLocaleMessages('tr', TrMessages());
|
|
|
|
setLocaleMessages('uk', UkMessages());
|
|
|
|
setLocaleMessages('uk_short', UkShortMessages());
|
|
|
|
setLocaleMessages('vi', ViMessages());
|
|
|
|
setLocaleMessages('vi_short', ViShortMessages());
|
|
|
|
setLocaleMessages('zh', ZhMessages());
|
|
|
|
setLocaleMessages('ms-MY', MsMyMessages());
|
|
|
|
setLocaleMessages('ms-MY_short', MsMyShortMessages());
|
|
|
|
setLocaleMessages('nb-NO', NbNoMessages());
|
|
|
|
setLocaleMessages('nb-NO_short', NbNoShortMessages());
|
|
|
|
setLocaleMessages('nn-NO', NnNoMessages());
|
|
|
|
setLocaleMessages('nn-NO_short', NnNoShortMessages());
|
|
|
|
setLocaleMessages('pt-BR', PtBrMessages());
|
|
|
|
setLocaleMessages('pt-BR_short', PtBrShortMessages());
|
|
|
|
setLocaleMessages('zh-CN', ZhCnMessages());
|
|
|
|
}
|