Blame SOURCES/0003-AutostartFile-add-support-to-create-a-user-autostart.patch

2b55cd
From e0ce8256d7c58f19d601cf11bb08ac701d04af7a Mon Sep 17 00:00:00 2001
2b55cd
From: Rui Matos <tiagomatos@gmail.com>
2b55cd
Date: Sat, 15 Feb 2014 17:08:48 +0100
2b55cd
Subject: [PATCH 03/12] AutostartFile: add support to create a user autostart
2b55cd
 file
2b55cd
2b55cd
If no appinfo is provided on the constructor we enter a mode where
2b55cd
we'll try to create the .desktop file in the user's autostart
2b55cd
directory.
2b55cd
2b55cd
https://bugzilla.gnome.org/show_bug.cgi?id=715022
2b55cd
---
2b55cd
 gtweak/utils.py | 27 +++++++++++++++++++++++----
2b55cd
 1 file changed, 23 insertions(+), 4 deletions(-)
2b55cd
2b55cd
diff --git a/gtweak/utils.py b/gtweak/utils.py
2b55cd
index 3d20425..9907adc 100644
2b55cd
--- a/gtweak/utils.py
2b55cd
+++ b/gtweak/utils.py
2b55cd
@@ -136,8 +136,17 @@ class AutostartManager:
2b55cd
 
2b55cd
 class AutostartFile:
2b55cd
     def __init__(self, appinfo, autostart_desktop_filename="", exec_cmd="", extra_exec_args=""):
2b55cd
-        self._desktop_file = appinfo.get_filename()
2b55cd
-        self._autostart_desktop_filename = autostart_desktop_filename or os.path.basename(self._desktop_file)
2b55cd
+        if appinfo:
2b55cd
+            self._desktop_file = appinfo.get_filename()
2b55cd
+            self._autostart_desktop_filename = autostart_desktop_filename or os.path.basename(self._desktop_file)
2b55cd
+            self._create_file = False
2b55cd
+        elif autostart_desktop_filename:
2b55cd
+            self._desktop_file = None
2b55cd
+            self._autostart_desktop_filename = autostart_desktop_filename
2b55cd
+            self._create_file = True
2b55cd
+        else:
2b55cd
+            raise Exception("Need either an appinfo or a file name")
2b55cd
+
2b55cd
         self._exec_cmd = exec_cmd
2b55cd
         self._extra_exec_args = " %s\n" % extra_exec_args
2b55cd
 
2b55cd
@@ -150,9 +159,16 @@ class AutostartFile:
2b55cd
 
2b55cd
         self._user_autostart_file = os.path.join(user_autostart_dir, self._autostart_desktop_filename)
2b55cd
 
2b55cd
-        logging.debug("Found desktop file: %s" % self._desktop_file)
2b55cd
+        if self._desktop_file:
2b55cd
+            logging.debug("Found desktop file: %s" % self._desktop_file)
2b55cd
         logging.debug("User autostart desktop file: %s" % self._user_autostart_file)
2b55cd
 
2b55cd
+    def _create_user_autostart_file(self):
2b55cd
+        f = open(self._user_autostart_file, "w")
2b55cd
+        f.write("[Desktop Entry]\nType=Application\nName=%s\nExec=%s\n" %
2b55cd
+                (self._autostart_desktop_filename[0:-len('.desktop')], self._exec_cmd + self._extra_exec_args))
2b55cd
+        f.close()
2b55cd
+
2b55cd
     def is_start_at_login_enabled(self):
2b55cd
         if os.path.exists(self._user_autostart_file):
2b55cd
             #prefer user directories first
2b55cd
@@ -175,7 +191,10 @@ class AutostartFile:
2b55cd
 
2b55cd
         if update:
2b55cd
             if (not self._desktop_file) or (not os.path.exists(self._desktop_file)):
2b55cd
-                logging.critical("Could not find desktop file: %s" % self._desktop_file)
2b55cd
+                if self._create_file:
2b55cd
+                    self._create_user_autostart_file()
2b55cd
+                else:
2b55cd
+                    logging.critical("Could not find desktop file: %s" % self._desktop_file)
2b55cd
                 return
2b55cd
 
2b55cd
             logging.info("Adding autostart %s" % self._user_autostart_file)
2b55cd
-- 
2b55cd
2.3.6
2b55cd