mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-25 23:14:18 +03:00
Update Android parts.
This commit is contained in:
parent
beb8ebfc4d
commit
44547b44be
@ -22,15 +22,17 @@ class CancelException implements Exception {}
|
||||
final oathApiProvider = StateProvider((_) => OathApi());
|
||||
|
||||
final androidOathStateProvider = StateNotifierProvider.autoDispose
|
||||
.family<OathStateNotifier, OathState?, DevicePath>((ref, devicePath) =>
|
||||
_AndroidOathStateNotifier(
|
||||
.family<OathStateNotifier, ApplicationStateResult<OathState>, DevicePath>(
|
||||
(ref, devicePath) => _AndroidOathStateNotifier(
|
||||
ref.watch(androidStateProvider), ref.watch(oathApiProvider)));
|
||||
|
||||
class _AndroidOathStateNotifier extends OathStateNotifier {
|
||||
final OathApi _api;
|
||||
|
||||
_AndroidOathStateNotifier(OathState? newState, this._api) : super() {
|
||||
state = newState;
|
||||
if (newState != null) {
|
||||
setState(newState);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@ -48,9 +50,9 @@ class _AndroidOathStateNotifier extends OathStateNotifier {
|
||||
try {
|
||||
final unlockSuccess = await _api.unlock(password, remember);
|
||||
|
||||
if (mounted && unlockSuccess) {
|
||||
if (unlockSuccess) {
|
||||
_log.config('applet unlocked');
|
||||
state = state?.copyWith(locked: false);
|
||||
setState(requireState().copyWith(locked: false));
|
||||
}
|
||||
return Pair(unlockSuccess, false); // TODO: provide correct second param
|
||||
} on PlatformException catch (e) {
|
||||
@ -101,7 +103,8 @@ final androidCredentialListProvider = StateNotifierProvider.autoDispose
|
||||
var notifier = _AndroidCredentialListNotifier(
|
||||
ref.watch(oathApiProvider),
|
||||
ref.watch(androidCredentialsProvider),
|
||||
ref.watch(oathStateProvider(devicePath).select((s) => s?.locked ?? true)),
|
||||
ref.watch(oathStateProvider(devicePath).select(
|
||||
(r) => r.whenOrNull(success: (state) => state.locked) ?? true)),
|
||||
);
|
||||
ref.listen<WindowState>(windowStateProvider, (_, windowState) {
|
||||
notifier._notifyWindowState(windowState);
|
||||
|
@ -11,13 +11,13 @@ final androidSubPageProvider =
|
||||
StateNotifierProvider<SubPageNotifier, SubPage>((ref) {
|
||||
FOathApi.setup(FOathApiImpl(ref));
|
||||
FManagementApi.setup(FManagementApiImpl(ref));
|
||||
return AndroidSubPageNotifier();
|
||||
return _AndroidSubPageNotifier();
|
||||
});
|
||||
|
||||
class AndroidSubPageNotifier extends SubPageNotifier {
|
||||
class _AndroidSubPageNotifier extends SubPageNotifier {
|
||||
final AppApi _api = AppApi();
|
||||
|
||||
AndroidSubPageNotifier() : super(SubPage.oath) {
|
||||
_AndroidSubPageNotifier() : super(SubPage.oath) {
|
||||
_handleSubPage(SubPage.oath);
|
||||
}
|
||||
|
||||
@ -32,13 +32,18 @@ class AndroidSubPageNotifier extends SubPageNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
final androidAttachedDevicesProvider = Provider<List<DeviceNode>>((ref) {
|
||||
final androidAttachedDevicesProvider =
|
||||
StateNotifierProvider<AttachedDevicesNotifier, List<DeviceNode>>((ref) {
|
||||
var currentDeviceData = ref.watch(androidDeviceDataProvider);
|
||||
if (currentDeviceData != null) {
|
||||
return [currentDeviceData.node];
|
||||
return _AndroidAttachedDevicesNotifier([currentDeviceData.node]);
|
||||
}
|
||||
return [];
|
||||
return _AndroidAttachedDevicesNotifier([]);
|
||||
});
|
||||
|
||||
class _AndroidAttachedDevicesNotifier extends AttachedDevicesNotifier {
|
||||
_AndroidAttachedDevicesNotifier(List<DeviceNode> state) : super(state);
|
||||
}
|
||||
|
||||
final androidDeviceDataProvider =
|
||||
Provider<YubiKeyData?>((ref) => ref.watch(androidYubikeyProvider));
|
||||
|
Loading…
Reference in New Issue
Block a user