# HG changeset patch # User Guido Berhoerster # Date 1318345669 -7200 # Node ID 0e50d36523260780f475711c4e5865845839eded # Parent 58a3312a1c596d640797a2daeafbae9037a874ec use libunique to ensure that only a single instance of pk-update-icon can be run diff -r 58a3312a1c59 -r 0e50d3652326 Makefile --- a/Makefile Tue Oct 11 17:07:49 2011 +0200 +++ b/Makefile Tue Oct 11 17:07:49 2011 +0200 @@ -15,16 +15,18 @@ xdgautostartdir ?= $(sysconfdir)/xdg/autostart PACKAGE = pk-update-icon +APP_NAME = org.opensuse.pk-update-icon VERSION = 0.1 OBJS = main.o notify.o packagekit.o AUTOSTART_FILE = $(PACKAGE).desktop MOFILES := $(patsubst %.po,%.mo,$(wildcard po/*.po)) POTFILE = po/$(PACKAGE).pot -CPPFLAGS := $(shell pkg-config --cflags gtk+-2.0 libnotify packagekit-glib2) \ +CPPFLAGS := $(shell pkg-config --cflags gtk+-2.0 unique-1.0 libnotify packagekit-glib2) \ -DI_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE \ -DPACKAGE="\"$(PACKAGE)\"" \ + -DAPP_NAME=\"$(APP_NAME)\" \ -DLOCALEDIR="\"$(localedir)\"" -LDLIBS := $(shell pkg-config --libs gtk+-2.0 libnotify packagekit-glib2) +LDLIBS := $(shell pkg-config --libs gtk+-2.0 unique-1.0 libnotify packagekit-glib2) .DEFAULT_TARGET = all diff -r 58a3312a1c59 -r 0e50d3652326 main.c --- a/main.c Tue Oct 11 17:07:49 2011 +0200 +++ b/main.c Tue Oct 11 17:07:49 2011 +0200 @@ -25,6 +25,7 @@ #include #include #include +#include struct UpdatesInfo info; @@ -86,6 +87,8 @@ int main(int argc, char **argv) { GtkStatusIcon *tray_icon; + UniqueApp *app; + int exitval = 0; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); @@ -93,6 +96,12 @@ textdomain(PACKAGE); gtk_init(&argc, &argv); + app = unique_app_new(APP_NAME, NULL); + if (unique_app_is_running(app)) { + g_printerr("Another instance of pk-update-icon is already running. Exiting.\n"); + exitval = 1; + goto out; + } tray_icon = create_tray_icon(); init_notify(); @@ -103,5 +112,10 @@ gtk_main(); - return 0; + g_object_unref(tray_icon); + +out: + g_object_unref(app); + + return exitval; }