[gnome-session/wip/desktop-generator: 2/2] wip! generate service files from desktop files
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-session/wip/desktop-generator: 2/2] wip! generate service files from desktop files
- Date: Fri, 6 Nov 2015 18:10:51 +0000 (UTC)
commit 680cd621c0b526c2ceab760a7cf52831bb518b6f
Author: Ray Strode <rstrode redhat com>
Date: Fri Nov 6 13:06:58 2015 -0500
wip! generate service files from desktop files
tools/Makefile.am | 14 +++
tools/gnome-session-desktop-app-generator.c | 142 +++++++++++++++++++++++++++
2 files changed, 156 insertions(+), 0 deletions(-)
---
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 57b82c7..57940b9 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -41,6 +41,20 @@ gnome_session_inhibit_CPPFLAGS = \
gnome_session_inhibit_LDADD = \
$(GNOME_SESSION_LIBS)
+if HAVE_SYSTEMD
+gnome_session_desktop_app_generator_LDADD = \
+ $(GIO_LIBS)
+
+gnome_session_desktop_app_generator_SOURCES = \
+ gnome-session-desktop-app-generator.c
+
+generatordir=$(prefix)/lib/systemd/user-generators
+
+gnome-session-desktop-app-generator-install-hook:
+ $(MKDIR_P) $(DESTDIR)$(generatordir)
+ -rm -f $(DESTDIR)$(generatordir)/gnome-session-desktop-app-generator
+#endif
+
gnome_session_check_accelerated_helper_SOURCES = \
gnome-session-check-accelerated-common.h \
gnome-session-check-accelerated-helper.c
diff --git a/tools/gnome-session-desktop-app-generator.c b/tools/gnome-session-desktop-app-generator.c
new file mode 100644
index 0000000..aa77a39
--- /dev/null
+++ b/tools/gnome-session-desktop-app-generator.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <config.h>
+
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+static void
+write_unit_file_for_app_info (const char *unit_dir,
+ GDesktopAppInfo *app_info)
+{
+ gboolean activatable;
+ char *contents;
+ gboolean contents_set;
+ GError *error = NULL;
+ const char *source_path, *name, *description, *exec_binary;
+ g_autofree char *desktop_id = NULL, *unit_path = NULL, *unit_file = NULL, *exec_line = NULL;
+
+ source_path = g_desktop_app_info_get_filename (app_info);
+
+ if (source_path == NULL) {
+ return;
+ }
+
+ desktop_id = g_path_get_basename (source_path);
+
+ activatable = g_desktop_app_info_get_boolean (app_info, G_KEY_FILE_DESKTOP_KEY_DBUS_ACTIVATABLE);
+
+ /* skip apps that are supposed to be bus activated */
+ if (activatable && g_dbus_is_name (desktop_id)) {
+ return;
+ }
+
+ name = g_app_info_get_display_name (G_APP_INFO (app_info));
+
+ if (name == NULL) {
+ return;
+ }
+
+ description = g_app_info_get_description (G_APP_INFO (app_info));
+
+ if (description == NULL) {
+ description = "";
+ }
+
+ exec_line = g_strdup (g_app_info_get_commandline (G_APP_INFO (app_info)));
+
+ if (exec_line == NULL) {
+ return;
+ }
+
+ exec_binary = g_app_info_get_executable (G_APP_INFO (app_info));
+
+ if (!g_path_is_absolute (exec_binary)) {
+ gint argc;
+ char **argv;
+ char *absolute_exec_binary;
+ char *new_exec_line;
+
+ if (!g_str_has_prefix (exec_line, exec_binary)) {
+ return;
+ }
+ absolute_exec_binary = g_find_program_in_path (exec_binary);
+
+ if (!absolute_exec_binary) {
+ return;
+ }
+
+ new_exec_line = g_strjoin ("", absolute_exec_binary,
+ exec_line + strlen (exec_binary));
+ g_free (exec_line);
+ exec_line = new_exec_line;
+ }
+
+ contents = g_string_printf (contents,
+ "# Automatically generated by gnome-session-desktop-app-generator\n"
+ "\n"
+ "[Unit]\n"
+ "SourcePath=%s\n"
+ "Description=Desktop Application: %s: %s\n"
+ "\n"
+ "[Service]\n"
+ "ExecStart=%s\n"
+ "Type=simple\n"
+ source_path,
+ name,
+ description,
+ exec_line);
+
+ unit_file = g_strdup_printf ("desktop-app-%s.service", desktop_id);
+ unit_path = g_build_filename (unit_dir, unit_file, NULL);
+ contents_set = g_file_set_contents (unit_path, contents->str, contents->len, &error);
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ char *unit_dir;
+ GList *app_infos, *node;
+
+ if (argc != 4) {
+ g_error ("generator called with incorrect arguments");
+ return 1;
+ }
+
+ unit_dir = argv[3];
+
+ app_infos = g_app_info_get_all ();
+
+ for (node = app_infos; node != NULL; node = node->next) {
+ GDesktopAppInfo *app_info;
+
+ if (!G_IS_DESKTOP_APP_INFO (node->data)) {
+ continue;
+ }
+
+ app_info = G_DESKTOP_APP_INFO (node->data);
+
+ write_unit_file_for_app_info (unit_dir, app_info);
+ }
+
+ g_list_free_full (app_infos, g_object_unref);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]