Build Android (FCM) / build-android-fcm (push) Canceled after 0s
Build Android / build-android (push) Canceled after 0s
Build iOS / build-ios (push) Canceled after 0s
Build Linux / build-linux (push) Canceled after 0s
Build macOS / build-macos (push) Canceled after 0s
Build Windows / build-windows (push) Canceled after 0s
Release (main) / android (oneme) (push) Canceled after 0s
Release (main) / android (qlyra) (push) Canceled after 0s
Release (main) / windows (push) Canceled after 0s
Release (main) / linux (push) Canceled after 0s
Release (main) / macos (push) Canceled after 0s
Release (main) / ios (push) Canceled after 0s
Release (main) / release (push) Canceled after 0s
68 lines
2.1 KiB
Dart
68 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
|
import '../../core/config/app_shape.dart';
|
|
import '../screens/webapp/web_app_security_policy.dart';
|
|
|
|
String _resourceLabel(PermissionResourceType type) {
|
|
if (type == PermissionResourceType.CAMERA) return 'камера';
|
|
if (type == PermissionResourceType.MICROPHONE) return 'микрофон';
|
|
if (type == PermissionResourceType.CAMERA_AND_MICROPHONE) {
|
|
return 'камера и микрофон';
|
|
}
|
|
if (type == PermissionResourceType.GEOLOCATION) return 'геолокация';
|
|
return 'дополнительный доступ';
|
|
}
|
|
|
|
Future<PermissionResponse> askWebViewPermission(
|
|
BuildContext context,
|
|
PermissionRequest request, {
|
|
required WebAppSecurityPolicy policy,
|
|
required Uri? currentUrl,
|
|
}) async {
|
|
PermissionResponse deny() => PermissionResponse(
|
|
resources: request.resources,
|
|
action: PermissionResponseAction.DENY,
|
|
);
|
|
|
|
if (!context.mounted ||
|
|
!policy.allowsPermission(
|
|
Uri.parse(request.origin.toString()),
|
|
currentUrl,
|
|
)) {
|
|
return deny();
|
|
}
|
|
|
|
final labels = <String>{
|
|
for (final r in request.resources) _resourceLabel(r),
|
|
}.join(', ');
|
|
final host = request.origin.host.isNotEmpty
|
|
? request.origin.host
|
|
: 'Веб-страница';
|
|
|
|
final granted = await showDialog<bool>(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
shape: AppShape.dialogBorder,
|
|
title: const Text('Запрос доступа'),
|
|
content: Text('$host запрашивает доступ к: $labels.'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(ctx).pop(false),
|
|
child: const Text('Запретить'),
|
|
),
|
|
FilledButton(
|
|
onPressed: () => Navigator.of(ctx).pop(true),
|
|
child: const Text('Разрешить'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
return PermissionResponse(
|
|
resources: request.resources,
|
|
action: granted == true
|
|
? PermissionResponseAction.GRANT
|
|
: PermissionResponseAction.DENY,
|
|
);
|
|
}
|