Skip to content
Browse files

bug 818234 prevent quickly tapping on bluetooth and wifi settings

  • Loading branch information...
1 parent 9994b80 commit 17622524b4114396a74578e2ca067b2f570b6a23 @evelynhung evelynhung committed
View
9 apps/settings/js/bluetooth.js
@@ -601,6 +601,9 @@ onLocalized(function bluetoothSettings() {
if (lastMozSettingValue == enabled)
return;
+ // lock UI toggle
+ gBluetoothCheckBox.disabled = true;
+
lastMozSettingValue = enabled;
updateBluetoothState(enabled);
@@ -630,7 +633,13 @@ onLocalized(function bluetoothSettings() {
};
bluetooth.onadapteradded = function bt_adapterAdded() {
+ // enable UI toggle
+ gBluetoothCheckBox.disabled = false;
initialDefaultAdapter();
};
+ bluetooth.ondisabled = function bt_onDisabled() {
+ // enable UI toggle
+ gBluetoothCheckBox.disabled = false;
+ };
});
View
7 apps/settings/js/wifi.js
@@ -76,11 +76,15 @@ onLocalized(function wifiSettings() {
};
gWifiManager.onenabled = function onWifiEnabled() {
+ // enable UI toogle
+ gWifiCheckBox.disabled = false;
updateNetworkState();
gNetworkList.scan();
};
gWifiManager.ondisabled = function onWifiDisabled() {
+ // enable UI toogle
+ gWifiCheckBox.disabled = false;
gWifiInfoBlock.textContent = _('disabled');
gNetworkList.clear(false);
gNetworkList.autoscan = false;
@@ -722,6 +726,9 @@ onLocalized(function wifiSettings() {
if (lastMozSettingValue == event.settingValue)
return;
+ // lock UI toggle
+ gWifiCheckBox.disabled = true;
+
lastMozSettingValue = event.settingValue;
setMozSettingsEnabled(event.settingValue);
});
View
22 apps/system/js/bluetooth.js
@@ -30,11 +30,27 @@ var Bluetooth = {
}
});
- // when bluetooth adapter is ready, let get the default adapter.
- // and try to acquire default adapter when booting.
- bluetooth.onadapteradded = this.initDefaultAdapter.bind(this);
+ var self = this;
+ // when bluetooth adapter is ready, emit event to notify QuickSettings
+ // and try to get defaultAdapter at this moment
+ bluetooth.onadapteradded = function bt_onAdapterAdded() {
+ var evt = document.createEvent('CustomEvent');
+ evt.initCustomEvent('bluetooth-adapter-added',
+ /* canBubble */ true, /* cancelable */ false, null);
+ window.dispatchEvent(evt);
+ self.initDefaultAdapter();
+ };
+ // if bluetooth is enabled in booting time, try to get adapter now
this.initDefaultAdapter();
+ // when bluetooth is really disabled, emit event to notify QuickSettings
+ bluetooth.ondisabled = function bt_onDisabled() {
+ var evt = document.createEvent('CustomEvent');
+ evt.initCustomEvent('bluetooth-disabled',
+ /* canBubble */ true, /* cancelable */ false, null);
+ window.dispatchEvent(evt);
+ };
+
/* for v1, we only support two use cases for bluetooth connection:
* 1. connecting with a headset
* 2. transfering a file to/from another device
View
110 apps/system/js/quick_settings.js
@@ -19,29 +19,89 @@ var QuickSettings = {
var self = this;
- // monitor data status
+ /* monitor data setting
+ * TODO prevent quickly tapping on it
+ */
SettingsListener.observe('ril.data.enabled', true, function(value) {
- self.data.dataset.enabled = value;
+ if (value) {
+ self.data.dataset.enabled = 'true';
+ } else {
+ delete self.data.dataset.enabled;
+ }
});
- // monitor bluetooth status
+ /* monitor bluetooth setting and initialization/disable ready event
+ * - when settings changed, update UI and lock toogle to prevent quickly
+ * tapping on it.
+ * - when got bluetooth initialization/disable ready, active toogle, so
+ * return the control to user.
+ */
+ var btFirstSet = true;
SettingsListener.observe('bluetooth.enabled', true, function(value) {
- self.bluetooth.dataset.enabled = value;
+ // check self.bluetooth.dataset.enabled and value are identical
+ if ((self.bluetooth.dataset.enabled && value) ||
+ (self.bluetooth.dataset.enabled === undefined && !value))
+ return;
+
+ if (value) {
+ self.bluetooth.dataset.enabled = 'true';
+ } else {
+ delete self.bluetooth.dataset.enabled;
+ }
+
+ // Set to the initializing state to block user interaction until the
+ // operation completes. (unless we are being called for the first time,
+ // where Bluetooth is already initialize
+ if (!btFirstSet)
+ self.bluetooth.dataset.initializing = 'true';
+ btFirstSet = false;
});
+ window.addEventListener('bluetooth-adapter-added', this);
+ window.addEventListener('bluetooth-disabled', this);
- // monitor wifi status
+
+ /* monitor wifi setting and initialization/disable ready event
+ * - when settings changed, update UI and lock toogle to prevent quickly
+ * tapping on it.
+ * - when got bluetooth initialization/disable ready, active toogle, so
+ * return the control to user.
+ */
+ var wifiFirstSet = true;
SettingsListener.observe('wifi.enabled', true, function(value) {
- self.wifi.dataset.enabled = value;
+ // check self.wifi.dataset.enabled and value are identical
+ if ((self.wifi.dataset.enabled && value) ||
+ (self.wifi.dataset.enabled === undefined && !value))
+ return;
+
+ if (value) {
+ self.wifi.dataset.enabled = 'true';
+ } else {
+ delete self.wifi.dataset.enabled;
+ }
+ // Set to the initializing state to block user interaction until the
+ // operation completes. (unless we are being called for the first time,
+ // where Wifi is already initialize
+ if (!wifiFirstSet)
+ self.wifi.dataset.initializing = 'true';
+ wifiFirstSet = false;
});
+ window.addEventListener('wifi-enabled', this);
+ window.addEventListener('wifi-disabled', this);
- // monitor geolocation status
+ /* monitor geolocation setting
+ * TODO prevent quickly tapping on it
+ */
SettingsListener.observe('geolocation.enabled', true, function(value) {
self.geolocationEnabled = value;
});
// monitor power save mode
SettingsListener.observe('powersave.enabled', false, function(value) {
- self.powerSave.dataset.enabled = value;
+ if (value) {
+ self.powerSave.dataset.enabled = 'true';
+ } else {
+ delete self.powerSave.dataset.enabled;
+ }
});
},
@@ -51,8 +111,10 @@ var QuickSettings = {
case 'click':
switch (evt.target) {
case this.wifi:
- var enabled = (this.wifi.dataset.enabled == 'true');
- this.wifi.dataset.enabled = !enabled;
+ // do nothing if wifi isn't ready
+ if (this.wifi.dataset.initializing)
+ return;
+ var enabled = !!this.wifi.dataset.enabled;
SettingsListener.getSettingsLock().set({
'wifi.enabled': !enabled
});
@@ -68,11 +130,8 @@ var QuickSettings = {
break;
case this.data:
- var enabled = (this.data.dataset.enabled == 'true');
- // the actual mozSettings request is async,
- // but we want to be responsive to user input
- // and double click so we'll change the UI state here
- this.data.dataset.enabled = !enabled;
+ // TODO should ignore the action if data initialization isn't done
+ var enabled = !!this.data.dataset.enabled;
SettingsListener.getSettingsLock().set({
'ril.data.enabled': !enabled
@@ -81,16 +140,18 @@ var QuickSettings = {
break;
case this.bluetooth:
- var enabled = (this.bluetooth.dataset.enabled == 'true');
- this.bluetooth.dataset.enabled = !enabled;
+ // do nothing if bluetooth isn't ready
+ if (this.bluetooth.dataset.initializing)
+ return;
+
+ var enabled = !!this.bluetooth.dataset.enabled;
SettingsListener.getSettingsLock().set({
'bluetooth.enabled': !enabled
});
break;
case this.powerSave:
- var enabled = (this.powerSave.dataset.enabled == 'true');
- this.powerSave.dataset.enabled = !enabled;
+ var enabled = !!this.powerSave.dataset.enabled;
SettingsListener.getSettingsLock().set({
'powersave.enabled': !enabled
});
@@ -111,6 +172,17 @@ var QuickSettings = {
case 'utilitytrayshow':
break;
+
+ // unlock bluetooth toggle
+ case 'bluetooth-adapter-added':
+ case 'bluetooth-disabled':
+ delete this.bluetooth.dataset.initializing;
+ break;
+ // unlock wifi toggle
+ case 'wifi-enabled':
+ case 'wifi-disabled':
+ delete this.wifi.dataset.initializing;
+ break;
}
},
View
15 apps/system/js/wifi.js
@@ -48,6 +48,21 @@ var Wifi = {
var self = this;
var wifiManager = window.navigator.mozWifiManager;
+ // when wifi is really enabled, emit event to notify QuickSettings
+ wifiManager.onenabled = function onWifiEnabled() {
+ var evt = document.createEvent('CustomEvent');
+ evt.initCustomEvent('wifi-enabled',
+ /* canBubble */ true, /* cancelable */ false, null);
+ window.dispatchEvent(evt);
+ };
+
+ // when wifi is really disabled, emit event to notify QuickSettings
+ wifiManager.ondisabled = function onWifiDisabled() {
+ var evt = document.createEvent('CustomEvent');
+ evt.initCustomEvent('wifi-disabled',
+ /* canBubble */ true, /* cancelable */ false, null);
+ window.dispatchEvent(evt);
+ };
// Track the wifi.enabled mozSettings value
SettingsListener.observe('wifi.enabled', true, function(value) {
View
12 apps/system/style/quick_settings/quick_settings.css
@@ -43,30 +43,34 @@
background: center no-repeat;
background-size: 25px 25px;
}
+#quick-settings > *[data-initializing] {
+ opacity: 0.5;
+}
#quick-settings > #quick-settings-wifi {
background-image: url(images/wifi-off.svg);
}
-#quick-settings > #quick-settings-wifi[data-enabled="true"] {
+#quick-settings > #quick-settings-wifi[data-enabled] {
background-image: url(images/wifi-on.svg);
}
#quick-settings > #quick-settings-data {
background-image: url(images/data-off.svg);
}
-#quick-settings > #quick-settings-data[data-enabled="true"] {
+#quick-settings > #quick-settings-data[data-enabled] {
background-image: url(images/data-on.svg);
}
#quick-settings > #quick-settings-bluetooth {
background-image: url(images/bluetooth-off.svg);
}
-#quick-settings > #quick-settings-bluetooth[data-enabled="true"] {
+#quick-settings > #quick-settings-bluetooth[data-enabled] {
background-image: url(images/bluetooth-on.svg);
}
#quick-settings > #quick-settings-power-save {
background-image: url(images/power-save-off.svg);
}
-#quick-settings > #quick-settings-power-save[data-enabled="true"] {
+#quick-settings > #quick-settings-power-save[data-enabled] {
background-image: url(images/power-save-on.svg);
}
#quick-settings > #quick-settings-full-app {
background-image: url(images/settings.svg);
}
+
View
3 shared/style/switches.css
@@ -110,3 +110,6 @@ label input[data-type="switch"]:checked + span:after {
transform: translateX(0);
}
+label input[data-type="switch"]:disabled + span {
+ opacity: 0.5;
+}

0 comments on commit 1762252

Please sign in to comment.
Something went wrong with that request. Please try again.