comparison main.c @ 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, 11 Oct 2011 17:07:49 +0200
parents 58a3312a1c59
children 64f05992d8ec
comparison
equal deleted inserted replaced
8:58a3312a1c59 9:0e50d3652326
23 #include "notify.h" 23 #include "notify.h"
24 #include "packagekit.h" 24 #include "packagekit.h"
25 #include <locale.h> 25 #include <locale.h>
26 #include <glib/gi18n.h> 26 #include <glib/gi18n.h>
27 #include <gtk/gtk.h> 27 #include <gtk/gtk.h>
28 #include <unique/unique.h>
28 29
29 struct UpdatesInfo info; 30 struct UpdatesInfo info;
30 31
31 GtkStatusIcon *tray_icon; 32 GtkStatusIcon *tray_icon;
32 33
84 } 85 }
85 86
86 int main(int argc, char **argv) 87 int main(int argc, char **argv)
87 { 88 {
88 GtkStatusIcon *tray_icon; 89 GtkStatusIcon *tray_icon;
90 UniqueApp *app;
91 int exitval = 0;
89 92
90 setlocale(LC_ALL, ""); 93 setlocale(LC_ALL, "");
91 bindtextdomain(PACKAGE, LOCALEDIR); 94 bindtextdomain(PACKAGE, LOCALEDIR);
92 bind_textdomain_codeset(PACKAGE, "UTF-8"); 95 bind_textdomain_codeset(PACKAGE, "UTF-8");
93 textdomain(PACKAGE); 96 textdomain(PACKAGE);
94 97
95 gtk_init(&argc, &argv); 98 gtk_init(&argc, &argv);
99 app = unique_app_new(APP_NAME, NULL);
100 if (unique_app_is_running(app)) {
101 g_printerr("Another instance of pk-update-icon is already running. Exiting.\n");
102 exitval = 1;
103 goto out;
104 }
96 tray_icon = create_tray_icon(); 105 tray_icon = create_tray_icon();
97 init_notify(); 106 init_notify();
98 107
99 periodic_check(NULL); 108 periodic_check(NULL);
100 send_notify(&info); 109 send_notify(&info);
101 // update tray icon and tooltip every 2 hours 110 // update tray icon and tooltip every 2 hours
102 g_timeout_add_seconds(2*3600, periodic_check, NULL); 111 g_timeout_add_seconds(2*3600, periodic_check, NULL);
103 112
104 gtk_main(); 113 gtk_main();
105 114
106 return 0; 115 g_object_unref(tray_icon);
116
117 out:
118 g_object_unref(app);
119
120 return exitval;
107 } 121 }