Files
MyGoNavi/internal/app/application_icon_darwin.go
Syngnat 176b100274 🐛 fix(app): 修复品牌图标与 SQLite 查询展示
- 修复 Windows、macOS 与关于页的品牌图标展示及资源裁切问题
- 补齐 SQLite 表记录数与 SELECT 查询结果渲染
- 增加品牌图标和 SQLite 回归测试
2026-07-15 22:53:47 +08:00

46 lines
948 B
Go

//go:build darwin
package app
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Cocoa
#import <Cocoa/Cocoa.h>
#import <dispatch/dispatch.h>
static int gonaviSetApplicationIconFromPNG(const void *data, int length) {
if (data == NULL || length <= 0) {
return 0;
}
NSData *pngData = [NSData dataWithBytes:data length:(NSUInteger)length];
if (pngData == nil) {
return 0;
}
NSImage *image = [[NSImage alloc] initWithData:pngData];
if (image == nil) {
return 0;
}
dispatch_async(dispatch_get_main_queue(), ^{
[NSApp setApplicationIconImage:image];
[image release];
});
return 1;
}
*/
import "C"
import (
"errors"
"unsafe"
)
func setApplicationIconPNG(png []byte) error {
if len(png) == 0 {
return errors.New("application icon PNG is empty")
}
if C.gonaviSetApplicationIconFromPNG(unsafe.Pointer(&png[0]), C.int(len(png))) == 0 {
return errors.New("failed to create macOS application icon image")
}
return nil
}