diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b390cdd4..45743ecf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## main + +### Changes + +* Terminate applet on manager termination if it was started by manager + ## 2.4.2 ### New features diff --git a/blueman/main/Applet.py b/blueman/main/Applet.py index 9e51f9d9f..9986c6494 100644 --- a/blueman/main/Applet.py +++ b/blueman/main/Applet.py @@ -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", ["w", "Escape"]) def do_activate(self) -> None: diff --git a/blueman/main/DBusProxies.py b/blueman/main/DBusProxies.py index 599ff1665..5f259b085 100644 --- a/blueman/main/DBusProxies.py +++ b/blueman/main/DBusProxies.py @@ -43,6 +43,12 @@ 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', @@ -50,11 +56,22 @@ def __init__(self) -> None: 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", diff --git a/blueman/main/Manager.py b/blueman/main/Manager.py index 8ec24fa6a..bf1bcc2db 100644 --- a/blueman/main/Manager.py +++ b/blueman/main/Manager.py @@ -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 @@ -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() @@ -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)