File tree Expand file tree Collapse file tree 11 files changed +15
-151
lines changed
Expand file tree Collapse file tree 11 files changed +15
-151
lines changed Original file line number Diff line number Diff line change @@ -160,7 +160,7 @@ int main() {
160160 }
161161
162162 // Create tray icon
163- native_tray_icon_t tray_icon = native_tray_manager_create ();
163+ native_tray_icon_t tray_icon = native_tray_icon_create ();
164164 if (!tray_icon ) {
165165 printf ("Error: Failed to create tray icon!\n" );
166166 native_menu_destroy (menu );
Original file line number Diff line number Diff line change @@ -27,15 +27,15 @@ int main() {
2727 [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
2828#endif
2929
30- // Get TrayManager instance (singleton pattern)
30+ // Check if tray icons are supported
3131 TrayManager& trayManager = TrayManager::GetInstance ();
3232 if (!trayManager.IsSupported ()) {
3333 std::cerr << " Tray icons are not supported on this platform!" << std::endl;
3434 return 1 ;
3535 }
3636
37- // Create a tray icon
38- auto trayIcon = trayManager. Create ();
37+ // Create a tray icon directly
38+ auto trayIcon = std::make_shared<TrayIcon> ();
3939 if (!trayIcon) {
4040 std::cerr << " Failed to create tray icon!" << std::endl;
4141 return 1 ;
Original file line number Diff line number Diff line change @@ -290,7 +290,7 @@ int main() {
290290 native_window_options_destroy (options );
291291
292292 // Create tray icon
293- g_tray_icon = native_tray_manager_create ();
293+ g_tray_icon = native_tray_icon_create ();
294294 if (g_tray_icon != NULL ) {
295295 native_tray_icon_set_icon (g_tray_icon ,
296296 "data:image/png;base64,"
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ int main() {
4242 options.centered = true ;
4343 std::shared_ptr<Window> window_ptr = window_manager.Create (options);
4444
45- std::shared_ptr<TrayIcon> tray_icon_ptr = tray_manager. Create ();
45+ std::shared_ptr<TrayIcon> tray_icon_ptr = std::make_shared<TrayIcon> ();
4646 if (tray_icon_ptr != nullptr ) {
4747 TrayIcon& tray_icon = *tray_icon_ptr;
4848 tray_icon.SetIcon (
Original file line number Diff line number Diff line change @@ -14,16 +14,6 @@ bool native_tray_manager_is_supported(void) {
1414 }
1515}
1616
17- native_tray_icon_t native_tray_manager_create (void ) {
18- try {
19- auto tray_icon = TrayManager::GetInstance ().Create ();
20- return tray_icon ? static_cast <native_tray_icon_t >(tray_icon.get ())
21- : nullptr ;
22- } catch (...) {
23- return nullptr ;
24- }
25- }
26-
2717native_tray_icon_t native_tray_manager_get (native_tray_icon_id_t tray_icon_id) {
2818 try {
2919 auto tray_icon = TrayManager::GetInstance ().Get (tray_icon_id);
@@ -67,14 +57,6 @@ native_tray_icon_list_t native_tray_manager_get_all(void) {
6757 }
6858}
6959
70- bool native_tray_manager_destroy (native_tray_icon_id_t tray_icon_id) {
71- try {
72- return TrayManager::GetInstance ().Destroy (tray_icon_id);
73- } catch (...) {
74- return false ;
75- }
76- }
77-
7860// Utility functions
7961
8062void native_tray_icon_list_free (native_tray_icon_list_t list) {
Original file line number Diff line number Diff line change @@ -35,13 +35,6 @@ typedef struct {
3535FFI_PLUGIN_EXPORT
3636bool native_tray_manager_is_supported (void );
3737
38- /**
39- * Create a new tray icon
40- * @return Tray icon handle, or NULL if creation failed
41- */
42- FFI_PLUGIN_EXPORT
43- native_tray_icon_t native_tray_manager_create (void );
44-
4538/**
4639 * Get a tray icon by its ID
4740 * @param tray_icon_id The tray icon ID
@@ -57,14 +50,6 @@ native_tray_icon_t native_tray_manager_get(native_tray_icon_id_t tray_icon_id);
5750FFI_PLUGIN_EXPORT
5851native_tray_icon_list_t native_tray_manager_get_all (void );
5952
60- /**
61- * Destroy a tray icon by its ID
62- * @param tray_icon_id The tray icon ID to destroy
63- * @return true if tray icon was found and destroyed, false otherwise
64- */
65- FFI_PLUGIN_EXPORT
66- bool native_tray_manager_destroy (native_tray_icon_id_t tray_icon_id );
67-
6853/**
6954 * Utility functions
7055 */
Original file line number Diff line number Diff line change @@ -62,22 +62,6 @@ bool TrayManager::IsSupported() {
6262#endif
6363}
6464
65- std::shared_ptr<TrayIcon> TrayManager::Create () {
66- std::lock_guard<std::mutex> lock (mutex_);
67-
68- #if HAS_GTK && HAS_AYATANA_APPINDICATOR
69- // Create tray icon with platform-specific initialization handled internally
70- auto tray = std::make_shared<TrayIcon>();
71- tray->id = next_tray_id_++;
72- trays_[tray->id ] = tray;
73-
74- return tray;
75- #else
76- // AppIndicator not available, return nullptr
77- return nullptr ;
78- #endif
79- }
80-
8165std::shared_ptr<TrayIcon> TrayManager::Get (TrayIconID id) {
8266 std::lock_guard<std::mutex> lock (mutex_);
8367
@@ -98,18 +82,4 @@ std::vector<std::shared_ptr<TrayIcon>> TrayManager::GetAll() {
9882 return trays;
9983}
10084
101- bool TrayManager::Destroy (TrayIconID id) {
102- std::lock_guard<std::mutex> lock (mutex_);
103-
104- auto it = trays_.find (id);
105- if (it != trays_.end ()) {
106- // Remove the tray icon from our container
107- // The shared_ptr will automatically clean up when the last reference is
108- // released
109- trays_.erase (it);
110- return true ;
111- }
112- return false ;
113- }
114-
11585} // namespace nativeapi
Original file line number Diff line number Diff line change 5656 return true ;
5757}
5858
59- std::shared_ptr<TrayIcon> TrayManager::Create () {
60- std::lock_guard<std::mutex> lock (mutex_);
61-
62- // Create tray icon with platform-specific initialization handled internally
63- auto tray = std::make_shared<TrayIcon>();
64- tray->id = next_tray_id_++;
65- trays_[tray->id ] = tray;
66-
67- return tray;
68- }
69-
7059std::shared_ptr<TrayIcon> TrayManager::Get (TrayIconID id ) {
7160 std::lock_guard<std::mutex> lock (mutex_);
7261
8776 return trays;
8877}
8978
90- bool TrayManager::Destroy (TrayIconID id ) {
91- std::lock_guard<std::mutex> lock (mutex_);
92-
93- auto it = trays_.find (id );
94- if (it != trays_.end ()) {
95- // Remove the tray icon from our container
96- // The shared_ptr will automatically clean up when the last reference is released
97- trays_.erase (it);
98- return true ;
99- }
100- return false ;
101- }
102-
10379} // namespace nativeapi
Original file line number Diff line number Diff line change @@ -87,17 +87,6 @@ bool TrayManager::IsSupported() {
8787 return true ; // Windows always supports system tray
8888}
8989
90- std::shared_ptr<TrayIcon> TrayManager::Create () {
91- std::lock_guard<std::mutex> lock (mutex_);
92-
93- // Create tray icon with platform-specific initialization handled internally
94- auto tray = std::make_shared<TrayIcon>();
95- tray->id = next_tray_id_++;
96- trays_[tray->id ] = tray;
97-
98- return tray;
99- }
100-
10190std::shared_ptr<TrayIcon> TrayManager::Get (TrayIconID id) {
10291 std::lock_guard<std::mutex> lock (mutex_);
10392
@@ -118,18 +107,4 @@ std::vector<std::shared_ptr<TrayIcon>> TrayManager::GetAll() {
118107 return trays;
119108}
120109
121- bool TrayManager::Destroy (TrayIconID id) {
122- std::lock_guard<std::mutex> lock (mutex_);
123-
124- auto it = trays_.find (id);
125- if (it != trays_.end ()) {
126- // Remove the tray icon from our container
127- // The shared_ptr will automatically clean up when the last reference is
128- // released
129- trays_.erase (it);
130- return true ;
131- }
132- return false ;
133- }
134-
135110} // namespace nativeapi
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ typedef long TrayIconID;
5858 * trayIcon->SetContextMenu(menu);
5959 *
6060 * // Show the tray icon
61- * trayIcon->Show( );
61+ * trayIcon->SetVisible(true );
6262 * ```
6363 */
6464class TrayIcon : public EventEmitter , public NativeObjectProvider {
You can’t perform that action at this time.
0 commit comments