Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ CMakeLists.txt
debian/*.debhelper.log
debian/*.substvars
debian/.debhelper/
debian/*.debhelper
debian/cinnamon-session-common/
debian/cinnamon-session/
debian/debhelper-build-stamp
Expand Down
90 changes: 55 additions & 35 deletions cinnamon-session-quit/cinnamon-session-quit.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ def __init__(self):
parser.add_argument("--no-prompt", dest="no_prompt", action='store_true',
help=_("Don't prompt for user confirmation"))
parser.add_argument("--sm-owned", action="store_true", help=argparse.SUPPRESS)
parser.add_argument("--sm-bus-id", dest="bus_id", action="store", help=argparse.SUPPRESS, default=config.DBUS_ADDRESS)

# unused in 6.4+, kept only for upgrade session (running c-s process is previous version, dialog is new)
parser.add_argument("--sm-bus-id", dest="bus_id", action="store", help=argparse.SUPPRESS, default=None)

args = parser.parse_args()

self.dialog_response = ResponseCode.NONE
Expand All @@ -76,11 +79,7 @@ def __init__(self):
self.force = args.force
self.no_prompt = args.no_prompt
self.sm_owned = args.sm_owned

if self.sm_owned:
self.bus_id = args.bus_id
else:
self.bus_id = None
self.bus_id = args.bus_id

self.proxy = None
self.signal_handler_id = 0
Expand Down Expand Up @@ -118,7 +117,7 @@ def async_cb(proxy, res):
proxy.call_finish(res)
# self.quit()
except GLib.Error as e:
print("An error occurred forwarding to the session manager: %s" % e.message)
print("An error occurred forwarding to the session manager: %s" % e.message, file=sys.stderr, end=None)

if self.mode == Action.LOGOUT:
arg = LogoutParams.NORMAL
Expand Down Expand Up @@ -156,7 +155,7 @@ def async_cb(proxy, res):
)
except GLib.Error as e:
if sm_proxy is None:
print("Could not forward to org.cinnamon.SessionManager.Manager: %s" % e.message)
print("Could not forward to org.cinnamon.SessionManager.Manager: %s" % e.message, file=sys.stderr, end=None)
sys.exit(1)

sys.exit(0)
Expand All @@ -169,40 +168,52 @@ def setup_proxy(self):
connection = None

try:
connection = Gio.DBusConnection.new_for_address_sync(
self.bus_id,
Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT,
None, None
)
# 6.4 and later this will always be None, obsolete connection
if self.bus_id is not None:
connection = Gio.DBusConnection.new_for_address_sync(
self.bus_id,
Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT,
None, None
)

self.proxy = Gio.DBusProxy.new_sync(
connection,
Gio.DBusProxyFlags.DO_NOT_AUTO_START,
None,
None,
"/org/gnome/SessionManager",
"org.cinnamon.SessionManager.DialogPrivate",
None
)
self.proxy = Gio.DBusProxy.new_sync(
connection,
Gio.DBusProxyFlags.DO_NOT_AUTO_START,
None,
None,
"/org/gnome/SessionManager",
"org.cinnamon.SessionManager.DialogPrivate",
None
)
else:
self.proxy = Gio.DBusProxy.new_for_bus_sync(
Gio.BusType.SESSION,
Gio.DBusProxyFlags.DO_NOT_AUTO_START,
None,
"org.gnome.SessionManager",
"/org/gnome/SessionManager",
"org.cinnamon.SessionManager.EndSessionDialog",
None
)

self.proxy.connect("g-signal", self.inhibitor_info_received)

except GLib.Error as e:
if connection is None:
print("Could not connect to session dialog server: %s" % e.message)
print("Could not connect to session dialog server: %s" % e.message, file=sys.stderr, end=None)
sys.exit(1)
if self.proxy is None:
print("Could not create proxy to session dialog interface: %s" % e.message)
print("Could not create proxy to session dialog interface: %s" % e.message, file=sys.stderr, end=None)
sys.exit(1)

def inhibitor_info_received(self, proxy, sender, signal, params):
inhibitors = params[0]

if self.dialog_response == ResponseCode.NONE:
print("Ignoring inhibitor info, still waiting on initial response from user")
print("Ignoring inhibitor info, still waiting on initial response from user", file=sys.stderr, end=None)
return

print("Inhibitor info received (%d inhibitors)" % len(inhibitors))
print("Inhibitor info received (%d inhibitors): %s" % (len(inhibitors), params), file=sys.stderr, end=None)

if inhibitors:
self.inhibited = True
Expand Down Expand Up @@ -243,8 +254,10 @@ def run_dialog(self):
self.view_stack = self.builder.get_object("view_stack")
self.inhibitor_treeview = self.builder.get_object("inhibitor_treeview")

can_switch_user, can_stop, can_restart, can_hybrid_sleep, can_suspend, can_hibernate, can_logout = self.get_session_capabilities()

try:
can_switch_user, can_stop, can_restart, can_hybrid_sleep, can_suspend, can_hibernate, can_logout = self.get_session_capabilities()
except Exception as e:
print(e, file=sys.stderr, end=None)
default_button = None

if self.mode == Action.LOGOUT:
Expand All @@ -265,7 +278,7 @@ def run_dialog(self):
self.window.set_icon_name("system-shutdown")
elif self.mode == Action.RESTART:
if not can_restart:
print("Restart not available")
print("Restart not available", file=sys.stderr, end=None)
Gtk.main_quit()
return
self.dialog_label.set_text(_("Restart this system now?"))
Expand Down Expand Up @@ -304,7 +317,7 @@ def get_session_capabilities(self):
)
return caps[0]
except GLib.Error as e:
print("Could not retrieve session capabilities: %s" % e.message)
print("Could not retrieve session capabilities: %s" % e.message, file=sys.stderr, end=None)

def start_timer(self):
if self.timer_id > 0:
Expand All @@ -315,6 +328,11 @@ def start_timer(self):
self.update_timer()
GLib.timeout_add(1000, self.update_timer)

def stop_timer(self):
if self.timer_id > 0:
GLib.source_remove(self.timer_id)
self.timer_id = 0

def update_timer(self):
if self.current_time == 0:
self.handle_response(self.window, self.default_response)
Expand Down Expand Up @@ -347,15 +365,17 @@ def update_timer(self):
return GLib.SOURCE_CONTINUE

def handle_response(self, dialog, code):
self.stop_timer()

self.view_stack.set_visible_child_name("busy")

if self.inhibited:
if code == ResponseCode.CONTINUE:
print("Sending ignore inhibitors")
print("Sending ignore inhibitors", file=sys.stderr, end=None)
self.send_command("IgnoreInhibitors")
self.finish_up()
elif code in (ResponseCode.CANCEL, Gtk.ResponseType.NONE, Gtk.ResponseType.DELETE_EVENT):
print("Canceling action during inhibit phase")
print("Canceling action during inhibit phase", file=sys.stderr, end=None)
self.send_command("Cancel")
self.quit()
return
Expand All @@ -378,7 +398,7 @@ def handle_response(self, dialog, code):
self.send_command("Cancel")
self.quit(0)
else:
print("Invalid response code: %d" % code)
print("Invalid response code: %d" % code, file=sys.stderr, end=None)

def send_command(self, command):
try:
Expand All @@ -391,7 +411,7 @@ def send_command(self, command):
None
)
except GLib.Error as e:
print("Could not send command '%s' to session manager: %s" % (str(command), e.message))
print("Could not send command '%s' to session manager: %s" % (str(command), e.message), file=sys.stderr, end=None)

self.command_sent = True
# wait for inhibit info
Expand All @@ -409,7 +429,7 @@ def show_inhibit_view(self, info):
self.view_stack.set_visible_child_name("inhibit")

def on_terminate(self, data=None):
print("Received SIGTERM from cinnamon-session, exiting")
print("Received SIGTERM from cinnamon-session, exiting", file=sys.stderr, end=None)
self.quit(0)

def finish_up(self):
Expand Down
1 change: 0 additions & 1 deletion cinnamon-session-quit/config.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
LOCALE_DIR=@LOCALE_DIR@
PACKAGE=@PACKAGE@
VERSION=@VERSION@
DBUS_ADDRESS=@DBUS_ADDRESS@
PKG_DATADIR=@PKG_DATADIR@
1 change: 0 additions & 1 deletion cinnamon-session-quit/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ csq_conf.set_quoted('LOCALE_DIR', join_paths(get_option('prefix'), get_option('l
csq_conf.set_quoted('PACKAGE', meson.project_name())
csq_conf.set_quoted('VERSION', meson.project_version())
csq_conf.set_quoted('PKG_DATADIR', pkg_datadir)
csq_conf.set_quoted('DBUS_ADDRESS', dialog_dbus_address)

config_py = configure_file(
output: 'config.py',
Expand Down
Loading
Loading