|
| 1 | +#include <stdio.h> |
| 2 | +#include <stdlib.h> |
| 3 | +#include <string.h> |
| 4 | + |
| 5 | +// Include C API headers |
| 6 | +#include "../../src/capi/accessibility_manager_c.h" |
| 7 | +#include "../../src/capi/tray_manager_c.h" |
| 8 | +#include "../../src/capi/tray_icon_c.h" |
| 9 | +#include "../../src/capi/window_manager_c.h" |
| 10 | +#include "../../src/capi/window_c.h" |
| 11 | +#include "../../src/capi/menu_c.h" |
| 12 | +#include "../../src/capi/run_example_app_c.h" |
| 13 | + |
| 14 | +// Global variables to store handles |
| 15 | +static native_window_t g_window = NULL; |
| 16 | +static native_tray_icon_t g_tray_icon = NULL; |
| 17 | +static native_menu_t g_context_menu = NULL; |
| 18 | + |
| 19 | +// Event callback functions |
| 20 | +void on_tray_icon_clicked(const void* event, void* user_data) { |
| 21 | + const native_tray_icon_clicked_event_t* clicked_event = (const native_tray_icon_clicked_event_t*)event; |
| 22 | + printf("*** TRAY ICON LEFT CLICKED! ***\n"); |
| 23 | + printf("This is the left click handler working!\n"); |
| 24 | + printf("Tray icon ID: %ld\n", clicked_event->tray_icon_id); |
| 25 | +} |
| 26 | + |
| 27 | +void on_tray_icon_right_clicked(const void* event, void* user_data) { |
| 28 | + const native_tray_icon_right_clicked_event_t* right_clicked_event = (const native_tray_icon_right_clicked_event_t*)event; |
| 29 | + printf("*** TRAY ICON RIGHT CLICKED! ***\n"); |
| 30 | + printf("This is the right click handler working!\n"); |
| 31 | + printf("Tray icon ID: %ld\n", right_clicked_event->tray_icon_id); |
| 32 | +} |
| 33 | + |
| 34 | +void on_tray_icon_double_clicked(const void* event, void* user_data) { |
| 35 | + const native_tray_icon_double_clicked_event_t* double_clicked_event = (const native_tray_icon_double_clicked_event_t*)event; |
| 36 | + printf("*** TRAY ICON DOUBLE CLICKED! ***\n"); |
| 37 | + printf("This is the double click handler working!\n"); |
| 38 | + printf("Tray icon ID: %ld\n", double_clicked_event->tray_icon_id); |
| 39 | +} |
| 40 | + |
| 41 | +void on_show_window_clicked(const void* event, void* user_data) { |
| 42 | + printf("Show Window clicked from context menu\n"); |
| 43 | + if (g_window) { |
| 44 | + native_window_show(g_window); |
| 45 | + native_window_focus(g_window); |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +void on_hide_window_clicked(const void* event, void* user_data) { |
| 50 | + printf("Hide Window clicked from context menu\n"); |
| 51 | + if (g_window) { |
| 52 | + native_window_hide(g_window); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +void on_about_clicked(const void* event, void* user_data) { |
| 57 | + printf("About clicked from context menu\n"); |
| 58 | + printf("Window Example v1.0 - Native API Demo\n"); |
| 59 | +} |
| 60 | + |
| 61 | +void on_clear_cache_clicked(const void* event, void* user_data) { |
| 62 | + printf("Clear Cache clicked from submenu\n"); |
| 63 | +} |
| 64 | + |
| 65 | +void on_reset_settings_clicked(const void* event, void* user_data) { |
| 66 | + printf("Reset Settings clicked from submenu\n"); |
| 67 | +} |
| 68 | + |
| 69 | +void on_debug_mode_clicked(const void* event, void* user_data) { |
| 70 | + native_menu_item_t debug_mode_item = (native_menu_item_t)user_data; |
| 71 | + native_menu_item_state_t current_state = native_menu_item_get_state(debug_mode_item); |
| 72 | + native_menu_item_state_t new_state = (current_state == NATIVE_MENU_ITEM_STATE_CHECKED) ? |
| 73 | + NATIVE_MENU_ITEM_STATE_UNCHECKED : NATIVE_MENU_ITEM_STATE_CHECKED; |
| 74 | + native_menu_item_set_state(debug_mode_item, new_state); |
| 75 | + printf("Debug Mode %s\n", (new_state == NATIVE_MENU_ITEM_STATE_CHECKED) ? "enabled" : "disabled"); |
| 76 | +} |
| 77 | + |
| 78 | +void on_auto_start_clicked(const void* event, void* user_data) { |
| 79 | + native_menu_item_t auto_start_item = (native_menu_item_t)user_data; |
| 80 | + native_menu_item_state_t current_state = native_menu_item_get_state(auto_start_item); |
| 81 | + native_menu_item_state_t new_state = (current_state == NATIVE_MENU_ITEM_STATE_CHECKED) ? |
| 82 | + NATIVE_MENU_ITEM_STATE_UNCHECKED : NATIVE_MENU_ITEM_STATE_CHECKED; |
| 83 | + native_menu_item_set_state(auto_start_item, new_state); |
| 84 | + printf("Auto Start %s\n", (new_state == NATIVE_MENU_ITEM_STATE_CHECKED) ? "enabled" : "disabled"); |
| 85 | +} |
| 86 | + |
| 87 | +void on_notifications_clicked(const void* event, void* user_data) { |
| 88 | + native_menu_item_t notifications_item = (native_menu_item_t)user_data; |
| 89 | + native_menu_item_state_t current_state = native_menu_item_get_state(notifications_item); |
| 90 | + native_menu_item_state_t new_state = (current_state == NATIVE_MENU_ITEM_STATE_CHECKED) ? |
| 91 | + NATIVE_MENU_ITEM_STATE_UNCHECKED : NATIVE_MENU_ITEM_STATE_CHECKED; |
| 92 | + native_menu_item_set_state(notifications_item, new_state); |
| 93 | + printf("Notifications %s\n", (new_state == NATIVE_MENU_ITEM_STATE_CHECKED) ? "enabled" : "disabled"); |
| 94 | +} |
| 95 | + |
| 96 | +void on_sync_item_clicked(const void* event, void* user_data) { |
| 97 | + native_menu_item_t sync_item = (native_menu_item_t)user_data; |
| 98 | + native_menu_item_state_t current_state = native_menu_item_get_state(sync_item); |
| 99 | + native_menu_item_state_t next_state; |
| 100 | + const char* state_name; |
| 101 | + |
| 102 | + // Cycle through states: Mixed -> Checked -> Unchecked -> Mixed |
| 103 | + switch (current_state) { |
| 104 | + case NATIVE_MENU_ITEM_STATE_MIXED: |
| 105 | + next_state = NATIVE_MENU_ITEM_STATE_CHECKED; |
| 106 | + state_name = "enabled"; |
| 107 | + break; |
| 108 | + case NATIVE_MENU_ITEM_STATE_CHECKED: |
| 109 | + next_state = NATIVE_MENU_ITEM_STATE_UNCHECKED; |
| 110 | + state_name = "disabled"; |
| 111 | + break; |
| 112 | + case NATIVE_MENU_ITEM_STATE_UNCHECKED: |
| 113 | + default: |
| 114 | + next_state = NATIVE_MENU_ITEM_STATE_MIXED; |
| 115 | + state_name = "partial"; |
| 116 | + break; |
| 117 | + } |
| 118 | + |
| 119 | + native_menu_item_set_state(sync_item, next_state); |
| 120 | + printf("Sync Status: %s\n", state_name); |
| 121 | +} |
| 122 | + |
| 123 | +void on_light_theme_clicked(const void* event, void* user_data) { |
| 124 | + native_menu_item_t light_theme_item = (native_menu_item_t)user_data; |
| 125 | + native_menu_item_set_state(light_theme_item, NATIVE_MENU_ITEM_STATE_CHECKED); |
| 126 | + printf("Light theme selected\n"); |
| 127 | +} |
| 128 | + |
| 129 | +void on_dark_theme_clicked(const void* event, void* user_data) { |
| 130 | + native_menu_item_t dark_theme_item = (native_menu_item_t)user_data; |
| 131 | + native_menu_item_set_state(dark_theme_item, NATIVE_MENU_ITEM_STATE_CHECKED); |
| 132 | + printf("Dark theme selected\n"); |
| 133 | +} |
| 134 | + |
| 135 | +void on_auto_theme_clicked(const void* event, void* user_data) { |
| 136 | + native_menu_item_t auto_theme_item = (native_menu_item_t)user_data; |
| 137 | + native_menu_item_set_state(auto_theme_item, NATIVE_MENU_ITEM_STATE_CHECKED); |
| 138 | + printf("Auto theme selected\n"); |
| 139 | +} |
| 140 | + |
| 141 | +void on_exit_clicked(const void* event, void* user_data) { |
| 142 | + printf("Exit clicked from context menu\n"); |
| 143 | + // Get all windows and destroy them to trigger app exit |
| 144 | + native_window_list_t windows = native_window_manager_get_all(); |
| 145 | + for (long i = 0; i < windows.count; i++) { |
| 146 | + native_window_id_t window_id = native_window_get_id(windows.windows[i]); |
| 147 | + native_window_manager_destroy(window_id); |
| 148 | + } |
| 149 | + native_window_list_free(&windows); |
| 150 | +} |
| 151 | + |
| 152 | +void on_tools_submenu_opened(const void* event, void* user_data) { |
| 153 | + const native_menu_item_submenu_opened_event_t* opened_event = (const native_menu_item_submenu_opened_event_t*)event; |
| 154 | + printf("Tools submenu opened (ID: %ld)\n", opened_event->item_id); |
| 155 | +} |
| 156 | + |
| 157 | +void on_tools_submenu_closed(const void* event, void* user_data) { |
| 158 | + const native_menu_item_submenu_closed_event_t* closed_event = (const native_menu_item_submenu_closed_event_t*)event; |
| 159 | + printf("Tools submenu closed (ID: %ld)\n", closed_event->item_id); |
| 160 | +} |
| 161 | + |
| 162 | +native_menu_t create_context_menu(void) { |
| 163 | + // Create context menu |
| 164 | + native_menu_t context_menu = native_menu_create(); |
| 165 | + |
| 166 | + // Add Show Window item |
| 167 | + native_menu_item_t show_window_item = native_menu_item_create("Show Window", NATIVE_MENU_ITEM_TYPE_NORMAL); |
| 168 | + native_menu_item_add_listener(show_window_item, NATIVE_MENU_ITEM_EVENT_CLICKED, on_show_window_clicked, NULL); |
| 169 | + native_menu_add_item(context_menu, show_window_item); |
| 170 | + |
| 171 | + // Add Hide Window item |
| 172 | + native_menu_item_t hide_window_item = native_menu_item_create("Hide Window", NATIVE_MENU_ITEM_TYPE_NORMAL); |
| 173 | + native_menu_item_add_listener(hide_window_item, NATIVE_MENU_ITEM_EVENT_CLICKED, on_hide_window_clicked, NULL); |
| 174 | + native_menu_add_item(context_menu, hide_window_item); |
| 175 | + |
| 176 | + // Add separator |
| 177 | + native_menu_add_separator(context_menu); |
| 178 | + |
| 179 | + // Add About item |
| 180 | + native_menu_item_t about_item = native_menu_item_create("About", NATIVE_MENU_ITEM_TYPE_NORMAL); |
| 181 | + native_menu_item_add_listener(about_item, NATIVE_MENU_ITEM_EVENT_CLICKED, on_about_clicked, NULL); |
| 182 | + native_menu_add_item(context_menu, about_item); |
| 183 | + |
| 184 | + // Create Tools submenu |
| 185 | + native_menu_t tools_submenu = native_menu_create(); |
| 186 | + |
| 187 | + // Add items to tools submenu |
| 188 | + native_menu_item_t clear_cache_item = native_menu_item_create("Clear Cache", NATIVE_MENU_ITEM_TYPE_NORMAL); |
| 189 | + native_menu_item_add_listener(clear_cache_item, NATIVE_MENU_ITEM_EVENT_CLICKED, on_clear_cache_clicked, NULL); |
| 190 | + native_menu_add_item(tools_submenu, clear_cache_item); |
| 191 | + |
| 192 | + native_menu_item_t reset_settings_item = native_menu_item_create("Reset Settings", NATIVE_MENU_ITEM_TYPE_NORMAL); |
| 193 | + native_menu_item_add_listener(reset_settings_item, NATIVE_MENU_ITEM_EVENT_CLICKED, on_reset_settings_clicked, NULL); |
| 194 | + native_menu_add_item(tools_submenu, reset_settings_item); |
| 195 | + |
| 196 | + native_menu_add_separator(tools_submenu); |
| 197 | + |
| 198 | + native_menu_item_t debug_mode_item = native_menu_item_create("Debug Mode", NATIVE_MENU_ITEM_TYPE_CHECKBOX); |
| 199 | + native_menu_item_set_state(debug_mode_item, NATIVE_MENU_ITEM_STATE_UNCHECKED); |
| 200 | + native_menu_item_add_listener(debug_mode_item, NATIVE_MENU_ITEM_EVENT_CLICKED, on_debug_mode_clicked, debug_mode_item); |
| 201 | + native_menu_add_item(tools_submenu, debug_mode_item); |
| 202 | + |
| 203 | + // Create the submenu parent item |
| 204 | + native_menu_item_t tools_item = native_menu_item_create("Tools", NATIVE_MENU_ITEM_TYPE_SUBMENU); |
| 205 | + native_menu_item_set_submenu(tools_item, tools_submenu); |
| 206 | + |
| 207 | + // Add submenu event listeners |
| 208 | + native_menu_item_add_listener(tools_item, NATIVE_MENU_ITEM_EVENT_SUBMENU_OPENED, on_tools_submenu_opened, NULL); |
| 209 | + native_menu_item_add_listener(tools_item, NATIVE_MENU_ITEM_EVENT_SUBMENU_CLOSED, on_tools_submenu_closed, NULL); |
| 210 | + |
| 211 | + native_menu_add_item(context_menu, tools_item); |
| 212 | + |
| 213 | + // Add separator before preferences |
| 214 | + native_menu_add_separator(context_menu); |
| 215 | + |
| 216 | + // Add preferences item |
| 217 | + native_menu_item_t preferences_item = native_menu_item_create("Preferences", NATIVE_MENU_ITEM_TYPE_NORMAL); |
| 218 | + native_menu_add_item(context_menu, preferences_item); |
| 219 | + |
| 220 | + // Add checkbox menu items |
| 221 | + native_menu_item_t auto_start_item = native_menu_item_create("Auto Start", NATIVE_MENU_ITEM_TYPE_CHECKBOX); |
| 222 | + native_menu_item_set_state(auto_start_item, NATIVE_MENU_ITEM_STATE_CHECKED); // Initially checked |
| 223 | + native_menu_item_add_listener(auto_start_item, NATIVE_MENU_ITEM_EVENT_CLICKED, on_auto_start_clicked, auto_start_item); |
| 224 | + native_menu_add_item(context_menu, auto_start_item); |
| 225 | + |
| 226 | + native_menu_item_t notifications_item = native_menu_item_create("Show Notifications", NATIVE_MENU_ITEM_TYPE_CHECKBOX); |
| 227 | + native_menu_item_set_state(notifications_item, NATIVE_MENU_ITEM_STATE_UNCHECKED); // Initially unchecked |
| 228 | + native_menu_item_add_listener(notifications_item, NATIVE_MENU_ITEM_EVENT_CLICKED, on_notifications_clicked, notifications_item); |
| 229 | + native_menu_add_item(context_menu, notifications_item); |
| 230 | + |
| 231 | + // Add three-state checkbox example |
| 232 | + native_menu_item_t sync_item = native_menu_item_create("Sync Status", NATIVE_MENU_ITEM_TYPE_CHECKBOX); |
| 233 | + native_menu_item_set_state(sync_item, NATIVE_MENU_ITEM_STATE_MIXED); // Initially mixed/indeterminate |
| 234 | + native_menu_item_add_listener(sync_item, NATIVE_MENU_ITEM_EVENT_CLICKED, on_sync_item_clicked, sync_item); |
| 235 | + native_menu_add_item(context_menu, sync_item); |
| 236 | + |
| 237 | + // Add separator before radio group |
| 238 | + native_menu_add_separator(context_menu); |
| 239 | + |
| 240 | + // Add radio button group for theme selection |
| 241 | + native_menu_item_t theme_label = native_menu_item_create("Theme:", NATIVE_MENU_ITEM_TYPE_NORMAL); |
| 242 | + native_menu_add_item(context_menu, theme_label); |
| 243 | + |
| 244 | + native_menu_item_t light_theme_item = native_menu_item_create("Light Theme", NATIVE_MENU_ITEM_TYPE_RADIO); |
| 245 | + native_menu_item_set_radio_group(light_theme_item, 0); // Group 0 |
| 246 | + native_menu_item_set_state(light_theme_item, NATIVE_MENU_ITEM_STATE_CHECKED); // Default selection |
| 247 | + native_menu_item_add_listener(light_theme_item, NATIVE_MENU_ITEM_EVENT_CLICKED, on_light_theme_clicked, light_theme_item); |
| 248 | + native_menu_add_item(context_menu, light_theme_item); |
| 249 | + |
| 250 | + native_menu_item_t dark_theme_item = native_menu_item_create("Dark Theme", NATIVE_MENU_ITEM_TYPE_RADIO); |
| 251 | + native_menu_item_set_radio_group(dark_theme_item, 0); // Same group as light theme |
| 252 | + native_menu_item_add_listener(dark_theme_item, NATIVE_MENU_ITEM_EVENT_CLICKED, on_dark_theme_clicked, dark_theme_item); |
| 253 | + native_menu_add_item(context_menu, dark_theme_item); |
| 254 | + |
| 255 | + native_menu_item_t auto_theme_item = native_menu_item_create("Auto Theme", NATIVE_MENU_ITEM_TYPE_RADIO); |
| 256 | + native_menu_item_set_radio_group(auto_theme_item, 0); // Same group |
| 257 | + native_menu_item_add_listener(auto_theme_item, NATIVE_MENU_ITEM_EVENT_CLICKED, on_auto_theme_clicked, auto_theme_item); |
| 258 | + native_menu_add_item(context_menu, auto_theme_item); |
| 259 | + |
| 260 | + // Add another separator |
| 261 | + native_menu_add_separator(context_menu); |
| 262 | + |
| 263 | + // Add exit item |
| 264 | + native_menu_item_t exit_item = native_menu_item_create("Exit", NATIVE_MENU_ITEM_TYPE_NORMAL); |
| 265 | + native_menu_item_add_listener(exit_item, NATIVE_MENU_ITEM_EVENT_CLICKED, on_exit_clicked, NULL); |
| 266 | + native_menu_add_item(context_menu, exit_item); |
| 267 | + |
| 268 | + return context_menu; |
| 269 | +} |
| 270 | + |
| 271 | +int main() { |
| 272 | + // Enable accessibility |
| 273 | + native_accessibility_manager_enable(); |
| 274 | + bool is_enabled = native_accessibility_manager_is_enabled(); |
| 275 | + printf("is_enabled: %s\n", is_enabled ? "true" : "false"); |
| 276 | + |
| 277 | + // Initialize managers |
| 278 | + native_window_manager_initialize(); |
| 279 | + |
| 280 | + // Create a new window with options |
| 281 | + native_window_options_t* options = native_window_options_create(); |
| 282 | + native_window_options_set_title(options, "Window Example"); |
| 283 | + native_window_options_set_size(options, 800, 600); |
| 284 | + native_window_options_set_minimum_size(options, 400, 300); |
| 285 | + native_window_options_set_maximum_size(options, 1920, 1080); |
| 286 | + native_window_options_set_centered(options, true); |
| 287 | + |
| 288 | + g_window = native_window_manager_create(options); |
| 289 | + native_window_options_destroy(options); |
| 290 | + |
| 291 | + // Create tray icon |
| 292 | + g_tray_icon = native_tray_manager_create(); |
| 293 | + if (g_tray_icon != NULL) { |
| 294 | + native_tray_icon_set_icon(g_tray_icon, |
| 295 | + "data:image/png;base64," |
| 296 | + "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABGdBTUEAALGPC/" |
| 297 | + "xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAhGVY" |
| 298 | + "SWZNTQAqAAAACAAFARIAAwAAAAEAAQAAARoABQAAAAEAAABKARsABQAAAAEAAABSASgAAw" |
| 299 | + "AAAAEAAgAAh2kABAAAAAEAAABaAAAAAAAAAEgAAAABAAAASAAAAAEAA6ABAAMAAAABAAEA" |
| 300 | + "AKACAAQAAAABAAAAFKADAAQAAAABAAAAFAAAAABB553+" |
| 301 | + "AAAACXBIWXMAAAsTAAALEwEAmpwYAAABWWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPH" |
| 302 | + "g6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUg" |
| 303 | + "Ni4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OT" |
| 304 | + "kvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjph" |
| 305 | + "Ym91dD0iIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3" |
| 306 | + "RpZmYvMS4wLyI+" |
| 307 | + "CiAgICAgICAgIDx0aWZmOk9yaWVudGF0aW9uPjE8L3RpZmY6T3JpZW50YXRpb24+" |
| 308 | + "CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+" |
| 309 | + "CjwveDp4bXBtZXRhPgoZXuEHAAADOElEQVQ4EY1USUtbURQ+N+/" |
| 310 | + "Fh1O04IxYHFAQNKiIIOJGV10oVbEb3fgHJLpKf0DjQuim3RS3roR25c7qzoWgkCAiiAM4I" |
| 311 | + "W5MnPUlt+c75j6iCdILN+/cM3xnzFFEpPjqYDD4WWsd4htUSgXAS8v4k3VExroJ1o3y/" |
| 312 | + "R6NRv+wlrKg2t7e/s2yrB+2bX8sKChwwHNdl/" |
| 313 | + "Xg6+WwMTmOQ+Alk0mR+Xw+Bzb8+FJRUeFcXFz8VYiMBb/ZzE0kEnp/" |
| 314 | + "f99mWnV2dtLz87MAAMzv99PR0RGVlJRQaWkpQCkvL49F2oV+KpWy+Y5YlZWVv+" |
| 315 | + "Dl6uoq2dra6p+enlYtLS20vr4uhqwkYCcnJzQ0NCQ8dkqFhYW0tbWlzs/" |
| 316 | + "PrcfHx2RZWZnFAdRQW1tbvLe3FzVJzc/Pw6OOxWJ4a/C5HLqvr0/" |
| 317 | + "ex8fHenV1VWjIFxcX9cHBgR4YGEg1Nzfrjo6OuM35BwCCsPnKQTo4SJNrQysrKzQxMUG1t" |
| 318 | + "bVSRxGm5aDZXBrLZMD3FgwK5uzs7AhYXV0dhUIhYZeXl9PS0pLQ4+" |
| 319 | + "Pj1NDQQLu7u1RUVKS4kdrHEi8yA4RO4kxNTdHm5iZtb28TmvSSCNHY2BhdXl7S2toajY6O" |
| 320 | + "UiAQINQarfcZYwOGr+" |
| 321 | + "FVV1dTU1MTFRcXe2IDyk2gxsZG6TqPC3FjRQcRZh14w5mZmRGDcDhMp6en4gjOuLs0OTlJ" |
| 322 | + "KMXy8jLV19cTd1psXmCFzP7p7+" |
| 323 | + "WVObm5kQYiUTo+vqahoeHCWPE3ae7uztvXqGUM0IDDa83NzcEYIDy4NPe3p6ADQ4Oypsb4ZUIdrapiQHJ/" |
| 324 | + "CI9GDw8PAh7YWGBzs7OhI7H45mqHo2UX82gJ0kTAEVa3d3dNDs7Kw3q6uoSJ6Z5GTYag22" |
| 325 | + "GMmt8TPT8XxeAnp4e+Q+jFLnAGFghZaygV+uKN484hZEBBX1/f+/" |
| 326 | + "xM6ICqVmOBZGwqqqqPrHRx/z8fPf29tbiJUH8f6XDw0PiVSZdfmOc6+lyFohi47/" |
| 327 | + "WVy6ENA/1l/" |
| 328 | + "XFg23zDhiRuqUXbBi1whJ9enqSQUWa7x3IcWHH0xDhLfUVYSpsWt6LMfZQwwX/" |
| 329 | + "wLVwWPG97osM9Wf7Df6GGOwnsP4BQFiPuOZ8wJUAAAAASUVORK5CYII="); |
| 330 | + |
| 331 | + native_tray_icon_id_t tray_id = native_tray_icon_get_id(g_tray_icon); |
| 332 | + printf("Tray ID: %ld\n", tray_id); |
| 333 | + |
| 334 | + char title_buffer[256]; |
| 335 | + int title_len = native_tray_icon_get_title(g_tray_icon, title_buffer, sizeof(title_buffer)); |
| 336 | + if (title_len >= 0) { |
| 337 | + printf("Tray Title: %s\n", title_buffer); |
| 338 | + } |
| 339 | + |
| 340 | + // Create context menu |
| 341 | + g_context_menu = create_context_menu(); |
| 342 | + |
| 343 | + // Set the context menu to the tray icon |
| 344 | + native_tray_icon_set_context_menu(g_tray_icon, g_context_menu); |
| 345 | + |
| 346 | + // Set up event listeners |
| 347 | + native_tray_icon_add_listener(g_tray_icon, NATIVE_TRAY_ICON_EVENT_CLICKED, on_tray_icon_clicked, NULL); |
| 348 | + native_tray_icon_add_listener(g_tray_icon, NATIVE_TRAY_ICON_EVENT_RIGHT_CLICKED, on_tray_icon_right_clicked, NULL); |
| 349 | + native_tray_icon_add_listener(g_tray_icon, NATIVE_TRAY_ICON_EVENT_DOUBLE_CLICKED, on_tray_icon_double_clicked, NULL); |
| 350 | + |
| 351 | + native_tray_icon_show(g_tray_icon); |
| 352 | + } else { |
| 353 | + fprintf(stderr, "Failed to create tray.\n"); |
| 354 | + } |
| 355 | + |
| 356 | + // Run the example app |
| 357 | + int result = native_run_example_app(); |
| 358 | + |
| 359 | + // Cleanup |
| 360 | + if (g_context_menu) { |
| 361 | + native_menu_destroy(g_context_menu); |
| 362 | + } |
| 363 | + if (g_tray_icon) { |
| 364 | + native_tray_icon_destroy(g_tray_icon); |
| 365 | + } |
| 366 | + |
| 367 | + native_window_manager_shutdown(); |
| 368 | + |
| 369 | + return result; |
| 370 | +} |
0 commit comments