Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #7320 from evelynhung/issue-826112
Browse files Browse the repository at this point in the history
Bug 826112 - record connected device by using asyncStorage
  • Loading branch information
evelynhung committed Jan 7, 2013
2 parents 2e33b9e + 15cf1c5 commit 567878d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions apps/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
26 changes: 23 additions & 3 deletions apps/settings/js/bluetooth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
};
}

Expand Down Expand Up @@ -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) ?
Expand Down

0 comments on commit 567878d

Please sign in to comment.