Skip to content

Commit

Permalink
Terminate applet on manager termination if it was started by manager
Browse files Browse the repository at this point in the history
Closes #2482
  • Loading branch information
cschramm committed Sep 10, 2024
1 parent 3a96de9 commit fa74af2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## main

### Changes

* Terminate applet on manager termination if it was started by manager

## 2.4.2

### New features
Expand Down
5 changes: 5 additions & 0 deletions blueman/main/Applet.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def do_quit(_: object) -> bool:

def do_startup(self) -> None:
Gtk.Application.do_startup(self)

quit_action = Gio.SimpleAction.new("Quit", None)
quit_action.connect("activate", lambda _action, _param: self.quit())
self.add_action(quit_action)

self.set_accels_for_action("win.close", ["<Ctrl>w", "Escape"])

def do_activate(self) -> None:
Expand Down
19 changes: 18 additions & 1 deletion blueman/main/DBusProxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,35 @@ def call_finish(proxy: ProxyBase, response: Gio.AsyncResult) -> None:
self.call(name, params, Gio.DBusCallFlags.NONE, -1, None, call_finish)


class DBus(ProxyBase):
def __init__(self) -> None:
super().__init__(name="org.freedesktop.DBus", interface_name="org.freedesktop.DBus",
object_path="/org/freedesktop/DBus")


class Mechanism(ProxyBase):
def __init__(self) -> None:
super().__init__(name='org.blueman.Mechanism', interface_name='org.blueman.Mechanism',
object_path="/org/blueman/mechanism", systembus=True)


class AppletService(ProxyBase):
NAME = "org.blueman.Applet"

def __init__(self) -> None:
super().__init__(name='org.blueman.Applet', interface_name='org.blueman.Applet',
super().__init__(name=self.NAME, interface_name='org.blueman.Applet',
object_path="/org/blueman/Applet")


class AppletServiceApplication(ProxyBase):
def __init__(self) -> None:
super().__init__(name=AppletService.NAME, interface_name="org.freedesktop.Application",
object_path="/org/blueman/Applet")

def stop(self) -> None:
self.ActivateAction('(sava{sv})', "Quit", [], {})


class ManagerService(ProxyBase):
def __init__(self) -> None:
super().__init__(name="org.blueman.Manager", interface_name="org.freedesktop.Application",
Expand Down
9 changes: 8 additions & 1 deletion blueman/main/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from blueman.gui.manager.ManagerStats import ManagerStats
from blueman.gui.manager.ManagerProgressbar import ManagerProgressbar
from blueman.main.Builder import Builder
from blueman.main.DBusProxies import AppletService, DBusProxyFailed
from blueman.main.DBusProxies import AppletService, DBusProxyFailed, DBus, AppletServiceApplication
from blueman.gui.CommonUi import ErrorDialog
from blueman.gui.Notification import Notification
from blueman.main.PluginManager import PluginManager
Expand All @@ -29,6 +29,7 @@
class Blueman(Gtk.Application):
def __init__(self) -> None:
super().__init__(application_id="org.blueman.Manager")
self._applet_was_running = DBus().NameHasOwner("(s)", AppletService.NAME)

def do_quit(_: object) -> bool:
self.quit()
Expand Down Expand Up @@ -60,6 +61,12 @@ def doquit(_a: Gio.SimpleAction, _param: None) -> None:
bt_status_action.connect("change-state", self._on_bt_state_changed)
self.add_action(bt_status_action)

def do_shutdown(self) -> None:
Gtk.Application.do_shutdown(self)

if not self._applet_was_running:
AppletServiceApplication().stop()

def do_activate(self) -> None:
if not self.window:
self.window = self.builder.get_widget("manager_window", Gtk.ApplicationWindow)
Expand Down

0 comments on commit fa74af2

Please sign in to comment.