Chromium Code Reviews| Index: chrome/browser/resources/bluetooth_internals/bluetooth_internals.js |
| diff --git a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js |
| index 4582adef574a89ced2976da1a1960d16bd1dac24..86a9ead45b452566ace0c745f203c6512dc75187 100644 |
| --- a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js |
| +++ b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js |
| @@ -26,32 +26,57 @@ |
| var AdapterClient = function() { this.devices_ = new Map(); }; |
| AdapterClient.prototype = { |
| /** |
| - * Logs added device to console and caches the device info. |
| - * @param {!bluetoothDevice.DeviceInfo} device |
| + * Caches the device info and updates the device list. |
| + * @param {!bluetoothDevice.DeviceInfo} deviceInfo |
| */ |
| deviceAdded: function(deviceInfo) { |
| - console.log('Device added', deviceInfo); |
| - this.devices_.set(deviceInfo.address, new Device(deviceInfo)); |
| + if (this.devices_.has(deviceInfo.address)) { |
|
dpapad
2016/10/21 22:46:21
How can device that was just added can already exi
mbrunson
2016/10/24 17:15:08
A device can be removed if it is not detected for
|
| + var deviceElement = $(deviceInfo.address); |
| + deviceElement.classList.remove('removed'); |
|
dpapad
2016/10/21 22:46:21
Let's put all CSS string literals used in JS in an
mbrunson
2016/10/24 17:15:08
Done.
|
| + } else { |
| + this.devices_.set(deviceInfo.address, new Device(deviceInfo)); |
| + |
| + var deviceRowTemplate = $('device-row-template'); |
| + var deviceRow = deviceRowTemplate.content.children[0].cloneNode( |
| + true /* deep */); |
|
dpapad
2016/10/21 22:46:21
The recommended way to instantiate templates is do
mbrunson
2016/10/24 17:15:08
Ok. I haven't used it before, but it seems to prod
|
| + deviceRow.id = deviceInfo.address; |
| + |
| + var deviceList = $('device-list'); |
| + deviceList.appendChild(deviceRow); |
| + } |
| + |
| + this.deviceChanged(deviceInfo); |
| }, |
| /** |
| - * Logs removed device to console and removes the cached device. |
| - * @param {!bluetoothDevice.DeviceInfo} device |
| + * Removes the cached device and updates the device list. |
| + * @param {!bluetoothDevice.DeviceInfo} deviceInfo |
| */ |
| deviceRemoved: function(deviceInfo) { |
| - console.log('Device removed', deviceInfo); |
| - this.devices_.delete(deviceInfo.address); |
| + $(deviceInfo.address).classList.add('removed'); |
| }, |
| /** |
| - * Logs changed device info to console and updates the cached device. |
| + * Updates cached device and updates the device list. |
| * @param {!bluetoothDevice.DeviceInfo} deviceInfo |
| */ |
| deviceChanged: function(deviceInfo) { |
| console.log(new Date(), deviceInfo); |
| - if (this.devices_.has(deviceInfo.address)) { |
| - this.devices_.get(deviceInfo.address).info = deviceInfo; |
| - } |
| + |
| + if (!this.devices_.has(deviceInfo.address)) |
| + throw new Error('Device does not exist.'); |
|
dpapad
2016/10/21 22:46:21
Can you use assert.js instead, see https://cs.chro
mbrunson
2016/10/24 17:15:08
Done.
|
| + |
| + this.devices_.get(deviceInfo.address).info = deviceInfo; |
| + |
| + var deviceRow = $(deviceInfo.address); |
| + deviceRow.querySelector('.device-name').innerText = |
|
dpapad
2016/10/21 22:46:22
You probably want to use textContent (more context
mbrunson
2016/10/24 17:15:08
Done.
|
| + deviceInfo.name_for_display; |
| + deviceRow.querySelector('.device-address').innerText = |
| + deviceInfo.address; |
| + |
| + var rssi = (deviceInfo.rssi && deviceInfo.rssi.value) || |
| + deviceRow.querySelector('.device-rssi').innerText; |
| + deviceRow.querySelector('.device-rssi').innerText = rssi; |
| } |
| }; |
| @@ -81,8 +106,6 @@ |
| 'device/bluetooth/public/interfaces/device.mojom', |
| 'mojo/public/js/connection', |
| ]).then(function([frameInterfaces, ...modules]) { |
| - console.log('Loaded modules'); |
| - |
| // Destructure here to assign global variables. |
| [bluetoothAdapter, bluetoothDevice, connection] = modules; |
| @@ -117,11 +140,7 @@ |
| .then(function(response) { console.log('adapter', response.info); }) |
| .then(function() { return adapter.getDevices(); }) |
| .then(function(response) { |
| - console.log('devices', response.devices.length); |
| - |
| - response.devices.forEach(function(deviceInfo) { |
| - adapterClient.deviceAdded(deviceInfo); |
| - }); |
| + response.devices.forEach(adapterClient.deviceAdded, adapterClient); |
| }) |
| .catch(function(error) { console.error(error); }); |
| }); |