Skip to content

Commit b201499

Browse files
committed
Refactor Image class for platform-specific implementations
Moved the generic Image implementation from image.cpp to a new macOS-specific implementation in image_macos.mm. The Image constructor is now private and only accessible via factory methods. Updated tray icon and menu code on macOS to use native NSImage objects from Image. Minor formatting and whitespace adjustments in tray icon code for Linux and Windows.
1 parent 0752bd2 commit b201499

File tree

9 files changed

+266
-95
lines changed

9 files changed

+266
-95
lines changed

include/nativeapi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "../src/foundation/event_emitter.h"
1010
#include "../src/foundation/geometry.h"
1111
#include "../src/foundation/id_allocator.h"
12+
#include "../src/image.h"
1213
#include "../src/keyboard_event.h"
1314
#include "../src/keyboard_monitor.h"
1415
#include "../src/menu.h"
@@ -18,14 +19,14 @@
1819
#include "../src/window.h"
1920
#include "../src/window_event.h"
2021
#include "../src/window_manager.h"
21-
#include "../src/image.h"
2222

2323
// Include necessary headers for C API
2424
#include "../src/capi/accessibility_manager_c.h"
2525
#include "../src/capi/app_runner_c.h"
2626
#include "../src/capi/display_c.h"
2727
#include "../src/capi/display_manager_c.h"
2828
#include "../src/capi/geometry_c.h"
29+
#include "../src/capi/image_c.h"
2930
#include "../src/capi/keyboard_monitor_c.h"
3031
#include "../src/capi/menu_c.h"
3132
#include "../src/capi/run_example_app_c.h"
@@ -34,4 +35,3 @@
3435
#include "../src/capi/tray_manager_c.h"
3536
#include "../src/capi/window_c.h"
3637
#include "../src/capi/window_manager_c.h"
37-
#include "../src/capi/image_c.h"

src/capi/tray_icon_c.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ native_tray_icon_id_t native_tray_icon_get_id(native_tray_icon_t tray_icon) {
8484
}
8585
}
8686

87-
void native_tray_icon_set_icon(native_tray_icon_t tray_icon, native_image_t image) {
87+
void native_tray_icon_set_icon(native_tray_icon_t tray_icon,
88+
native_image_t image) {
8889
if (!tray_icon)
8990
return;
9091

src/image.cpp

Lines changed: 0 additions & 72 deletions
This file was deleted.

src/image.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@ namespace nativeapi {
7171
*/
7272
class Image : public NativeObjectProvider {
7373
public:
74-
/**
75-
* @brief Default constructor.
76-
*
77-
* Creates an empty image instance.
78-
*/
79-
Image();
80-
8174
/**
8275
* @brief Destructor.
8376
*
@@ -244,6 +237,14 @@ class Image : public NativeObjectProvider {
244237
void* GetNativeObjectInternal() const override;
245238

246239
private:
240+
/**
241+
* @brief Private default constructor for use by factory methods.
242+
*
243+
* This constructor is private to prevent direct instantiation of Image objects.
244+
* Use the static factory methods (FromFile, FromBase64, FromSystemIcon) instead.
245+
*/
246+
Image();
247+
247248
/**
248249
* @brief Private implementation class using the PIMPL idiom.
249250
*

src/platform/linux/tray_icon_linux.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace nativeapi {
1717
class TrayIcon::Impl {
1818
public:
1919
std::shared_ptr<Image> image_;
20-
20+
2121
Impl(AppIndicator* indicator)
2222
: app_indicator_(indicator),
2323
title_(std::nullopt),
@@ -86,12 +86,12 @@ void TrayIcon::SetIcon(std::shared_ptr<Image> image) {
8686
if (image) {
8787
// For now, use a placeholder implementation
8888
// TODO: Implement proper Image to file conversion
89-
app_indicator_set_icon_full(pimpl_->app_indicator_, "application-default-icon",
90-
"Tray Icon");
89+
app_indicator_set_icon_full(pimpl_->app_indicator_,
90+
"application-default-icon", "Tray Icon");
9191
} else {
9292
// Use default icon
93-
app_indicator_set_icon_full(pimpl_->app_indicator_, "application-default-icon",
94-
"Tray Icon");
93+
app_indicator_set_icon_full(pimpl_->app_indicator_,
94+
"application-default-icon", "Tray Icon");
9595
}
9696
}
9797

0 commit comments

Comments
 (0)