Skip to content

Commit 50046d0

Browse files
committed
Update StartupViewModel.cs
1 parent 00120b3 commit 50046d0

File tree

1 file changed

+14
-32
lines changed

1 file changed

+14
-32
lines changed

src/ShinyWonderland/StartupViewModel.cs

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ public partial class StartupViewModel(
77
IGeofenceManager geofenceManager
88
) : ObservableObject, IPageLifecycleAware
99
{
10+
const string GEOFENCE_ID = "ThemePark";
11+
1012
public async void OnAppearing()
1113
{
1214
await services.Notifications.RequestAccess();
1315
await this.TryGps();
14-
await this.TryGeofencing();
1516

1617
await services.Navigator.NavigateTo("//main");
1718
}
@@ -37,43 +38,24 @@ async Task TryGps()
3738
{
3839
var start = await services.IsUserWithinPark();
3940
if (start)
40-
await services.Gps.StartListener(GpsRequest.Realtime(true));
41-
}
42-
}
43-
catch (Exception ex)
44-
{
45-
logger.LogWarning(ex, "Failed to start GPS");
46-
}
47-
}
48-
49-
50-
bool geofenceChecked = false;
51-
const string GEOFENCE_ID = "ThemePark";
52-
async Task TryGeofencing()
53-
{
54-
if (geofenceChecked)
55-
return;
56-
57-
try
58-
{
59-
this.geofenceChecked = true;
60-
var access = await geofenceManager.RequestAccess();
61-
if (access == AccessState.Available)
62-
{
63-
var regions = geofenceManager.GetMonitorRegions();
64-
if (!regions.Any(x => x.Identifier.Equals(GEOFENCE_ID, StringComparison.InvariantCultureIgnoreCase)))
6541
{
66-
await geofenceManager.StartMonitoring(new GeofenceRegion(
67-
GEOFENCE_ID,
68-
services.ParkOptions.Value.CenterOfPark,
69-
services.ParkOptions.Value.NotificationDistance
70-
));
42+
await services.Gps.StartListener(GpsRequest.Realtime(true));
43+
44+
var regions = geofenceManager.GetMonitorRegions();
45+
if (!regions.Any(x => x.Identifier.Equals(GEOFENCE_ID, StringComparison.InvariantCultureIgnoreCase)))
46+
{
47+
await geofenceManager.StartMonitoring(new GeofenceRegion(
48+
GEOFENCE_ID,
49+
services.ParkOptions.Value.CenterOfPark,
50+
services.ParkOptions.Value.NotificationDistance
51+
));
52+
}
7153
}
7254
}
7355
}
7456
catch (Exception ex)
7557
{
76-
logger.LogWarning(ex, "Error with geofencing");
58+
logger.LogWarning(ex, "Failed to start GPS");
7759
}
7860
}
7961
}

0 commit comments

Comments
 (0)