Skip to content

Commit 5f95179

Browse files
committed
Refactor type casting and memory management on macOS
Updated type casting for tray icon IDs to use explicit static_cast for better type safety. Removed unnecessary manual memory management (release calls) for Objective-C objects in image handling, relying on ARC. Cleaned up unused variable in menu item state logic.
1 parent 05438a0 commit 5f95179

File tree

4 files changed

+2
-14
lines changed

4 files changed

+2
-14
lines changed

src/capi/tray_manager_c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ bool native_tray_manager_is_supported(void) {
1616

1717
native_tray_icon_t native_tray_manager_get(native_tray_icon_id_t tray_icon_id) {
1818
try {
19-
auto tray_icon = TrayManager::GetInstance().Get(tray_icon_id);
19+
auto tray_icon = TrayManager::GetInstance().Get(static_cast<TrayIconId>(tray_icon_id));
2020
return tray_icon ? static_cast<native_tray_icon_t>(tray_icon.get())
2121
: nullptr;
2222
} catch (...) {

src/platform/macos/image_macos.mm

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
Impl() : ns_image_(nil), size_({0, 0}), format_("Unknown") {}
2121

2222
~Impl() {
23-
if (ns_image_) {
24-
[ns_image_ release];
25-
}
2623
}
2724

2825
Impl(const Impl& other)
@@ -34,9 +31,6 @@
3431

3532
Impl& operator=(const Impl& other) {
3633
if (this != &other) {
37-
if (ns_image_) {
38-
[ns_image_ release];
39-
}
4034
ns_image_ = nil;
4135
source_ = other.source_;
4236
size_ = other.size_;
@@ -124,10 +118,7 @@
124118

125119
// Default assumption for base64 images
126120
image->pimpl_->format_ = "PNG";
127-
128-
[imageData release];
129121
} else {
130-
[imageData release];
131122
return nullptr;
132123
}
133124
} else {
@@ -179,7 +170,6 @@
179170
}
180171

181172
NSData* pngData = [bitmapRep representationUsingType:NSBitmapImageFileTypePNG properties:@{}];
182-
[bitmapRep release];
183173

184174
if (!pngData) {
185175
return "";
@@ -226,7 +216,6 @@
226216
}
227217

228218
NSData* imageData = [bitmapRep representationUsingType:fileType properties:properties];
229-
[bitmapRep release];
230219

231220
if (!imageData) {
232221
return false;

src/platform/macos/menu_macos.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,6 @@ - (void)menuDidClose:(NSMenu*)menu {
444444
// Get the MenuItemId from the associated object
445445
NSNumber* sibling_id_obj = objc_getAssociatedObject(sibling, kMenuItemIdKey);
446446
if (sibling_id_obj) {
447-
MenuItemId sibling_id = [sibling_id_obj longValue];
448447
// Find the corresponding MenuItem in the parent menu's items
449448
// This is a simplified approach - in practice, you might need to store
450449
// a reference to the parent menu or use a different strategy

src/platform/macos/tray_icon_macos.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ - (void)statusItemClicked:(id)sender;
4444
NSNumber* allocated_id = objc_getAssociatedObject(status_item, kTrayIconIdKey);
4545
if (allocated_id) {
4646
// Reuse allocated ID
47-
id_ = [allocated_id longValue];
47+
id_ = static_cast<TrayIconId>([allocated_id longValue]);
4848
} else {
4949
// Allocate new ID and store it
5050
id_ = IdAllocator::Allocate<TrayIcon>();

0 commit comments

Comments
 (0)