62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using FieldLogger.Services;
|
|
using FieldLogger.Services.Sync;
|
|
|
|
namespace FieldLogger;
|
|
|
|
public partial class App : Application
|
|
{
|
|
private readonly DeviceConnectionManager _connectionManager;
|
|
private readonly IMqttSyncService _syncService;
|
|
|
|
public App(DeviceConnectionManager connectionManager, IMqttSyncService syncService)
|
|
{
|
|
InitializeComponent();
|
|
_connectionManager = connectionManager;
|
|
_syncService = syncService;
|
|
|
|
Console.WriteLine("===== FIELD LOGGER APP STARTING =====");
|
|
Console.WriteLine($"Console output is working! Time: {DateTime.Now:HH:mm:ss}");
|
|
}
|
|
|
|
protected override Window CreateWindow(IActivationState? activationState)
|
|
{
|
|
var window = new Window(new AppShell());
|
|
|
|
// Disconnect BLE devices when window is closing
|
|
window.Destroying += async (s, e) =>
|
|
{
|
|
Console.WriteLine("App: Window closing, disconnecting devices...");
|
|
await DisconnectAllDevicesAsync();
|
|
await _syncService.StopAsync();
|
|
};
|
|
|
|
return window;
|
|
}
|
|
|
|
private async Task DisconnectAllDevicesAsync()
|
|
{
|
|
try
|
|
{
|
|
// Disconnect locator
|
|
if (_connectionManager.Locator.IsConnected)
|
|
{
|
|
Console.WriteLine("App: Disconnecting locator...");
|
|
await _connectionManager.Locator.DisconnectAsync();
|
|
}
|
|
|
|
// Disconnect GPS
|
|
if (_connectionManager.Gps.IsConnected)
|
|
{
|
|
Console.WriteLine("App: Disconnecting GPS...");
|
|
await _connectionManager.Gps.DisconnectAsync();
|
|
}
|
|
|
|
Console.WriteLine("App: All devices disconnected");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"App: Error disconnecting devices: {ex.Message}");
|
|
}
|
|
}
|
|
}
|