#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace tt::app::launcher { constexpr auto* TAG = "Launcher"; constexpr auto* BACKGROUND_ASSET = "color-field.png"; constexpr auto* CUSTOM_BACKGROUND_PATH = "tactility/launcher/background.bin"; constexpr lv_color_t TEXT_COLOR = LV_COLOR_MAKE(0xF8, 0xF5, 0xF2); constexpr lv_color_t MUTED_TEXT_COLOR = LV_COLOR_MAKE(0xDF, 0xD6, 0xD3); constexpr lv_color_t ACCENT_COLOR = LV_COLOR_MAKE(0xEC, 0x75, 0x69); namespace { struct LauncherWidgets { lv_obj_t* timeLabel = nullptr; lv_obj_t* dateLabel = nullptr; lv_obj_t* dataLabel = nullptr; lv_obj_t* statusLabel = nullptr; lv_timer_t* updateTimer = nullptr; }; void onAppPressed(lv_event_t* event) { const auto* app_id = static_cast(lv_event_get_user_data(event)); uint32_t instance_id = 0; app_start(app_id, 0, nullptr, &instance_id); } bool shouldShowPowerButton() { bool show_power_button = false; device_for_each_of_type(&POWER_SUPPLY_TYPE, &show_power_button, [](Device* device, void* context) { if (device_is_ready(device) && power_supply_supports_power_off(device)) { *static_cast(context) = true; return false; } return true; }); return show_power_button; } int getBatteryPercentage() { Device* power = nullptr; device_for_each_of_type(&POWER_SUPPLY_TYPE, &power, [](Device* device, void* context) { if (device_is_ready(device) && power_supply_supports_property(device, POWER_SUPPLY_PROP_CAPACITY)) { *static_cast(context) = device; return false; } return true; }); if (power == nullptr) return -1; PowerSupplyPropertyValue charge_level; if (power_supply_get_property(power, POWER_SUPPLY_PROP_CAPACITY, &charge_level) != ERROR_NONE) return -1; return std::clamp(charge_level.int_value, 0, 100); } const char* getWifiStatusIcon(service::wifi::RadioState state) { using enum service::wifi::RadioState; switch (state) { case ConnectionActive: return LVGL_ICON_STATUSBAR_SIGNAL_WIFI_4_BAR; case Off: case OffPending: return LVGL_ICON_STATUSBAR_SIGNAL_WIFI_OFF; default: return LVGL_ICON_STATUSBAR_SIGNAL_WIFI_0_BAR; } } const char* getBatteryStatusIcon(int percentage) { if (percentage < 0) return ""; if (percentage >= 95) return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_FULL; if (percentage >= 64) return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_5; if (percentage >= 32) return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_3; return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_1; } lv_obj_t* createAppButton(lv_obj_t* parent, const char* icon, const char* app_id, bool emphasized) { auto* button = lv_button_create(parent); lv_obj_set_size(button, 52, 52); lv_obj_set_style_radius(button, 15, LV_PART_MAIN); lv_obj_set_style_shadow_width(button, 0, LV_PART_MAIN); lv_obj_set_style_border_width(button, emphasized ? 2 : 1, LV_PART_MAIN); lv_obj_set_style_border_color(button, emphasized ? ACCENT_COLOR : lv_color_hex(0x746568), LV_PART_MAIN); lv_obj_set_style_border_opa(button, emphasized ? LV_OPA_COVER : LV_OPA_60, LV_PART_MAIN); lv_obj_set_style_bg_color(button, lv_color_hex(0x211B20), LV_PART_MAIN); lv_obj_set_style_bg_opa(button, emphasized ? LV_OPA_80 : LV_OPA_70, LV_PART_MAIN); lv_obj_set_style_bg_color(button, lv_color_hex(0x392C32), LV_STATE_PRESSED); lv_obj_set_style_transform_scale(button, 238, LV_STATE_PRESSED); lv_obj_set_style_outline_color(button, ACCENT_COLOR, LV_STATE_FOCUSED); lv_obj_set_style_outline_width(button, 2, LV_STATE_FOCUSED); lv_obj_set_style_outline_pad(button, 2, LV_STATE_FOCUSED); auto* image = lv_image_create(button); lv_obj_set_size(image, 36, 36); lv_obj_center(image); lv_obj_set_style_text_font(image, lvgl_get_launcher_icon_font(), LV_STATE_DEFAULT); lv_image_set_src(image, icon); lv_obj_set_style_image_recolor(image, TEXT_COLOR, LV_STATE_DEFAULT); lv_obj_set_style_image_recolor_opa(image, LV_OPA_COVER, LV_STATE_DEFAULT); lv_obj_add_event_cb(button, onAppPressed, LV_EVENT_SHORT_CLICKED, const_cast(app_id)); return button; } void updateInformation(LauncherWidgets& widgets) { const std::time_t now = std::time(nullptr); std::tm local_time {}; localtime_r(&now, &local_time); char time_buffer[12]; char date_buffer[40]; if (local_time.tm_year >= 125) { if (settings::isTimeFormat24Hour()) { std::strftime(time_buffer, sizeof(time_buffer), "%H:%M", &local_time); } else { std::strftime(time_buffer, sizeof(time_buffer), "%I:%M", &local_time); if (time_buffer[0] == '0') std::memmove(time_buffer, time_buffer + 1, std::strlen(time_buffer)); } std::strftime(date_buffer, sizeof(date_buffer), "%A, %B %e", &local_time); } else { std::strcpy(time_buffer, "--:--"); std::strcpy(date_buffer, "Set date and time"); } lv_label_set_text(widgets.timeLabel, time_buffer); lv_label_set_text(widgets.dateLabel, date_buffer); const auto wifi_state = service::wifi::getRadioState(); std::string sd_card_path; const bool sd_ready = findFirstMountedSdCardPath(sd_card_path); const int battery_percentage = getBatteryPercentage(); char data_buffer[80]; if (battery_percentage >= 0) { std::snprintf(data_buffer, sizeof(data_buffer), "%s • %s • %d%%", wifi_state == service::wifi::RadioState::ConnectionActive ? "Wi-Fi connected" : "Wi-Fi offline", sd_ready ? "SD ready" : "No SD", battery_percentage); } else { std::snprintf(data_buffer, sizeof(data_buffer), "%s • %s", wifi_state == service::wifi::RadioState::ConnectionActive ? "Wi-Fi connected" : "Wi-Fi offline", sd_ready ? "SD ready" : "No SD"); } lv_label_set_text(widgets.dataLabel, data_buffer); char status_buffer[24]; std::snprintf(status_buffer, sizeof(status_buffer), "%s%s", getWifiStatusIcon(wifi_state), getBatteryStatusIcon(battery_percentage)); lv_label_set_text(widgets.statusLabel, status_buffer); } void onUpdateTimer(lv_timer_t* timer) { updateInformation(*static_cast(lv_timer_get_user_data(timer))); } std::string getDefaultBackgroundPath() { return std::string(file::MOUNT_POINT_SYSTEM) + "/app/Launcher/assets/" + BACKGROUND_ASSET; } void createWidgets(lv_obj_t* parent, void* user_data) { auto& widgets = *static_cast(user_data); lv_obj_set_style_bg_color(parent, lv_color_hex(0x211A20), LV_PART_MAIN); lv_obj_set_style_bg_opa(parent, LV_OPA_COVER, LV_PART_MAIN); lv_obj_set_style_pad_all(parent, 0, LV_PART_MAIN); lv_obj_clear_flag(parent, LV_OBJ_FLAG_SCROLLABLE); auto* display = lv_obj_get_display(parent); const auto display_width = lv_display_get_horizontal_resolution(display); const auto display_height = lv_display_get_vertical_resolution(display); const bool is_portrait = display_height > display_width; auto background_path = lvgl::PATH_PREFIX + getDefaultBackgroundPath(); std::string sd_card_path; if (findFirstMountedSdCardPath(sd_card_path)) { const auto custom_background_path = file::getChildPath(sd_card_path, CUSTOM_BACKGROUND_PATH); if (file::isFile(custom_background_path)) { const auto lvgl_custom_background_path = lvgl::PATH_PREFIX + custom_background_path; lv_image_header_t header {}; if (lv_image_decoder_get_info(lvgl_custom_background_path.c_str(), &header) == LV_RESULT_OK) { if (header.w >= display_width && header.h >= display_height) { background_path = lvgl_custom_background_path; LOG_I(TAG, "Using SD background %s (%ux%u, format 0x%02x)", custom_background_path.c_str(), header.w, header.h, header.cf); } else { LOG_W(TAG, "Ignoring undersized SD background %s (%ux%u for %dx%d display)", custom_background_path.c_str(), header.w, header.h, display_width, display_height); } } else { LOG_W(TAG, "Ignoring invalid SD background %s", custom_background_path.c_str()); } } } auto* background = lv_image_create(parent); lv_image_set_src(background, background_path.c_str()); lv_obj_align(background, LV_ALIGN_CENTER, 0, 0); lv_obj_add_flag(background, LV_OBJ_FLAG_IGNORE_LAYOUT); widgets.timeLabel = lv_label_create(parent); lv_label_set_text(widgets.timeLabel, "--:--"); lv_obj_set_style_text_color(widgets.timeLabel, TEXT_COLOR, LV_PART_MAIN); #if LV_FONT_MONTSERRAT_48 lv_obj_set_style_text_font(widgets.timeLabel, &lv_font_montserrat_48, LV_PART_MAIN); #else lv_obj_set_style_text_font(widgets.timeLabel, lvgl_get_text_font(FONT_SIZE_LARGE), LV_PART_MAIN); #endif lv_obj_align(widgets.timeLabel, LV_ALIGN_TOP_LEFT, 18, 58); widgets.dateLabel = lv_label_create(parent); lv_obj_set_style_text_font(widgets.dateLabel, lvgl_get_text_font(FONT_SIZE_LARGE), LV_PART_MAIN); lv_obj_set_style_text_color(widgets.dateLabel, TEXT_COLOR, LV_PART_MAIN); lv_obj_align(widgets.dateLabel, LV_ALIGN_TOP_LEFT, 20, 118); widgets.dataLabel = lv_label_create(parent); lv_obj_set_width(widgets.dataLabel, is_portrait ? display_width - 40 : 225); lv_label_set_long_mode(widgets.dataLabel, LV_LABEL_LONG_MODE_WRAP); lv_obj_set_style_text_font(widgets.dataLabel, lvgl_get_text_font(FONT_SIZE_SMALL), LV_PART_MAIN); lv_obj_set_style_text_color(widgets.dataLabel, MUTED_TEXT_COLOR, LV_PART_MAIN); lv_obj_align(widgets.dataLabel, LV_ALIGN_TOP_LEFT, 20, 148); widgets.statusLabel = lv_label_create(parent); lv_obj_set_style_text_font(widgets.statusLabel, lvgl_get_statusbar_icon_font(), LV_PART_MAIN); lv_obj_set_style_text_color(widgets.statusLabel, TEXT_COLOR, LV_PART_MAIN); lv_obj_align(widgets.statusLabel, LV_ALIGN_TOP_RIGHT, -15, 8); auto* button_rail = lv_obj_create(parent); if (is_portrait) { lv_obj_set_size(button_rail, 184, 60); lv_obj_align(button_rail, LV_ALIGN_BOTTOM_MID, 0, -7); lv_obj_set_flex_flow(button_rail, LV_FLEX_FLOW_ROW); } else { lv_obj_set_size(button_rail, 60, 184); lv_obj_align(button_rail, LV_ALIGN_RIGHT_MID, -7, 8); lv_obj_set_flex_flow(button_rail, LV_FLEX_FLOW_COLUMN); } lv_obj_set_flex_align(button_rail, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); lv_obj_set_style_pad_all(button_rail, 0, LV_PART_MAIN); lv_obj_set_style_border_width(button_rail, 0, LV_PART_MAIN); lv_obj_set_style_bg_opa(button_rail, LV_OPA_TRANSP, LV_PART_MAIN); lv_obj_clear_flag(button_rail, LV_OBJ_FLAG_SCROLLABLE); auto* app_list_button = createAppButton(button_rail, LVGL_ICON_LAUNCHER_APPS, "tactility.applist", true); createAppButton(button_rail, LVGL_ICON_LAUNCHER_FOLDER, "tactility.files", false); createAppButton(button_rail, LVGL_ICON_LAUNCHER_SETTINGS, "tactility.settings", false); if (shouldShowPowerButton()) { auto* power_button = lv_button_create(parent); lv_obj_set_size(power_button, 36, 36); lv_obj_align(power_button, LV_ALIGN_BOTTOM_LEFT, 16, -12); lv_obj_set_style_radius(power_button, LV_RADIUS_CIRCLE, LV_PART_MAIN); lv_obj_set_style_shadow_width(power_button, 0, LV_PART_MAIN); lv_obj_set_style_bg_color(power_button, lv_color_hex(0x211B20), LV_PART_MAIN); lv_obj_set_style_bg_opa(power_button, LV_OPA_70, LV_PART_MAIN); lv_obj_add_event_cb(power_button, onAppPressed, LV_EVENT_SHORT_CLICKED, const_cast("tactility.poweroff")); auto* power_label = lv_label_create(power_button); lv_label_set_text(power_label, LV_SYMBOL_POWER); lv_obj_set_style_text_color(power_label, TEXT_COLOR, LV_PART_MAIN); lv_obj_center(power_label); } if (!device_has_active_by_type(&POINTER_TYPE)) { lv_group_focus_obj(app_list_button); lv_obj_add_state(app_list_button, LV_STATE_FOCUS_KEY); } updateInformation(widgets); widgets.updateTimer = lv_timer_create(onUpdateTimer, 1000, &widgets); } void destroyWidgets(void* user_data) { auto& widgets = *static_cast(user_data); if (widgets.updateTimer != nullptr) { lv_timer_delete(widgets.updateTimer); widgets.updateTimer = nullptr; } widgets.timeLabel = nullptr; widgets.dateLabel = nullptr; widgets.dataLabel = nullptr; widgets.statusLabel = nullptr; } void runAutoStart() { settings::BootSettings boot_properties; AppManifest manifest; if (strcmp(CONFIG_TT_AUTO_START_APP_ID, "") != 0 && app_manager_find_manifest(CONFIG_TT_AUTO_START_APP_ID, &manifest) == ERROR_NONE) { LOG_I(TAG, "Starting %s", CONFIG_TT_AUTO_START_APP_ID); uint32_t app_launch_id; app_start(CONFIG_TT_AUTO_START_APP_ID, 0, nullptr, &app_launch_id); } else if (settings::loadBootSettings(boot_properties) && !boot_properties.autoStartAppId.empty() && app_manager_find_manifest(boot_properties.autoStartAppId.c_str(), &manifest) == ERROR_NONE) { LOG_I(TAG, "Starting %s", boot_properties.autoStartAppId.c_str()); uint32_t app_launch_id; app_start(boot_properties.autoStartAppId.c_str(), 0, nullptr, &app_launch_id); } else if (!setup::isCompleted()) { setup::start(); } } int32_t appMain(int argc, char* argv[]) { uint32_t app_instance_id = app_scheduler_current_app_id(); runAutoStart(); LauncherWidgets widgets; WindowId window = window_manager_create_ext(app_instance_id, createWidgets, destroyWidgets, &widgets); TaskEventGroup event_group {}; task_event_group_construct(&event_group); AppEventSubscription sub {}; check(app_event_subscribe(&sub, &event_group) == ERROR_NONE); while (true) { task_event_group_wait_any(&event_group, nullptr, portMAX_DELAY); bool should_close = false; AppEvent event {}; while (app_event_poll(&sub, &event) == ERROR_NONE) { if (event.type == APP_EVENT_CLOSE) { should_close = true; break; } } if (should_close) break; } window_manager_remove(window); check(app_event_unsubscribe(&sub) == ERROR_NONE); task_event_group_destruct(&event_group); return 0; } } // namespace extern const ::AppManifest manifest = { .id = "tactility.launcher", .name = "Launcher", .category = APP_CATEGORY_SYSTEM, .location = { .type = APP_LOCATION_MEMORY, .location = reinterpret_cast(appMain) }, .flags = APP_MANIFEST_FLAG_HIDDEN, .stack = { .depth = 3072, .desired_memory_capability = MEMORY_CAPABILITY_EXTERNAL } }; uint32_t start() { uint32_t instance_id = 0; app_start(manifest.id, 0, nullptr, &instance_id); return instance_id; } } // namespace tt::app::launcher