Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore shutdown #631

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
<property name="use_underline">True</property>
<property name="xalign">0.5</property>
<property name="draw_indicator">True</property>
<property name="has_tooltip">True</property>
<property name="tooltip_text" translatable="yes">Work only on GNOME</property>
sgranjoux marked this conversation as resolved.
Show resolved Hide resolved
</object>
<packing>
<property name="expand">False</property>
Expand Down
60 changes: 32 additions & 28 deletions src/hamster/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# along with Project Hamster. If not, see <http://www.gnu.org/licenses/>.

import dbus
import logging
logger = logging.getLogger(__name__)

class DbusSessionListener(object):
"""Listen for GNOME manager end session event."""
Expand All @@ -35,34 +37,36 @@ def __init__(self):

# Get SessionManager interface
session_bus = dbus.SessionBus()
session_manager = session_bus.get_object("org.gnome.SessionManager",
"/org/gnome/SessionManager")
self.__session_manager_iface = dbus.Interface(session_manager,
dbus_interface="org.gnome.SessionManager")
self.__client_id = self.__session_manager_iface.RegisterClient("", "")

# Get SessionManager.ClientPrivate interface
session_client = session_bus.get_object("org.gnome.SessionManager",
self.__client_id)
self.__session_client_private_iface = dbus.Interface(session_client,
dbus_interface="org.gnome.SessionManager.ClientPrivate")

# Connect to the needed signals
session_bus.add_signal_receiver(self.__query_end_session_handler,
signal_name = "QueryEndSession",
dbus_interface = "org.gnome.SessionManager.ClientPrivate",
bus_name = "org.gnome.SessionManager")

session_bus.add_signal_receiver(self.__end_session_handler,
signal_name = "EndSession",
dbus_interface = "org.gnome.SessionManager.ClientPrivate",
bus_name = "org.gnome.SessionManager")

session_bus.add_signal_receiver(self.__stop_handler,
signal_name = "Stop",
dbus_interface = "org.gnome.SessionManager.ClientPrivate",
bus_name = "org.gnome.SessionManager")

try:
session_manager = session_bus.get_object("org.gnome.SessionManager",
"/org/gnome/SessionManager")
self.__session_manager_iface = dbus.Interface(session_manager,
dbus_interface="org.gnome.SessionManager")
self.__client_id = self.__session_manager_iface.RegisterClient("", "")

# Get SessionManager.ClientPrivate interface
session_client = session_bus.get_object("org.gnome.SessionManager",
self.__client_id)
self.__session_client_private_iface = dbus.Interface(session_client,
dbus_interface="org.gnome.SessionManager.ClientPrivate")

# Connect to the needed signals
session_bus.add_signal_receiver(self.__query_end_session_handler,
signal_name = "QueryEndSession",
dbus_interface = "org.gnome.SessionManager.ClientPrivate",
bus_name = "org.gnome.SessionManager")

session_bus.add_signal_receiver(self.__end_session_handler,
signal_name = "EndSession",
dbus_interface = "org.gnome.SessionManager.ClientPrivate",
bus_name = "org.gnome.SessionManager")

session_bus.add_signal_receiver(self.__stop_handler,
signal_name = "Stop",
dbus_interface = "org.gnome.SessionManager.ClientPrivate",
bus_name = "org.gnome.SessionManager")
except dbus.exceptions.DBusException:
logger.warning("Unable to connect to GNOME session manager, stop trcking on logout won't work")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please either make this logger.info() or just replace this line with pass so command line users don't see this message on every single command (because warning is the default logging level). Also trcking -> tracking.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have changed it but I think this message will appear only when your start the hamster daemon so probably not on each command.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, I forgot that I was using a cover script that restart the daemon before each command. Thanks anyway.


def __query_end_session_handler(self, flags):
"""Inform that the session is about to end. It must reply with
Expand Down