2022-08-16 15:05:53 +03:00
|
|
|
import 'package:flutter/services.dart';
|
2022-03-03 18:43:36 +03:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
|
|
|
import '../app/models.dart';
|
|
|
|
import '../app/state.dart';
|
2022-08-16 15:05:53 +03:00
|
|
|
import 'devices.dart';
|
|
|
|
|
2022-08-19 10:36:45 +03:00
|
|
|
const _contextChannel = MethodChannel('android.state.appContext');
|
2022-09-08 13:17:44 +03:00
|
|
|
const _methodsChannel = MethodChannel('app.methods');
|
|
|
|
|
|
|
|
final androidAllowScreenshotsProvider =
|
|
|
|
StateNotifierProvider<AllowScreenshotsNotifier, bool>(
|
|
|
|
(ref) => AllowScreenshotsNotifier(),
|
|
|
|
);
|
|
|
|
|
|
|
|
class AllowScreenshotsNotifier extends StateNotifier<bool> {
|
|
|
|
AllowScreenshotsNotifier() : super(false);
|
|
|
|
|
|
|
|
void setAllowScreenshots(bool value) async {
|
2022-09-08 14:15:38 +03:00
|
|
|
final result =
|
|
|
|
await _methodsChannel.invokeMethod('allowScreenshots', value);
|
|
|
|
if (mounted) {
|
|
|
|
state = result;
|
|
|
|
}
|
2022-09-08 13:17:44 +03:00
|
|
|
}
|
|
|
|
}
|
2022-03-03 18:43:36 +03:00
|
|
|
|
2022-03-04 19:01:55 +03:00
|
|
|
final androidSubPageProvider =
|
2022-03-14 13:48:39 +03:00
|
|
|
StateNotifierProvider<CurrentAppNotifier, Application>((ref) {
|
|
|
|
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-05-12 10:56:55 +03:00
|
|
|
_AndroidSubPageNotifier(super.supportedApps) {
|
2022-03-14 13:48:39 +03:00
|
|
|
_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-08-16 15:05:53 +03:00
|
|
|
await _contextChannel.invokeMethod('setContext', {'index': subPage.index});
|
2022-03-03 18:43:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2022-06-28 20:51:58 +03:00
|
|
|
List<DeviceNode> devs = currentDeviceData.maybeWhen(
|
|
|
|
data: (data) => [data.node], orElse: () => []);
|
|
|
|
return _AndroidAttachedDevicesNotifier(devs);
|
2022-03-03 18:43:36 +03:00
|
|
|
});
|
|
|
|
|
2022-03-11 15:53:28 +03:00
|
|
|
class _AndroidAttachedDevicesNotifier extends AttachedDevicesNotifier {
|
2022-05-12 10:56:55 +03:00
|
|
|
_AndroidAttachedDevicesNotifier(super.state);
|
2022-03-11 15:53:28 +03:00
|
|
|
}
|
|
|
|
|
2022-06-28 20:51:58 +03:00
|
|
|
final androidDeviceDataProvider = Provider<AsyncValue<YubiKeyData>>(
|
|
|
|
(ref) => ref.watch(androidYubikeyProvider));
|
2022-03-21 11:34:45 +03:00
|
|
|
|
|
|
|
final androidCurrentDeviceProvider =
|
|
|
|
StateNotifierProvider<CurrentDeviceNotifier, DeviceNode?>((ref) {
|
2022-08-19 10:36:45 +03:00
|
|
|
final provider =
|
|
|
|
_AndroidCurrentDeviceNotifier(ref.watch(androidYubikeyProvider));
|
2022-03-21 11:34:45 +03:00
|
|
|
return provider;
|
|
|
|
});
|
|
|
|
|
|
|
|
class _AndroidCurrentDeviceNotifier extends CurrentDeviceNotifier {
|
2022-08-19 10:36:45 +03:00
|
|
|
_AndroidCurrentDeviceNotifier(AsyncValue<YubiKeyData> device)
|
|
|
|
: super(device.whenOrNull(data: (data) => data.node));
|
2022-03-21 11:34:45 +03:00
|
|
|
|
|
|
|
@override
|
2022-06-07 16:13:11 +03:00
|
|
|
setCurrentDevice(DeviceNode? device) {
|
2022-03-21 11:34:45 +03:00
|
|
|
state = device;
|
|
|
|
}
|
|
|
|
}
|