Skip to content

Commit

Permalink
Delay hiding the status icon when ...
Browse files Browse the repository at this point in the history
...bluetooth gets re-enabled.

Right after re-enabling bluetooth no adapters are available so the icon vanishes for a short moment until adapters are presented. To avoid that, just wait a second for adapters to show up before hiding the icon if none are present at all.

Fixes #314
  • Loading branch information
cschramm committed Feb 4, 2017
1 parent 28db593 commit 2bb615c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

* Icon disappeared when switching off bluetooth
* Revert "bluez manager: Subclass from GDBusObjectManagerClient"
* Icon briefly vanished when turning on bluetooth

## 2.1.alpha1

Expand Down
2 changes: 1 addition & 1 deletion blueman/plugins/applet/KillSwitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def io_event(self, _, condition):

logging.info("State: %s" % self._enabled)

self.Applet.Plugins.StatusIcon.QueryVisibility()
self.Applet.Plugins.StatusIcon.QueryVisibility(delay_hiding=not self._hardblocked)
self.Applet.Plugins.PowerManager.UpdatePowerState()

return True
Expand Down
26 changes: 17 additions & 9 deletions blueman/plugins/applet/StatusIcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from gi.repository import GObject
from gi.repository import Gtk, GLib


class StatusIcon(AppletPlugin, Gtk.StatusIcon):
Expand All @@ -22,11 +21,11 @@ class StatusIcon(AppletPlugin, Gtk.StatusIcon):
SHOW = 1
FORCE_HIDE = 0

visibility_timeout = None

def on_load(self, applet):
Gtk.StatusIcon.__init__(self)
self.lines = {}
self.pixbuf = None
self.timeout = None

self.set_title('blueman')

Expand All @@ -53,13 +52,12 @@ def on_icon_theme_changed(self, icon_theme):
def on_power_state_changed(self, manager, state):
if state:
self.SetTextLine(0, _("Bluetooth Enabled"))
self.QueryVisibility(delay_hiding=True)
else:
self.SetTextLine(0, _("Bluetooth Disabled"))
self.QueryVisibility()

self.QueryVisibility()

def QueryVisibility(self):

def QueryVisibility(self, delay_hiding=False):
rets = self.Applet.Plugins.Run("on_query_status_icon_visibility")
if StatusIcon.FORCE_HIDE not in rets:
if StatusIcon.FORCE_SHOW in rets:
Expand All @@ -70,12 +68,22 @@ def QueryVisibility(self):
return

try:
self.set_visible(self.Applet.Manager.get_adapters())
if self.Applet.Manager.get_adapters():
self.set_visible(True)
elif not self.visibility_timeout:
if delay_hiding:
self.visibility_timeout = GLib.timeout_add(1000, self.on_visibility_timeout)
else:
self.set_visible(False)
except:
self.set_visible(False)
else:
self.set_visible(False)

def on_visibility_timeout(self):
GLib.source_remove(self.visibility_timeout)
self.QueryVisibility()

def set_visible(self, visible):
self.props.visible = visible

Expand Down

0 comments on commit 2bb615c

Please sign in to comment.