Refactor CocoaSetDockIcon function

Refactor CocoaSetDockIcon to improve structure and readability.
This commit is contained in:
annes 2025-12-02 00:09:39 +08:00 committed by GitHub
parent c468628564
commit 738b81aa50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,9 +1,14 @@
#if defined(__APPLE__) #if defined(__APPLE__)
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import <objc/runtime.h> #import <objc/runtime.h>
#include "_cocoalayer.h" #include "_cocoalayer.h"
// Example: make a global function you can call
extern "C" void CocoaSetDockIcon(unsigned char* data, int width, int height) #ifdef __cplusplus
extern "C" {
#endif
void CocoaSetDockIcon(unsigned char* data, int width, int height)
{ {
NSImage *dockIcon = [[NSImage alloc] initWithSize:NSMakeSize(width, height)]; NSImage *dockIcon = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
CGDataProviderRef provider = CGDataProviderCreateWithData(nullptr, data, width*height*4, nullptr); CGDataProviderRef provider = CGDataProviderCreateWithData(nullptr, data, width*height*4, nullptr);
@ -17,4 +22,10 @@ extern "C" void CocoaSetDockIcon(unsigned char* data, int width, int height)
CGColorSpaceRelease(colorSpace); CGColorSpaceRelease(colorSpace);
CGDataProviderRelease(provider); CGDataProviderRelease(provider);
} }
#ifdef __cplusplus
}
#endif
#endif #endif