yubioath-flutter/lib/main.dart

80 lines
2.3 KiB
Dart
Raw Normal View History

2022-10-04 13:12:54 +03:00
/*
* Copyright (C) 2022 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2021-11-19 15:02:25 +03:00
import 'dart:developer' as developer;
2024-08-14 14:40:14 +03:00
import 'dart:io';
2021-11-19 15:02:25 +03:00
import 'package:flutter/material.dart';
2021-11-19 15:02:25 +03:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';
2022-03-03 19:24:26 +03:00
import 'package:shared_preferences/shared_preferences.dart';
2021-11-19 15:02:25 +03:00
2022-03-03 19:24:26 +03:00
import 'android/init.dart' as android;
import 'app/app.dart';
import 'app/state.dart';
2021-11-19 15:02:25 +03:00
import 'core/state.dart';
import 'desktop/init.dart' as desktop;
2021-11-19 17:05:57 +03:00
import 'error_page.dart';
2024-08-14 14:40:14 +03:00
import 'version.dart';
2021-11-19 17:05:57 +03:00
final _log = Logger('main');
void main(List<String> argv) async {
2021-11-19 15:02:25 +03:00
WidgetsFlutterBinding.ensureInitialized();
try {
final Widget initializedApp;
if (isDesktop) {
initializedApp = await desktop.initialize(argv);
2022-03-03 19:24:26 +03:00
} else if (isAndroid) {
initializedApp = await android.initialize();
} else {
_initializeDebugLogging();
throw UnimplementedError('Platform not supported');
}
2024-08-14 14:40:14 +03:00
_log.info('Running Yubico Authenticator...', {
'app_version': version,
'dart': Platform.version,
'os': Platform.operatingSystem,
'os_version': Platform.operatingSystemVersion,
});
runApp(initializedApp);
2021-11-19 15:02:25 +03:00
} catch (e) {
_log.warning('Platform initialization failed: $e');
runApp(
ProviderScope(
overrides: [
prefProvider.overrideWithValue(await SharedPreferences.getInstance()),
supportedThemesProvider.overrideWith((ref) => ThemeMode.values),
],
2022-05-12 09:34:51 +03:00
child: YubicoAuthenticatorApp(page: ErrorPage(error: e.toString())),
),
);
2021-11-19 15:02:25 +03:00
}
}
void _initializeDebugLogging() {
Logger.root.onRecord.listen((record) {
developer.log(
2021-11-24 13:36:59 +03:00
'${record.level}: ${record.message}',
error: record.error,
name: record.loggerName,
time: record.time,
level: record.level.value,
);
});
}