private async void OnBluetoothDeviceUpdated(BluetoothWatcher sender, DeviceWatchEvent eventCode, DeviceInformation deviceInformation) { string deviceId = deviceInformation == null ? string.Empty : deviceInformation.Id; Log.D($"OnBluetoothDeviceUpdated: {eventCode} {deviceId}"); switch (eventCode) { case DeviceWatchEvent.Added: EarbudsMenuItem newEarbudsMenuItem = new EarbudsMenuItem(deviceInformation, systrayApplicationServiceConnection); bool result = await newEarbudsMenuItem.Start(); Log.D($"Starting {newEarbudsMenuItem.Text}, result = {result}"); PairedDeviceMenuItems.Add(newEarbudsMenuItem); break; case DeviceWatchEvent.Removed: foreach (EarbudsMenuItem earbudsMenuItem in PairedDeviceMenuItems) { if (deviceId.Equals(earbudsMenuItem.BtID)) { PairedDeviceMenuItems.Remove(earbudsMenuItem); earbudsMenuItem.Stop(); break; } } break; } InitMenuItems(); }
public DeviceManager() { // Init BleAdvertisementWacther bleAdvertisementWatcher = new BleAdvertisementWatcher(); // Init BluetoothWacther bluetoothWatcher = new BluetoothWatcher(); PairingManager = new PairingManager(); }
public SystrayApplicationContext() { // Initialize ApplicationSErvice Connection systrayApplicationServiceConnection = new SystrayApplicationServiceConnection(); systrayApplicationServiceConnection.Init(); if (systrayApplicationServiceConnection.Initialized) { MessageBox.Show("Failed to initialize AppServiceConnection" + systrayApplicationServiceConnection.Status.ToString()); Application.Exit(); } systrayApplicationServiceConnection.NewMessageReceived += OnNewMessageReceived; systrayApplicationServiceConnection.ConnectionClosed += OnAppClosed; Log = Log.GetInstance(systrayApplicationServiceConnection); // Init Parameters var userInfo = (ApplicationDataCompositeValue)ApplicationData.Current.LocalSettings.Values["userInfo"]; if (userInfo != null) { userName = userInfo["name"] as string; userKey = userInfo["key"] as string; } else { userName = "******"; userKey = null; } // Init BleAdvertisementWacther bleAdvertisementWatcher = new BleAdvertisementWatcher(); // Init BluetoothWacther bluetoothWatcher = new BluetoothWatcher(); // Initialize Menu InitMenu(); InitMenuItems(); // Initialize AudioMonitor AudioMonitor = new AudioMonitor(); // Start Post Initilalizaion Timer postInitializationTimer.Tick += OnIntialized; postInitializationTimer.Interval = 1000; postInitializationTimer.Start(); }
private void OnBluetoothDeviceUpdated(BluetoothWatcher sender, DeviceWatchEvent eventCode, DeviceInformation deviceInformation) { string deviceId = deviceInformation == null ? string.Empty : deviceInformation.Id; Log.D(string.Format($"OnBluetoothDeviceUpdated: {eventCode} {deviceId}")); switch (eventCode) { case DeviceWatchEvent.Added: AddPairedBtDevice(deviceInformation); break; case DeviceWatchEvent.Updated: UpdatePairedBtDevice(deviceInformation); break; case DeviceWatchEvent.Removed: RemovePairedBtDevice(deviceInformation); break; } PairedDeviceUpdated?.Invoke(this, eventCode, deviceInformation); }