Skip to content

Commit

Permalink
1. add visibility timeout: 2mins; 2. update connection type key
Browse files Browse the repository at this point in the history
  • Loading branch information
evelynhung committed Sep 28, 2012
1 parent 3bff9f3 commit db91357
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
8 changes: 4 additions & 4 deletions apps/settings/index.html
Expand Up @@ -400,18 +400,18 @@ <h1 data-l10n-id="bluetooth">
<ul>
<li id="bluetooth-status">
<label class="switch">
<input type="checkbox"/>
<input type="checkbox" />
<span></span>
</label>
<a data-l10n-id="bluetooth">Bluetooth</a>
</li>
<li hidden id="device-visible">
<label>
<input type="checkbox" checked />
<label class="switch">
<input type="checkbox" data-ignore checked />
<span></span>
</label>
<small id="bluetooth-device-name"></small>
<a data-l10n-id="bluetooth-visible-to-other">Visible to other devices</a>
<a data-l10n-id="bluetooth-visible-to-all">Visible to all</a>
</li>
<li hidden id="bluetooth-rename">
<label>
Expand Down
43 changes: 35 additions & 8 deletions apps/settings/js/bluetooth.js
Expand Up @@ -70,10 +70,10 @@ window.addEventListener('localized', function bluetoothSettings(evt) {
var visibleCheckBox = document.querySelector('#device-visible input');
var renameButton = document.getElementById('rename-device');

var visibleTimeout = null;
var myName = '';

visibleCheckBox.onchange = function changeDiscoverable() {
settings.createLock().set({'bluetooth.visible': this.checked});
setDiscoverable(this.checked);
};

Expand All @@ -100,14 +100,18 @@ window.addEventListener('localized', function bluetoothSettings(evt) {
if (typeof visible === 'undefined') {
visible = true;
}
visibleCheckBox.checked = visible;
setDiscoverable(visible);
};
req.onerror = function bt_getVisibleError() {
visibleCheckBox.checked = true;
};
} else {
visibleItem.hidden = true;
renameButton.disabled = true;
if (visibleTimeout) {
clearTimeout(visibleTimeout);
visibleTimeout = null;
}
}
}

Expand All @@ -120,17 +124,31 @@ window.addEventListener('localized', function bluetoothSettings(evt) {
}

function setDiscoverable(visible) {
settings.createLock().set({'bluetooth.visible': visible});
if (!defaultAdapter)
return;

defaultAdapter.setDiscoverable(visible);
// Visibility will time out after 2 mins.
if (visible) {
if (!visibleTimeout) {
visibleTimeout = setTimeout(function() {
setDiscoverable(false);
}, 120000);
}
} else {
if (visibleTimeout) {
clearTimeout(visibleTimeout);
visibleTimeout = null;
}
}
visibleCheckBox.checked = visible;
}

// API
return {
update: updateDeviceInfo,
initWithAdapter: initial,
setDiscoverable: setDiscoverable
initWithAdapter: initial
};
})();

Expand Down Expand Up @@ -427,8 +445,10 @@ window.addEventListener('localized', function bluetoothSettings(evt) {
function setDeviceDisconnect(device) {
if (!device.connected)
return;
var req = defaultAdapter.disconnect(device.address,
defaultAdapter.HANDSFREE);

// '0x111E' is a service id to distigush connection type.
// https://www.bluetooth.org/Technical/AssignedNumbers/service_discovery.htm
var req = defaultAdapter.disconnect(device.address, 0x111E);
req.onsuccess = function() {
showDeviceConnected(connectingAddress, false);
connectingAddress = null;
Expand All @@ -444,8 +464,10 @@ window.addEventListener('localized', function bluetoothSettings(evt) {
// we only support audio-card device to connect now
if (!defaultAdapter || device.icon !== 'audio-card')
return;
var req = defaultAdapter.connect(device.address,
defaultAdapter.HANDSFREE);

// '0x111E' is a service id to distigush connection type.
// https://www.bluetooth.org/Technical/AssignedNumbers/service_discovery.htm
var req = defaultAdapter.connect(device.address, 0x111E);
req.onsuccess = function() {
showDeviceConnected(connectingAddress, true);
connectingAddress = null;
Expand Down Expand Up @@ -567,6 +589,11 @@ window.addEventListener('localized', function bluetoothSettings(evt) {

gDeviceList.update(enabled);
gMyDeviceInfo.update(enabled);

// clear defaultAdapter, we have to acquire it again when enabled.
if (!enabled)
defaultAdapter = null;

});

// startup, update status
Expand Down
2 changes: 1 addition & 1 deletion apps/settings/locales/settings.en-US.properties
Expand Up @@ -104,7 +104,7 @@ bluetooth = Bluetooth
bluetooth-enable-msg = Turn Bluetooth on to view devices in the area.
bluetooth-paired-devices = Paired Devices
bluetooth-devices-in-area = Devices in the Area
bluetooth-visible-to-other = Visible to other devices
bluetooth-visible-to-all = Visible to all
bt-status-nopaired = No devices paired
bt-status-turnoff = Turned off
bt-status-pairmore = , +{{n}} more
Expand Down
2 changes: 1 addition & 1 deletion apps/settings/locales/settings.zh-TW.properties
Expand Up @@ -99,7 +99,7 @@ bluetooth = 藍牙
bluetooth-enable-msg = 打開藍牙可檢視區域內的可見裝置
bluetooth-paired-devices = 配對裝置
bluetooth-devices-in-area = 區域內的可見裝置
bluetooth-visible-to-other = 於其他裝置可見
bluetooth-visible-to-all = 於其他裝置可見
bt-status-nopaired = 無配對裝置
bt-status-turnoff = 關閉
bt-status-pairmore = , 還有 +{{n}} 個
Expand Down

0 comments on commit db91357

Please sign in to comment.