PWA Fundvelo der Caritas.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PermissionsProvider.cs 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Microsoft.JSInterop;
  2. using System;
  3. using System.Threading.Tasks;
  4. namespace cwebplusApp.Shared.Services {
  5. public class PermissionsProvider {
  6. private bool _isGeoLocationAllowed;
  7. public delegate void GeoLocationPermissionChangeCallBack();
  8. private GeoLocationPermissionChangeCallBack _geoLocationPermissionChangeCallBack;
  9. public IJSRuntime JSRuntime { get; set; }
  10. public bool IsGeoLocationAllowed {
  11. get { return _isGeoLocationAllowed; }
  12. set { _isGeoLocationAllowed = value; }
  13. }
  14. public PermissionsProvider(IJSRuntime _jSRuntime) {
  15. this.JSRuntime = _jSRuntime;
  16. }
  17. [JSInvokable]
  18. public void GeoLocationPermissionChanged(string geoLocationStatus) {
  19. IsGeoLocationAllowed = (geoLocationStatus.Equals("granted") || geoLocationStatus.Equals("prompt")) ? true : false;
  20. _geoLocationPermissionChangeCallBack();
  21. }
  22. public void SetGeoLocationPermissionChangeCallBack(GeoLocationPermissionChangeCallBack callback) {
  23. _geoLocationPermissionChangeCallBack = callback;
  24. }
  25. public void RemoveOnlineStatusChangeCallBack() {
  26. _geoLocationPermissionChangeCallBack = null;
  27. }
  28. public async Task<bool> GeoLocationAllowed() {
  29. var dotNetObjRef = DotNetObjectReference.Create(this);
  30. string result = await JSRuntime.InvokeAsync<string>("IsGeoLocationAllowed", dotNetObjRef);
  31. this.IsGeoLocationAllowed = result.Equals("granted") || result.Equals("prompt");
  32. return IsGeoLocationAllowed;
  33. }
  34. }
  35. }