public MainPageViewModel() { if (App.Current.Properties.ContainsKey("defaultPrinter")) { string guidName = App.Current.Properties["defaultPrinter"].ToString(); _connectedDisposable = _centralManager.GetConnectedPeripherals().Subscribe(scanResult => { scanResult.ToList().ForEach( item => { if (!string.IsNullOrEmpty(item.Name) && item.Name == guidName) { Peripherals.Add(item); _centralManager.StopScan(); Device.BeginInvokeOnMainThread(async() => { await App.Current.MainPage.Navigation.PushAsync(new PrintPage(item)); SelectedPeripheral = null; }); _scanDisposable?.Dispose(); IsScanning = _centralManager.IsScanning; } }); _connectedDisposable?.Dispose(); }); if (_centralManager.IsScanning) { _centralManager.StopScan(); } if (_centralManager.Status == Shiny.AccessState.Available && !_centralManager.IsScanning) { _scanDisposable = _centralManager.ScanForUniquePeripherals().Subscribe(scanResult => { if (!string.IsNullOrEmpty(scanResult.Name) && !Peripherals.Contains(scanResult)) { Peripherals.Add(scanResult); Device.BeginInvokeOnMainThread(async() => { await App.Current.MainPage.Navigation.PushAsync(new PrintPage(scanResult)); SelectedPeripheral = null; }); } }); } } else { GetDeviceListCommand = new Command(GetDeviceList); SetAdapterCommand = new Command(async() => await SetAdapter()); CheckPermissionsCommand = new Command(async() => await CheckPermissions()); CheckPermissionsCommand.Execute(null); } }
public ConnectedPeripheralsViewModel(IBleManager centralManager) { this.Load = ReactiveCommand.CreateFromTask(async() => { var peripherals = await centralManager.GetConnectedPeripherals(); //peripherals.Select(x => x // TODO: get TBD connected devices too }); }