2022-03-03 18:43:36 +03:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
|
|
|
import '../app/models.dart';
|
|
|
|
import '../app/state.dart';
|
|
|
|
import 'api/flutter_management_api_impl.dart';
|
|
|
|
import 'api/flutter_oath_api_impl.dart';
|
|
|
|
import 'api/impl.dart';
|
|
|
|
import 'command_providers.dart';
|
|
|
|
|
2022-03-04 19:01:55 +03:00
|
|
|
final androidSubPageProvider =
|
2022-03-14 13:48:39 +03:00
|
|
|
StateNotifierProvider<CurrentAppNotifier, Application>((ref) {
|
2022-03-04 19:01:55 +03:00
|
|
|
FOathApi.setup(FOathApiImpl(ref));
|
|
|
|
FManagementApi.setup(FManagementApiImpl(ref));
|
2022-03-14 13:48:39 +03:00
|
|
|
return _AndroidSubPageNotifier(ref.watch(supportedAppsProvider));
|
2022-03-04 19:01:55 +03:00
|
|
|
});
|
2022-03-03 18:43:36 +03:00
|
|
|
|
2022-03-14 13:48:39 +03:00
|
|
|
class _AndroidSubPageNotifier extends CurrentAppNotifier {
|
2022-03-03 18:43:36 +03:00
|
|
|
final AppApi _api = AppApi();
|
|
|
|
|
2022-03-14 13:48:39 +03:00
|
|
|
_AndroidSubPageNotifier(List<Application> supportedApps)
|
|
|
|
: super(supportedApps) {
|
|
|
|
_handleSubPage(state);
|
2022-03-03 18:43:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-03-14 13:48:39 +03:00
|
|
|
void setCurrentApp(Application app) {
|
|
|
|
super.setCurrentApp(app);
|
|
|
|
_handleSubPage(app);
|
2022-03-03 18:43:36 +03:00
|
|
|
}
|
|
|
|
|
2022-03-14 13:48:39 +03:00
|
|
|
void _handleSubPage(Application subPage) async {
|
2022-03-03 18:43:36 +03:00
|
|
|
await _api.setContext(subPage.index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-11 15:53:28 +03:00
|
|
|
final androidAttachedDevicesProvider =
|
|
|
|
StateNotifierProvider<AttachedDevicesNotifier, List<DeviceNode>>((ref) {
|
2022-03-03 18:43:36 +03:00
|
|
|
var currentDeviceData = ref.watch(androidDeviceDataProvider);
|
|
|
|
if (currentDeviceData != null) {
|
2022-03-11 15:53:28 +03:00
|
|
|
return _AndroidAttachedDevicesNotifier([currentDeviceData.node]);
|
2022-03-03 18:43:36 +03:00
|
|
|
}
|
2022-03-11 15:53:28 +03:00
|
|
|
return _AndroidAttachedDevicesNotifier([]);
|
2022-03-03 18:43:36 +03:00
|
|
|
});
|
|
|
|
|
2022-03-11 15:53:28 +03:00
|
|
|
class _AndroidAttachedDevicesNotifier extends AttachedDevicesNotifier {
|
|
|
|
_AndroidAttachedDevicesNotifier(List<DeviceNode> state) : super(state);
|
|
|
|
}
|
|
|
|
|
2022-03-03 18:43:36 +03:00
|
|
|
final androidDeviceDataProvider =
|
2022-03-03 19:24:26 +03:00
|
|
|
Provider<YubiKeyData?>((ref) => ref.watch(androidYubikeyProvider));
|