private async void OnDisconnectDeviceCommand() { if (!Disconnecting) { if (SelectedDevice != null) { if (CrossBleAdapter.Current.Status == AdapterStatus.PoweredOn || CrossBleAdapter.Current.Status == AdapterStatus.Unsupported) { try { Disconnecting = true; DisconnectDeviceCommand.RaiseCanExecuteChanged(); //BatteryToken?.Cancel(); //SystemToken?.Cancel(); //ProgramToken?.Cancel(); bleService.Disconnect(); var timeOut = 0; while (SelectedDevice.ConnectState != DeviceState.Disconnected && timeOut < 30) { await Task.Delay(TimeSpan.FromSeconds(1)); timeOut++; } Disconnecting = false; DisconnectDeviceCommand.RaiseCanExecuteChanged(); if (SelectedDevice.ConnectState != DeviceState.Disconnected) { await dialogService.DisplayAlertAsync("Bluetooth", "Device failed to disconnect", "Ok"); } else { foundDevices.Clear(); AvailableDevices.Clear(); SelectedDevice = null; // RaisePropertyChanged(nameof(SelectedDevice)); } } catch (Exception e) { // Crashes.TrackError(e); Disconnecting = false; DisconnectDeviceCommand.RaiseCanExecuteChanged(); } } else { await dialogService.DisplayAlertAsync("Bluetooth", "Please check your Bluetooth Settings", "Ok"); } } } }
/// <summary> /// Adds the platform-specific commands. /// </summary> partial void AddPlatformCommands() { CommandList.Add(SearchForDevicesToolbarCommand); CommandList.Add(SearchForDevicesToolbarCommand.CreateToolbarSeparator(CommandLocation.Before)); SearchForDevicesCommand.Weight = 0.12; SearchForDevicesCommand.MenuParent = RootCommandGroup.ToolsMenuCommand; CommandList.Add(ConnectToDeviceSubmenuCommand); DisconnectDeviceCommand.Weight = 0.122; DisconnectDeviceCommand.MenuParent = RootCommandGroup.ToolsMenuCommand; DisconnectDeviceCommand.KeyboardShortcutKey = "d"; DisconnectDeviceCommand.KeyboardShortcutModifiers = OSModifierKeys.Menu; DisconnectDeviceCommand.VisualParent = RootCommandGroup.RootCommand; DeviceInformationCommand.Weight = 0.123; DeviceInformationCommand.MenuParent = RootCommandGroup.ToolsMenuCommand; CommandList.Add(DeviceInformationCommand); #if false SetShowTitleScreenCommand.VisualParent = DeviceSettingsRibbonGroupCommand; SetShowTitleScreenCommand.Weight = 0; SetEcsCompatibilityCommand.VisualParent = DeviceSettingsRibbonGroupCommand; SetEcsCompatibilityCommand.Weight = 0.1; SetIntellivisionIICompatibilityCommand.VisualParent = DeviceSettingsRibbonGroupCommand; SetIntellivisionIICompatibilityCommand.Weight = 0.12; CommandList.Add(SetIntellivisionIICompatibilityCommand.CreateRibbonSeparator(CommandLocation.After)); SetSaveMenuPositionCommand.VisualParent = DeviceSettingsRibbonGroupCommand; SetSaveMenuPositionCommand.Weight = 0.13; SetKeyclicksCommand.VisualParent = DeviceSettingsRibbonGroupCommand; SetKeyclicksCommand.Weight = 0.14; SetBackgroundGarbageCollectCommand.VisualParent = DeviceSettingsRibbonGroupCommand; SetBackgroundGarbageCollectCommand.Weight = 0.15; SetDeviceNameCommand.VisualParent = ActiveDeviceRibbonGroupCommand; SetDeviceNameCommand.Weight = 0; SetDeviceOwnerCommand.VisualParent = ActiveDeviceRibbonGroupCommand; SetDeviceOwnerCommand.Weight = 0.1; DeviceUniqueIdCommand.VisualParent = ActiveDeviceRibbonGroupCommand; DeviceUniqueIdCommand.Weight = 0.2; AdvancedGroupCommand.Weight = 0.15; CommandList.Add(ActiveDeviceRibbonGroupCommand); CommandList.Add(DeviceSettingsRibbonGroupCommand); CommandList.Add(SetShowTitleScreenCommand); CommandList.Add(SetSaveMenuPositionCommand); CommandList.Add(SetKeyclicksCommand); CommandList.Add(SetBackgroundGarbageCollectCommand); CommandList.Add(SetDeviceNameCommand); CommandList.Add(SetDeviceOwnerCommand); CommandList.Add(DeviceUniqueIdCommand); CommandList.Add(BackupRibbonSplitButtonCommand); CommandList.Add(ShowFileSystemDetailsCommand); CommandList.Add(DisconnectDeviceCommand.CreateRibbonMenuSeparator(CommandLocation.After, true)); CommandList.Add(OpenDeviceBackupsDirectoryCommand.CreateRibbonMenuSeparator(CommandLocation.After, true)); CommandList.Add(ClearCacheCommand.CreateRibbonMenuSeparator(CommandLocation.After, true)); CommandList.Add(AdvancedGroupCommand.CreateRibbonMenuSeparator(CommandLocation.After, true)); #endif CommandList.Add(AdvancedGroupCommand); CommandList.Add(OpenDeviceBackupsDirectoryCommand.CreateSeparator(CommandLocation.After)); CommandList.Add(ReformatCommand.CreateSeparator(CommandLocation.Before)); }
/// <inheritdoc /> partial void AddPlatformCommands() { SearchForDevicesCommand.MenuParent = LtoFlashCommandGroup.LtoFlashGroupCommand; SearchForDevicesCommand.VisualParent = LtoFlashCommandGroup.LtoFlashHomeRibbonGroupCommand; SearchForDevicesCommand.UseXamlResource = true; DisconnectDeviceCommand.MenuParent = LtoFlashCommandGroup.LtoFlashGroupCommand; DisconnectDeviceCommand.VisualParent = LtoFlashCommandGroup.LtoFlashHomeRibbonGroupCommand; DisconnectDeviceCommand.Weight = 0.12; DisconnectDeviceCommand.UseXamlResource = true; SetShowTitleScreenCommand.VisualParent = DeviceSettingsRibbonGroupCommand; SetShowTitleScreenCommand.UseXamlResource = true; SetShowTitleScreenCommand.Weight = 0; SetEcsCompatibilityCommand.VisualParent = DeviceSettingsRibbonGroupCommand; SetEcsCompatibilityCommand.UseXamlResource = true; SetEcsCompatibilityCommand.Weight = 0.1; SetIntellivisionIICompatibilityCommand.VisualParent = DeviceSettingsRibbonGroupCommand; SetIntellivisionIICompatibilityCommand.UseXamlResource = true; SetIntellivisionIICompatibilityCommand.Weight = 0.12; CommandList.Add(SetIntellivisionIICompatibilityCommand.CreateRibbonSeparator(CommandLocation.After)); SetSaveMenuPositionCommand.VisualParent = DeviceSettingsRibbonGroupCommand; SetSaveMenuPositionCommand.UseXamlResource = true; SetSaveMenuPositionCommand.Weight = 0.13; SetKeyclicksCommand.VisualParent = DeviceSettingsRibbonGroupCommand; SetKeyclicksCommand.UseXamlResource = true; SetKeyclicksCommand.Weight = 0.14; SetBackgroundGarbageCollectCommand.VisualParent = DeviceSettingsRibbonGroupCommand; SetBackgroundGarbageCollectCommand.UseXamlResource = true; SetBackgroundGarbageCollectCommand.Weight = 0.15; CommandList.Add(SetBackgroundGarbageCollectCommand.CreateRibbonSeparator(CommandLocation.After)); SetEnableConfigMenuOnCartCommand.VisualParent = DeviceSettingsRibbonGroupCommand; SetEnableConfigMenuOnCartCommand.UseXamlResource = true; SetEnableConfigMenuOnCartCommand.Weight = 0.16; SetRandomizeLtoFlashRamCommand.VisualParent = DeviceSettingsRibbonGroupCommand; SetRandomizeLtoFlashRamCommand.UseXamlResource = true; SetRandomizeLtoFlashRamCommand.Weight = 0.161; SetDeviceNameCommand.VisualParent = ActiveDeviceRibbonGroupCommand; SetDeviceNameCommand.UseXamlResource = true; SetDeviceNameCommand.Weight = 0; SetDeviceOwnerCommand.VisualParent = ActiveDeviceRibbonGroupCommand; SetDeviceOwnerCommand.UseXamlResource = true; SetDeviceOwnerCommand.Weight = 0.1; DeviceUniqueIdCommand.VisualParent = ActiveDeviceRibbonGroupCommand; DeviceUniqueIdCommand.UseXamlResource = true; DeviceUniqueIdCommand.Weight = 0.2; AdvancedGroupCommand.Weight = 0.15; CommandList.Add(ActiveDeviceRibbonGroupCommand); CommandList.Add(DeviceSettingsRibbonGroupCommand); CommandList.Add(SetShowTitleScreenCommand); CommandList.Add(SetSaveMenuPositionCommand); CommandList.Add(SetKeyclicksCommand); CommandList.Add(SetBackgroundGarbageCollectCommand); CommandList.Add(SetEnableConfigMenuOnCartCommand); CommandList.Add(SetRandomizeLtoFlashRamCommand); CommandList.Add(SetDeviceNameCommand); CommandList.Add(SetDeviceOwnerCommand); CommandList.Add(DeviceUniqueIdCommand); CommandList.Add(BackupRibbonSplitButtonCommand); CommandList.Add(ShowFileSystemDetailsCommand); CommandList.Add(DisconnectDeviceCommand.CreateRibbonMenuSeparator(CommandLocation.After, true)); CommandList.Add(AdvancedGroupCommand); CommandList.Add(OpenDeviceBackupsDirectoryCommand.CreateRibbonMenuSeparator(CommandLocation.After, true)); CommandList.Add(ClearCacheCommand.CreateRibbonMenuSeparator(CommandLocation.After, true)); CommandList.Add(AdvancedGroupCommand.CreateRibbonMenuSeparator(CommandLocation.After, true)); }