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
|
|
|
|
2021-11-23 15:02:05 +03:00
|
|
|
import 'package:flutter/material.dart';
|
2021-11-19 15:02:25 +03:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2021-11-23 15:02:05 +03:00
|
|
|
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;
|
2021-12-02 13:44:17 +03:00
|
|
|
import 'app/app.dart';
|
2023-10-20 12:15:10 +03:00
|
|
|
import 'app/state.dart';
|
2021-11-19 15:02:25 +03:00
|
|
|
import 'core/state.dart';
|
2022-01-27 14:34:29 +03:00
|
|
|
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
|
|
|
|
2022-02-21 11:38:09 +03:00
|
|
|
final _log = Logger('main');
|
2021-11-23 15:02:05 +03:00
|
|
|
|
2022-04-29 15:41:40 +03:00
|
|
|
void main(List<String> argv) async {
|
2021-11-19 15:02:25 +03:00
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
try {
|
2022-03-25 10:36:29 +03:00
|
|
|
final Widget initializedApp;
|
2022-01-27 14:34:29 +03:00
|
|
|
if (isDesktop) {
|
2022-04-29 15:41:40 +03:00
|
|
|
initializedApp = await desktop.initialize(argv);
|
2022-03-03 19:24:26 +03:00
|
|
|
} else if (isAndroid) {
|
2022-03-25 10:36:29 +03:00
|
|
|
initializedApp = await android.initialize();
|
|
|
|
} else {
|
|
|
|
_initializeDebugLogging();
|
|
|
|
throw UnimplementedError('Platform not supported');
|
2022-01-27 14:34:29 +03:00
|
|
|
}
|
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,
|
|
|
|
});
|
2022-04-29 14:13:42 +03:00
|
|
|
runApp(initializedApp);
|
2021-11-19 15:02:25 +03:00
|
|
|
} catch (e) {
|
2022-02-21 11:38:09 +03:00
|
|
|
_log.warning('Platform initialization failed: $e');
|
2022-03-25 10:36:29 +03:00
|
|
|
runApp(
|
|
|
|
ProviderScope(
|
|
|
|
overrides: [
|
2023-10-20 12:15:10 +03:00
|
|
|
prefProvider.overrideWithValue(await SharedPreferences.getInstance()),
|
|
|
|
supportedThemesProvider.overrideWith((ref) => ThemeMode.values),
|
2022-03-25 10:36:29 +03:00
|
|
|
],
|
2022-05-12 09:34:51 +03:00
|
|
|
child: YubicoAuthenticatorApp(page: ErrorPage(error: e.toString())),
|
2022-03-25 10:36:29 +03:00
|
|
|
),
|
|
|
|
);
|
2021-11-19 15:02:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-21 11:38:09 +03:00
|
|
|
void _initializeDebugLogging() {
|
2021-11-23 15:02:05 +03:00
|
|
|
Logger.root.onRecord.listen((record) {
|
|
|
|
developer.log(
|
2021-11-24 13:36:59 +03:00
|
|
|
'${record.level}: ${record.message}',
|
2021-11-23 15:02:05 +03:00
|
|
|
error: record.error,
|
|
|
|
name: record.loggerName,
|
|
|
|
time: record.time,
|
|
|
|
level: record.level.value,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|