projects/pk-update-icon

changeset 9:0e50d3652326

use libunique to ensure that only a single instance of pk-update-icon can be run
author Guido Berhoerster <guido@berhoerster.name>
date Tue Oct 11 17:07:49 2011 +0200 (2011-10-11)
parents 58a3312a1c59
children fe1a21ab4f69
files Makefile main.c
line diff
     1.1 --- a/Makefile	Tue Oct 11 17:07:49 2011 +0200
     1.2 +++ b/Makefile	Tue Oct 11 17:07:49 2011 +0200
     1.3 @@ -15,16 +15,18 @@
     1.4  xdgautostartdir ?=	$(sysconfdir)/xdg/autostart
     1.5  
     1.6  PACKAGE =	pk-update-icon
     1.7 +APP_NAME =	org.opensuse.pk-update-icon
     1.8  VERSION =	0.1
     1.9  OBJS =		main.o notify.o packagekit.o
    1.10  AUTOSTART_FILE =	$(PACKAGE).desktop
    1.11  MOFILES :=	$(patsubst %.po,%.mo,$(wildcard po/*.po))
    1.12  POTFILE =	po/$(PACKAGE).pot
    1.13 -CPPFLAGS :=	$(shell pkg-config --cflags gtk+-2.0 libnotify packagekit-glib2) \
    1.14 +CPPFLAGS := 	$(shell pkg-config --cflags gtk+-2.0 unique-1.0 libnotify packagekit-glib2) \
    1.15  		-DI_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE \
    1.16  		-DPACKAGE="\"$(PACKAGE)\"" \
    1.17 +		-DAPP_NAME=\"$(APP_NAME)\" \
    1.18  		-DLOCALEDIR="\"$(localedir)\""
    1.19 -LDLIBS :=	$(shell pkg-config --libs gtk+-2.0 libnotify packagekit-glib2)
    1.20 +LDLIBS :=	$(shell pkg-config --libs gtk+-2.0 unique-1.0 libnotify packagekit-glib2)
    1.21  
    1.22  .DEFAULT_TARGET = all
    1.23  
     2.1 --- a/main.c	Tue Oct 11 17:07:49 2011 +0200
     2.2 +++ b/main.c	Tue Oct 11 17:07:49 2011 +0200
     2.3 @@ -25,6 +25,7 @@
     2.4  #include <locale.h>
     2.5  #include <glib/gi18n.h>
     2.6  #include <gtk/gtk.h>
     2.7 +#include <unique/unique.h>
     2.8  
     2.9  struct UpdatesInfo info;
    2.10  
    2.11 @@ -86,6 +87,8 @@
    2.12  int main(int argc, char **argv)
    2.13  {
    2.14  	GtkStatusIcon *tray_icon;
    2.15 +	UniqueApp *app;
    2.16 +	int exitval = 0;
    2.17  
    2.18  	setlocale(LC_ALL, "");
    2.19  	bindtextdomain(PACKAGE, LOCALEDIR);
    2.20 @@ -93,6 +96,12 @@
    2.21  	textdomain(PACKAGE);
    2.22  
    2.23  	gtk_init(&argc, &argv);
    2.24 +	app = unique_app_new(APP_NAME, NULL);
    2.25 +	if (unique_app_is_running(app)) {
    2.26 +		g_printerr("Another instance of pk-update-icon is already running. Exiting.\n");
    2.27 +		exitval = 1;
    2.28 +		goto out;
    2.29 +	}
    2.30  	tray_icon = create_tray_icon();
    2.31  	init_notify();
    2.32  
    2.33 @@ -103,5 +112,10 @@
    2.34  
    2.35  	gtk_main();
    2.36  
    2.37 -	return 0;
    2.38 +	g_object_unref(tray_icon);
    2.39 +
    2.40 +out:
    2.41 +	g_object_unref(app);
    2.42 +
    2.43 +	return exitval;
    2.44  }