Пример #1
0
 def run(self):
     app = read_desktop_file(self.filename)
     logger.info('Run application %s (%s)', app.get_name(), self.filename)
     try:
         app.launch()
     except Exception as e:
         logger.error('%s: %s', type(e).__name__, e)
Пример #2
0
    def _add_file_sync(self, pathname: str) -> None:
        """
        Add .desktop file to DB

        Raises self.InvalidDesktopFile if failed to add an app
        """

        # get filename of the desktop file (i.e chromium.desktop)
        file_name = os.path.basename(pathname)
        # search for desktop file in all of DESKTOP_DIRS
        pathnames_in_xdg_dirs = list(find_desktop_files(DESKTOP_DIRS, file_name))
        # if the pathname is not found in the desktop files it is overridden
        # with a file of the same name in a different XDG directory, so skip
        # trying to add this desktop file
        if pathname not in pathnames_in_xdg_dirs:
            logger.warning('Skipping adding %s to DB -> desktop file overridden in a different XDG directory', pathname)
            raise self.SkipDesktopFile(pathname)

        try:
            app = read_desktop_file(pathname)
            if filter_app(app, disable_desktop_filters):
                self.__db.put_app(app)
                logger.info('New app was added "%s" (%s)', app.get_name(), app.get_filename())
            else:
                raise self.InvalidDesktopFile(pathname)
        except Exception as e:
            logger.warning('Cannot add %s to DB -> %s', pathname, e)
            raise self.InvalidDesktopFile(pathname)
Пример #3
0
    def run(self):
        app = read_desktop_file(self.filename)
        app_id = Path(self.filename).with_suffix('').stem
        exec = app.get_string('Exec')
        if not exec:
            logger.error("No command to run %s", self.filename)
        else:
            # strip field codes %f, %F, %u, %U, etc
            sanitized_exec = re.sub(r'\%[uUfFdDnNickvm]', '', exec).rstrip()
            terminal_exec = shlex.split(
                settings.get_property('terminal-command'))
            if app.get_boolean('Terminal'):
                if terminal_exec:
                    logger.info('Will run command in preferred terminal (%s)',
                                terminal_exec)
                    sanitized_exec = terminal_exec + [sanitized_exec]
                else:
                    sanitized_exec = ['gtk-launch', app_id]
            else:
                sanitized_exec = shlex.split(sanitized_exec)
            if runs_in_systemd and not app.get_boolean(
                    'X-Ulauncher-Inherit-Scope'):
                logger.warning(
                    "Will attempt to launch the app using systemd-run with --scope argument"
                )
                logger.warning(
                    "This prevents the apps from terminating if Ulauncher crashes or is restarted."
                )
                logger.warning(
                    "On some systems with outdated systemd or incorrect permissions this doesn't work."
                )
                logger.warning(
                    "If this happens to you, don't run Ulauncher from systemd."
                )
                sanitized_exec = [
                    'systemd-run',
                    '--user',
                    '--scope',
                ] + sanitized_exec

            env = dict(os.environ.items())
            # Make sure GDK apps aren't forced to use x11 on wayland due to ulauncher's need to run
            # under X11 for proper centering.
            env.pop("GDK_BACKEND", None)

            try:
                logger.info('Run application %s (%s) Exec %s', app.get_name(),
                            self.filename, exec)
                envp = ["{}={}".format(k, v) for k, v in env.items()]
                GLib.spawn_async(
                    argv=sanitized_exec,
                    envp=envp,
                    flags=GLib.SpawnFlags.SEARCH_PATH_FROM_ENVP
                    | GLib.SpawnFlags.SEARCH_PATH,
                    # setsid is really only needed if systemd-run is missing, but doesn't hurt to have.
                    child_setup=os.setsid)
            except Exception as e:
                logger.error('%s: %s', type(e).__name__, e)
Пример #4
0
 def run(self):
     app = read_desktop_file(self.filename)
     command = app.get_string('Exec')
     terminal_exec = settings.get_property('terminal-command')
     if app.get_boolean('Terminal') and terminal_exec and command:
         logger.info('Run command %s (%s) in preferred terminal (%s)',
                     command, self.filename, terminal_exec)
         subprocess.Popen(terminal_exec.split() + [pipes.quote(command)])
     else:
         logger.info('Run application %s (%s)', app.get_name(),
                     self.filename)
         try:
             app.launch()
         except Exception as e:
             logger.error('%s: %s', type(e).__name__, e)
Пример #5
0
    def _add_file_sync(self, pathname: str) -> None:
        """
        Add .desktop file to DB

        Raises self.InvalidDesktopFile if failed to add an app
        """
        try:
            app = read_desktop_file(pathname)
            if filter_app(app):
                self.__db.put_app(app)
                logger.info('New app was added "%s" (%s)', app.get_name(), app.get_filename())
            else:
                raise self.InvalidDesktopFile(pathname)
        except Exception as e:
            logger.warning('Cannot add %s to DB -> %s', pathname, e)
            raise self.InvalidDesktopFile(pathname)
Пример #6
0
 def run(self):
     app = read_desktop_file(self.filename)
     logger.info('Run application %s (%s)', app.get_name(), self.filename)
     app.launch()