Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug 826112 - record connected device by using asyncStorage

and restore the connection when bluetooth is turned on again.
  • Loading branch information...
commit c34959ce959a24e8d3a0b22c00c90b657f232820 1 parent bc9200f
@evelynhung evelynhung authored samjoch committed
Showing with 26 additions and 3 deletions.
  1. +3 −0  apps/settings/index.html
  2. +23 −3 apps/settings/js/bluetooth.js
View
3  apps/settings/index.html
@@ -38,8 +38,11 @@
<link rel="resource" type="application/l10n" href="locales/locales.ini"/>
<script type="application/javascript" src="shared/js/l10n.js"></script>
<script type="application/javascript" src="shared/js/l10n_date.js"></script>
+
+ <!-- shared helper library -->
<script type="application/javascript" defer src="shared/js/mouse_event_shim.js"></script>
<script type="application/javascript" defer src="shared/js/manifest_helper.js"></script>
+ <script type="application/javascript" defer src="shared/js/async_storage.js"></script>
<!-- Specific code -->
<script type="application/javascript" defer src="js/utils.js"></script>
View
26 apps/settings/js/bluetooth.js
@@ -349,11 +349,22 @@ onLocalized(function bluetoothSettings() {
}
);
- getPairedDevice();
+ // get paired device and restore connection
+ // if we have one device connected before.
+ getPairedDevice(restoreConnection);
startDiscovery();
}
- function getPairedDevice() {
+ function restoreConnection() {
+ window.asyncStorage.getItem('device.connected', function(value) {
+ if(!value || !pairList.index[value])
+ return;
+ var device = pairList.index[value][0];
+ setDeviceConnect(device);
+ });
+ }
+
+ function getPairedDevice(callback) {
if (!bluetooth.enabled || !defaultAdapter)
return;
var req = defaultAdapter.getPairedDevices();
@@ -399,6 +410,10 @@ onLocalized(function bluetoothSettings() {
});
gBluetoothInfoBlock.textContent = text;
pairList.show(true);
+ // the callback function now is for restoring the connected device
+ // when the bluetooth is turned on.
+ if (callback)
+ callback();
};
}
@@ -520,9 +535,14 @@ onLocalized(function bluetoothSettings() {
function showDeviceConnected(deviceAddress, connected) {
if (connected) {
connectedAddress = deviceAddress;
+ // record connected device so if Bluetooth is turned off and then on
+ // we can restore the connection
+ window.asyncStorage.setItem('device.connected', connectedAddress);
} else {
- if (connectedAddress === deviceAddress)
+ if (connectedAddress === deviceAddress) {
connectedAddress = null;
+ window.asyncStorage.removeItem('device.connected');
+ }
}
var item = pairList.index[deviceAddress][1];
item.querySelector('small').textContent = (connected) ?
Please sign in to comment.
Something went wrong with that request. Please try again.