summaryrefslogtreecommitdiff
path: root/ui.js
diff options
context:
space:
mode:
authorBartosz Jaroszewski <b.jarosze@gmail.com>2021-10-25 15:25:08 +0200
committerBartosz Jaroszewski <b.jarosze@gmail.com>2021-10-25 15:59:03 +0200
commit212d223217c3c1af05ee0548229f29d60822e988 (patch)
tree182c13b884ff1ea814ff345c77783e47947b98a4 /ui.js
parent6d2c592a63fa6e148ae33aa8f6647506189fb2cb (diff)
change item state based on event or timeout only
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js36
1 files changed, 11 insertions, 25 deletions
diff --git a/ui.js b/ui.js
index 1bce0bd..dcbf406 100644
--- a/ui.js
+++ b/ui.js
@@ -114,29 +114,20 @@ var PopupBluetoothDeviceMenuItem = GObject.registerClass(
this._device = device;
- this._syncSwitch(device);
+ this._switch.state = device.isConnected;
this.visible = device.isPaired;
if (this._showRefreshButton && device.isConnected)
this._refreshButton.show();
else
this._refreshButton.hide();
- this._updateDeviceInfo();
+ this._disablePending();
if (device.isConnected)
this._tryLocateBatteryWithTimeout();
}
- _syncSwitch(device) {
- this._switch.state = device.isConnected;
- }
-
- _updateDeviceInfo() {
- this._logger.info(`updating label for ${this._device.name} ${this._optBatDevice.map(bat => bat.percentage)}`);
- this.label.text = this._device.name || "unknown";;
- }
-
_buildRefreshButton() {
let icon = new St.Icon({
icon_name: 'view-refresh',
@@ -169,10 +160,8 @@ var PopupBluetoothDeviceMenuItem = GObject.registerClass(
button.connect('clicked', () => {
this._enablePending();
- this._device.reconnect(() => {
- this._disablePending();
- this._updateDeviceInfo();
- });
+ this._device.reconnect();
+ GLib.timeout_add(GLib.PRIORITY_DEFAULT, 10000, () => this._disablePending());
if (this._closeMenuOnAction)
this.emit('activate', Clutter.get_current_event());
@@ -190,16 +179,13 @@ var PopupBluetoothDeviceMenuItem = GObject.registerClass(
_connectToggledEvent() {
this.connect('toggled', (item, state) => {
- if (state) {
- this._device.connect(() => {
- this._disablePending();
- this._updateDeviceInfo();
- });
- } else {
- this._device.disconnect(() => {
- this._disablePending();
- });
- }
+ if (state)
+ this._device.connect();
+ else
+ this._device.disconnect();
+
+ // in case there is no change on device
+ GLib.timeout_add(GLib.PRIORITY_DEFAULT, 10000, () => this._disablePending());
});
}