| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using Microsoft.JSInterop;
- using System;
- using System.Threading.Tasks;
-
- namespace cwebplusApp.Shared.Services {
-
- public class PermissionsProvider {
-
- private bool _isGeoLocationAllowed;
-
- public delegate void GeoLocationPermissionChangeCallBack(bool allowed);
- private GeoLocationPermissionChangeCallBack _geoLocationPermissionChangeCallBack;
-
- public IJSRuntime JSRuntime { get; set; }
-
- public bool IsGeoLocationAllowed {
- get {
- Console.WriteLine("IsGeoLocationAllowed.Get {0}", _isGeoLocationAllowed);
- return _isGeoLocationAllowed;
- }
- set {
- Console.WriteLine("IsGeoLocationAllowed.Set {0}", value);
- _isGeoLocationAllowed = value;
- }
- }
-
- public PermissionsProvider(IJSRuntime _jSRuntime) {
- this.JSRuntime = _jSRuntime;
- initialize();
- }
-
- [JSInvokable]
- public void GeoLocationPermissionChanged(string geoLocationStatus) {
- IsGeoLocationAllowed = (geoLocationStatus.Equals("granted") || geoLocationStatus.Equals("prompt")) ? true : false;
- this._geoLocationPermissionChangeCallBack(IsGeoLocationAllowed);
- }
-
- public void SetGeoLocationPermissionChangeCallBack(GeoLocationPermissionChangeCallBack callback) {
- this._geoLocationPermissionChangeCallBack = callback;
- }
-
- public void RemoveOnlineStatusChangeCallBack() {
- this._geoLocationPermissionChangeCallBack = null;
- }
-
-
- private async void initialize() {
- Console.WriteLine("PermissionsProvider.initialize");
- await GeoLocationAllowed();
- }
-
- private async Task<bool> GeoLocationAllowed() {
- Console.WriteLine("PermissionsProvider.GeoLocationAllowed");
- var dotNetObjRef = DotNetObjectReference.Create(this);
- string result = await JSRuntime.InvokeAsync<string>("IsGeoLocationAllowed", dotNetObjRef);
- this.IsGeoLocationAllowed = result.Equals("granted") || result.Equals("prompt");
- Console.WriteLine("PermissionsProvider.GeoLocationAllowed result={0}", result);
- return IsGeoLocationAllowed;
- }
-
- }
- }
|