1#!/usr/local/bin/python3.8 2# 3""" Launches or restarts cinnamon 4""" 5 6import os 7import sys 8import gettext 9from setproctitle import setproctitle 10 11import gi 12gi.require_version('Gtk', '3.0') # noqa 13from gi.repository import Gtk 14 15FALLBACK_COMMAND = "metacity" 16FALLBACK_ARGS = ("--replace",) 17 18gettext.install("cinnamon", "/usr/local/share/locale") 19 20panel_process_name = None 21panel_cmd = None 22if os.path.exists("/usr/local/bin/mate-panel"): 23 panel_process_name = "mate-panel" 24 panel_cmd = "mate-panel --replace &" 25elif os.path.exists("/usr/local/bin/gnome-panel"): 26 panel_process_name = "gnome-panel" 27 panel_cmd = "gnome-panel --replace &" 28elif os.path.exists("/usr/local/bin/tint2"): 29 panel_process_name = "tint2" 30 panel_cmd = "killall tint2; tint2 &" 31 32 33def confirm_restart(): 34 d = Gtk.MessageDialog(title=None, parent=None, flags=0, message_type=Gtk.MessageType.WARNING) 35 d.add_buttons(_("No"), Gtk.ResponseType.NO, 36 _("Yes"), Gtk.ResponseType.YES) 37 d.set_keep_above(True) 38 d.set_position(Gtk.WindowPosition.CENTER) 39 d.set_title(_("Cinnamon just crashed")) 40 box = d.get_content_area() 41 checkbutton = Gtk.CheckButton(label=_("Disable downloaded applets, desklets and extensions")) 42 d.set_markup("<span size='large'><b>%s</b></span>\n\n%s\n\n%s\n\n" % 43 ( 44 _("You are currently running in fallback mode."), 45 _("If you suspect the source of the crash is a local extension, applet or desklet, you can disable downloaded add-ons using the checkbox below."), 46 _("Do you want to restart Cinnamon?"), 47 )) 48 box.set_border_width(20) 49 box.add(checkbutton) 50 checkbutton.show_all() 51 resp = d.run() 52 d.destroy() 53 if resp == Gtk.ResponseType.YES: 54 if checkbutton.get_active(): 55 os.environ["CINNAMON_TROUBLESHOOT"] = "1" 56 return(True) 57 return(False) 58 59if __name__ == "__main__": 60 setproctitle("cinnamon-launcher") 61 cinnamon_pid = os.fork() 62 if cinnamon_pid == 0: 63 os.execvp("cinnamon", ("cinnamon", "--replace", ) + tuple(sys.argv[1:])) 64 else: 65 exit_status = os.waitpid(cinnamon_pid, 0)[1] 66 if exit_status != 0: 67 if os.fork() == 0: 68 # Start the fallback panel 69 if panel_cmd is not None: 70 os.system(panel_cmd) 71 # Start the fallback window manager 72 os.execvp(FALLBACK_COMMAND, (FALLBACK_COMMAND,) + FALLBACK_ARGS) 73 else: 74 if confirm_restart(): 75 # Kill the fallback panel 76 os.system("killall %s" % panel_process_name) 77 # Restart Cinnamon 78 os.execvp(sys.argv[0], (sys.argv[0], "--replace")) 79