diff options
author | Bartosz Jaroszewski <b.jarosze@gmail.com> | 2021-10-25 15:25:08 +0200 |
---|---|---|
committer | Bartosz Jaroszewski <b.jarosze@gmail.com> | 2021-10-25 15:59:03 +0200 |
commit | 212d223217c3c1af05ee0548229f29d60822e988 (patch) | |
tree | 182c13b884ff1ea814ff345c77783e47947b98a4 /ui.js | |
parent | 6d2c592a63fa6e148ae33aa8f6647506189fb2cb (diff) |
change item state based on event or timeout only
Diffstat (limited to 'ui.js')
-rw-r--r-- | ui.js | 36 |
1 files changed, 11 insertions, 25 deletions
@@ -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()); }); } |