diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/flashlight.c | 14 | ||||
-rw-r--r-- | src/flashlight.h | 3 | ||||
-rw-r--r-- | src/service.c | 7 |
3 files changed, 20 insertions, 4 deletions
diff --git a/src/flashlight.c b/src/flashlight.c index 3c5e8b1..63553e5 100644 --- a/src/flashlight.c +++ b/src/flashlight.c @@ -31,6 +31,7 @@ const size_t qcom_sysfs_size = 2; const char* const qcom_sysfs[] = {"/sys/class/leds/torch-light/brightness", "/sys/class/leds/led:flash_torch/brightness"}; char* flash_sysfs_path = NULL; +gboolean activated = 0; int set_sysfs_path() @@ -44,29 +45,34 @@ set_sysfs_path() return 0; } +gboolean +flashlight_activated() +{ + return activated; +} + void toggle_flashlight_action(GAction *action, GVariant *parameter G_GNUC_UNUSED, gpointer data G_GNUC_UNUSED) { GVariant *state; - gboolean b; FILE* fd; if (!set_sysfs_path()) return; state = g_action_get_state(action); - b = g_variant_get_boolean(state); + activated = g_variant_get_boolean(state); g_variant_unref(state); fd = fopen(flash_sysfs_path, "w"); if (fd != NULL){ - if (b) + if (activated) fprintf(fd, QCOM_DISABLE); else fprintf(fd, QCOM_ENABLE); fclose(fd); - g_action_change_state(action, g_variant_new_boolean(!b)); + g_action_change_state(action, g_variant_new_boolean(!activated)); } } diff --git a/src/flashlight.h b/src/flashlight.h index af2822d..51ed5e7 100644 --- a/src/flashlight.h +++ b/src/flashlight.h @@ -32,6 +32,9 @@ toggle_flashlight_action(GAction *action, int flashlight_supported(); +gboolean +flashlight_activated(); + G_END_DECLS #endif /* INDICATOR_POWER_FLASHLIGHT__H */ diff --git a/src/service.c b/src/service.c index 75d4538..feb9dc4 100644 --- a/src/service.c +++ b/src/service.c @@ -678,7 +678,14 @@ create_phone_settings_section(IndicatorPowerService * self) g_menu_item_set_attribute(item, "x-canonical-type", "s", "com.canonical.indicator.switch"); g_menu_append_item(section, item); g_object_unref(item); + if (flashlight_activated()) + { + item = g_menu_item_new(_("Warning: Heavy use can damage the LED!"), "indicator.flashlight"); + g_menu_append_item(section, item); + g_object_unref(item); + } } + g_menu_append(section, _("Battery settingsā¦"), "indicator.activate-phone-settings"); return G_MENU_MODEL(section); |