90 lines
3.3 KiB
Dart
90 lines
3.3 KiB
Dart
import 'package:adaptive_theme/adaptive_theme.dart';
|
|
import 'package:computer/computer.dart';
|
|
import "package:ente_auth/app/view/app.dart";
|
|
import 'package:ente_auth/core/configuration.dart';
|
|
import 'package:ente_auth/core/constants.dart';
|
|
import 'package:ente_auth/core/logging/super_logging.dart';
|
|
import 'package:ente_auth/core/network.dart';
|
|
import 'package:ente_auth/ente_theme_data.dart';
|
|
import 'package:ente_auth/locale.dart';
|
|
import 'package:ente_auth/services/authenticator_service.dart';
|
|
import 'package:ente_auth/services/billing_service.dart';
|
|
import 'package:ente_auth/services/notification_service.dart';
|
|
import 'package:ente_auth/services/preference_service.dart';
|
|
import 'package:ente_auth/services/update_service.dart';
|
|
import 'package:ente_auth/services/user_remote_flag_service.dart';
|
|
import 'package:ente_auth/services/user_service.dart';
|
|
import 'package:ente_auth/store/code_store.dart';
|
|
import 'package:ente_auth/ui/tools/app_lock.dart';
|
|
import 'package:ente_auth/ui/tools/lock_screen.dart';
|
|
import 'package:ente_auth/ui/utils/icon_utils.dart';
|
|
import 'package:ente_auth/utils/crypto_util.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import "package:flutter/material.dart";
|
|
import 'package:logging/logging.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
final _logger = Logger("main");
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
final savedThemeMode = await AdaptiveTheme.getThemeMode();
|
|
await _runInForeground(savedThemeMode);
|
|
}
|
|
|
|
Future<void> _runInForeground(AdaptiveThemeMode? savedThemeMode) async {
|
|
return await _runWithLogs(() async {
|
|
_logger.info("Starting app in foreground");
|
|
await _init(false, via: 'mainMethod');
|
|
final Locale locale = await getLocale();
|
|
UpdateService.instance.showUpdateNotification();
|
|
runApp(
|
|
AppLock(
|
|
builder: (args) => App(locale: locale),
|
|
lockScreen: const LockScreen(),
|
|
enabled: Configuration.instance.shouldShowLockScreen(),
|
|
locale: locale,
|
|
lightTheme: lightThemeData,
|
|
darkTheme: darkThemeData,
|
|
savedThemeMode: _themeMode(savedThemeMode),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
ThemeMode _themeMode(AdaptiveThemeMode? savedThemeMode) {
|
|
if (savedThemeMode == null) return ThemeMode.system;
|
|
if (savedThemeMode.isLight) return ThemeMode.light;
|
|
if (savedThemeMode.isDark) return ThemeMode.dark;
|
|
return ThemeMode.system;
|
|
}
|
|
|
|
Future _runWithLogs(Function() function, {String prefix = ""}) async {
|
|
await SuperLogging.main(
|
|
LogConfig(
|
|
body: function,
|
|
logDirPath: (await getApplicationSupportDirectory()).path + "/logs",
|
|
maxLogFiles: 5,
|
|
sentryDsn: sentryDSN,
|
|
enableInDebugMode: true,
|
|
prefix: prefix,
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _init(bool bool, {String? via}) async {
|
|
// Start workers asynchronously. No need to wait for them to start
|
|
Computer.shared().turnOn(workersCount: 4, verbose: kDebugMode);
|
|
CryptoUtil.init();
|
|
await PreferenceService.instance.init();
|
|
await CodeStore.instance.init();
|
|
await Configuration.instance.init();
|
|
await Network.instance.init();
|
|
await UserService.instance.init();
|
|
await UserRemoteFlagService.instance.init();
|
|
await AuthenticatorService.instance.init();
|
|
await BillingService.instance.init();
|
|
await NotificationService.instance.init();
|
|
await UpdateService.instance.init();
|
|
await IconUtils.instance.init();
|
|
}
|