try to display tray bar icon
[psensor.git] / src / main.c
index 9d89c01..aaff079 100644 (file)
@@ -135,18 +135,6 @@ update_psensor_values_size(struct psensor **sensors, struct config *cfg)
        }
 }
 
-static void log_measures(struct psensor **sensors)
-{
-       if (log_level == LOG_DEBUG)
-               while (*sensors) {
-                       log_debug("Measure: %s %.2f",
-                                  (*sensors)->name,
-                                  psensor_get_current_value(*sensors));
-
-                       sensors++;
-               }
-}
-
 void update_psensor_measures(struct ui_psensor *ui)
 {
        struct psensor **sensors = ui->sensors;
@@ -171,7 +159,7 @@ void update_psensor_measures(struct ui_psensor *ui)
                amd_psensor_list_update(sensors);
 #endif
 
-               log_measures(sensors);
+               psensor_log_measures(sensors);
 
                g_mutex_unlock(ui->sensors_mutex);
 
@@ -215,7 +203,7 @@ gboolean ui_refresh_thread(gpointer data)
 
        g_mutex_lock(ui->sensors_mutex);
 
-       graph_update(ui->sensors, ui->w_graph, ui->config);
+       graph_update(ui->sensors, ui->w_graph, ui->config, ui->main_window);
 
        ui_sensorlist_update(ui);
 
@@ -224,7 +212,8 @@ gboolean ui_refresh_thread(gpointer data)
 
 #ifdef HAVE_UNITY
        ui_unity_launcher_entry_update(ui->sensors,
-                                      !cfg->unity_launcher_count_disabled);
+                                      !cfg->unity_launcher_count_disabled,
+                                      cfg->temperature_unit == CELCIUS);
 #endif
 
        if (ui->graph_update_interval != cfg->graph_update_interval) {
@@ -319,8 +308,10 @@ static void associate_preferences(struct psensor **sensors)
 
                n = config_get_sensor_name(s->id);
 
-               if (n)
+               if (n) {
+                       free(s->name);
                        s->name = n;
+               }
 
                sensor_cur++;
        }
@@ -392,6 +383,12 @@ static void log_glib_info()
                  glib_micro_version);
 }
 
+static void activate(GApplication *application,
+                    gpointer data)
+{
+       ui_window_show((struct ui_psensor *)data);
+}
+
 int main(int argc, char **argv)
 {
        struct ui_psensor ui;
@@ -399,6 +396,7 @@ int main(int argc, char **argv)
        GThread *thread;
        int optc, cmdok, opti, use_libatasmart;
        char *url = NULL;
+       GApplication *app;
 
        program_name = argv[0];
 
@@ -447,6 +445,17 @@ int main(int argc, char **argv)
 
        log_init();
 
+       app = g_application_new("wpitchoune.psensor", 0);
+       g_application_register(app, NULL, NULL);
+
+       if (g_application_get_is_remote(app)) {
+               g_application_activate(app);
+               log_debug(_("Psensor instance already exists"));
+               exit(EXIT_SUCCESS);
+       }
+
+       g_signal_connect(app, "activate", G_CALLBACK(activate), &ui);
+
        log_glib_info();
 #if !(GLIB_CHECK_VERSION(2, 31, 0))
        /*
@@ -497,6 +506,7 @@ int main(int argc, char **argv)
 
 #if !defined(HAVE_APPINDICATOR) && !defined(HAVE_APPINDICATOR_029)
        ui_status_init(&ui);
+       ui_status_set_visible(1);
 #endif
 
        /* main window */
@@ -506,6 +516,8 @@ int main(int argc, char **argv)
        /* drawing box */
        ui.w_graph = ui_graph_create(&ui);
 
+       ui_enable_alpha_channel(&ui);
+
        /* sensor list */
        ui_sensorlist_create(&ui);
 
@@ -521,6 +533,7 @@ int main(int argc, char **argv)
 
 #if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029)
        ui_appindicator_init(&ui);
+       ui_status_set_visible(1);
 #endif
 
        /*
@@ -536,6 +549,8 @@ int main(int argc, char **argv)
        /* main loop */
        gtk_main();
 
+       log_debug("Quitting...");
+
        g_mutex_lock(ui.sensors_mutex);
 
        psensor_cleanup();
@@ -563,6 +578,8 @@ int main(int argc, char **argv)
 
        config_cleanup();
 
+       log_debug("Cleanup done, closing log");
+
        log_close();
 
        return 0;