2022-03-03 18:43:36 +03:00
|
|
|
import 'dart:async';
|
|
|
|
|
2022-05-11 15:02:31 +03:00
|
|
|
import 'package:flutter/foundation.dart';
|
2022-03-03 18:43:36 +03:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:logging/logging.dart';
|
2022-03-25 10:36:29 +03:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2022-04-13 16:26:32 +03:00
|
|
|
import 'package:yubico_authenticator/android/logger.dart';
|
2022-05-11 15:53:41 +03:00
|
|
|
import 'package:yubico_authenticator/android/window_state_provider.dart';
|
2022-05-09 09:32:44 +03:00
|
|
|
import 'package:yubico_authenticator/app/logging.dart';
|
2022-03-03 18:43:36 +03:00
|
|
|
|
2022-03-25 10:36:29 +03:00
|
|
|
import '../app/app.dart';
|
2022-03-14 13:48:39 +03:00
|
|
|
import '../app/models.dart';
|
2022-04-05 12:10:37 +03:00
|
|
|
import '../app/state.dart';
|
2022-03-25 10:36:29 +03:00
|
|
|
import '../app/views/main_page.dart';
|
|
|
|
import '../core/state.dart';
|
2022-03-16 12:37:52 +03:00
|
|
|
import '../management/state.dart';
|
2022-03-28 11:58:09 +03:00
|
|
|
import '../oath/state.dart';
|
2022-04-28 14:12:32 +03:00
|
|
|
import 'api/impl.dart';
|
2022-03-16 12:37:52 +03:00
|
|
|
import 'management/state.dart';
|
2022-03-03 19:24:26 +03:00
|
|
|
import 'oath/state.dart';
|
2022-03-28 11:58:09 +03:00
|
|
|
import 'qr_scanner/qr_scanner_provider.dart';
|
|
|
|
import 'state.dart';
|
2022-04-05 12:10:37 +03:00
|
|
|
import 'views/tap_request_dialog.dart';
|
2022-03-03 18:43:36 +03:00
|
|
|
|
2022-05-09 09:32:44 +03:00
|
|
|
final androidLogger = AndroidLogger();
|
2022-03-03 18:43:36 +03:00
|
|
|
|
2022-03-25 10:36:29 +03:00
|
|
|
Future<Widget> initialize() async {
|
2022-05-11 15:02:31 +03:00
|
|
|
if (kDebugMode) {
|
|
|
|
Logger.root.level = Levels.DEBUG;
|
|
|
|
}
|
|
|
|
|
2022-03-25 10:36:29 +03:00
|
|
|
return ProviderScope(
|
|
|
|
overrides: [
|
|
|
|
supportedAppsProvider.overrideWithValue([
|
|
|
|
Application.oath,
|
|
|
|
]),
|
|
|
|
prefProvider.overrideWithValue(await SharedPreferences.getInstance()),
|
|
|
|
attachedDevicesProvider
|
|
|
|
.overrideWithProvider(androidAttachedDevicesProvider),
|
|
|
|
currentDeviceDataProvider.overrideWithProvider(androidDeviceDataProvider),
|
|
|
|
oathStateProvider.overrideWithProvider(androidOathStateProvider),
|
|
|
|
credentialListProvider
|
|
|
|
.overrideWithProvider(androidCredentialListProvider),
|
|
|
|
currentAppProvider.overrideWithProvider(androidSubPageProvider),
|
|
|
|
managementStateProvider.overrideWithProvider(androidManagementState),
|
2022-03-28 11:58:09 +03:00
|
|
|
currentDeviceProvider.overrideWithProvider(androidCurrentDeviceProvider),
|
2022-05-11 15:53:41 +03:00
|
|
|
qrScannerProvider.overrideWithProvider(androidQrScannerProvider),
|
|
|
|
windowStateProvider.overrideWithProvider(androidWindowStateProvider)
|
2022-03-25 10:36:29 +03:00
|
|
|
],
|
2022-04-05 12:10:37 +03:00
|
|
|
child: YubicoAuthenticatorApp(page: Consumer(
|
|
|
|
builder: (context, ref, child) {
|
|
|
|
// activates the sub page provider
|
2022-04-05 17:11:01 +03:00
|
|
|
ref.read(androidSubPageProvider);
|
2022-04-28 14:12:32 +03:00
|
|
|
|
2022-05-11 15:53:41 +03:00
|
|
|
// activates window state provider
|
|
|
|
ref.read(androidWindowStateProvider);
|
|
|
|
|
2022-05-09 09:32:44 +03:00
|
|
|
ref.listen(logLevelProvider, (oldLevel, newLevel) {
|
|
|
|
if (oldLevel != newLevel && newLevel is Level) {
|
|
|
|
androidLogger.setLogLevel(newLevel);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-05-11 15:02:31 +03:00
|
|
|
androidLogger.setLogLevel(Logger.root.level);
|
|
|
|
|
2022-04-28 14:12:32 +03:00
|
|
|
/// initializes global handler for dialogs
|
2022-04-28 16:23:04 +03:00
|
|
|
FDialogApi.setup(FDialogApiImpl(ref.watch(withContextProvider)));
|
2022-04-05 12:10:37 +03:00
|
|
|
return const MainPage();
|
|
|
|
},
|
|
|
|
)),
|
2022-03-25 10:36:29 +03:00
|
|
|
);
|
2022-03-03 18:43:36 +03:00
|
|
|
}
|