2022-01-27 14:34:29 +03:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:ui';
|
|
|
|
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
import 'package:window_manager/window_manager.dart';
|
|
|
|
|
2022-02-22 13:15:15 +03:00
|
|
|
import '../oath/state.dart';
|
2022-01-27 14:34:29 +03:00
|
|
|
import '../app/state.dart';
|
2022-02-22 13:15:15 +03:00
|
|
|
import 'oath/state.dart';
|
2022-01-27 14:34:29 +03:00
|
|
|
import 'rpc.dart';
|
2022-02-22 13:15:15 +03:00
|
|
|
import 'devices.dart';
|
|
|
|
import 'qr_scanner.dart';
|
|
|
|
import 'state.dart';
|
2022-01-27 14:34:29 +03:00
|
|
|
|
2022-02-21 11:38:09 +03:00
|
|
|
final _log = Logger('desktop.init');
|
|
|
|
|
|
|
|
initializeLogging() {
|
|
|
|
Logger.root.onRecord.listen((record) {
|
|
|
|
stderr.writeln('[${record.loggerName}] ${record.level}: ${record.message}');
|
|
|
|
if (record.error != null) {
|
|
|
|
stderr.writeln(record.error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
_log.info('Logging initialized, outputting to stderr');
|
|
|
|
}
|
2022-01-27 14:34:29 +03:00
|
|
|
|
|
|
|
Future<List<Override>> initializeAndGetOverrides() async {
|
|
|
|
await windowManager.ensureInitialized();
|
|
|
|
|
|
|
|
// Linux doesn't currently support hiding the window at start currently.
|
|
|
|
// For now, this size should match linux/flutter/my_application.cc to avoid window flicker at startup.
|
|
|
|
unawaited(windowManager.waitUntilReadyToShow().then((_) async {
|
|
|
|
await windowManager.setSize(const Size(400, 720));
|
|
|
|
await windowManager.show();
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Either use the _YKMAN_EXE environment variable, or look relative to executable.
|
|
|
|
var exe = Platform.environment['_YKMAN_PATH'];
|
|
|
|
if (exe?.isEmpty ?? true) {
|
2022-02-10 15:47:58 +03:00
|
|
|
var relativePath = 'ykman-rpc/ykman-rpc';
|
2022-01-27 14:34:29 +03:00
|
|
|
if (Platform.isMacOS) {
|
|
|
|
relativePath = '../Resources/' + relativePath;
|
|
|
|
} else if (Platform.isWindows) {
|
|
|
|
relativePath += '.exe';
|
|
|
|
}
|
|
|
|
exe = Uri.file(Platform.resolvedExecutable)
|
|
|
|
.resolve(relativePath)
|
|
|
|
.toFilePath();
|
|
|
|
}
|
|
|
|
|
2022-02-21 11:38:09 +03:00
|
|
|
_log.info('Starting subprocess: $exe');
|
2022-01-27 14:34:29 +03:00
|
|
|
var rpc = await RpcSession.launch(exe!);
|
2022-02-21 11:38:09 +03:00
|
|
|
_log.info('ykman-rpc process started', exe);
|
2022-01-27 14:34:29 +03:00
|
|
|
rpc.setLogLevel(Logger.root.level);
|
|
|
|
|
|
|
|
return [
|
|
|
|
rpcProvider.overrideWithValue(rpc),
|
|
|
|
windowStateProvider.overrideWithProvider(desktopWindowStateProvider),
|
|
|
|
attachedDevicesProvider.overrideWithProvider(desktopDevicesProvider),
|
|
|
|
currentDeviceDataProvider.overrideWithProvider(desktopDeviceDataProvider),
|
|
|
|
oathStateProvider.overrideWithProvider(desktopOathState),
|
|
|
|
credentialListProvider
|
|
|
|
.overrideWithProvider(desktopOathCredentialListProvider),
|
2022-02-10 17:24:28 +03:00
|
|
|
qrScannerProvider.overrideWithProvider(desktopQrScannerProvider),
|
2022-01-27 14:34:29 +03:00
|
|
|
];
|
|
|
|
}
|