Open liudanking opened 9 years ago
@carsonefv or @Derekf5 you guys want to take a look at this?
It is far easier than you think you have to create 2 png (imagemagick convert) files with 2x increment in size and then squash them together into a tiff (tiffutil) and then load as normal:
convert -background none img/darwin/$ICON.svg -resize 32x32 -sharpen 1 img/darwin/$ICON.png
convert -background none img/darwin/$ICON.svg -resize 64x64 -sharpen 1 img/darwin/$ICON@2x.png
tiffutil -cathidpicheck img/darwin/$ICON.png img/darwin/$ICON@2x.png -out img/darwin/$ICON.tiff
$GOPATH/bin/2goarray $ICON main < img/darwin/$ICON.tiff | grep -v package >> "$OUTPUT"
@xor-gate Awesome! It woks like a charm.
@xor-gate I meet another problem:
After I packaged my golang-app into a OSX application, say foo.app, the retina icon is gone. It seems that OS X add some actions when launching foo.app, but have no idea what did it do.
The icon is gone? You must make sure you load the tiff as byte array and not the png.
I mean the retina icon is not shown, only the default one is shown.
I am pretty sure I load the tiff as byte array, because if I copy foo.app/Contents/MacOS/foo
to a normal directory, and launch foo with ./foo
, the retina icon is displayed as expected.
Probably the application bundle loader is not properly configured to have support for multiimage. Could you paste your Plist.info
?
Below is my info.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist
SYSTEM 'file://localhost/System/Library/DTDs/PropertyList.dtd'>
<plist version="0.9">
<dict>
<key>CFBundleExecutable</key>
<string>foo</string>
<key>CFBundleGetInfoString</key>
<string>hi</string>
<key>CFBundleIconFile</key>
<string>app.icns</string>
<key>CFBundleIdentifier</key>
<string>foo</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>foo</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.0.1</string>
<key>CFBundleSignature</key>
<string>WRUN</string>
<key>CFBundleVersion</key>
<string>0.0.3</string>
<!-- Set LSUIElement to indicate this is an agent app, meaning that it
does not get an icon in the dock. -->
<key>LSUIElement</key>
<string>1</string>
</dict>
</plist>
Try adding:
<key>LSMinimumSystemVersion</key>
<string>10.10</string>
Probably it changes behaviour how the Foundation.framework is loaded and the image load process.
See my Info.plist
: https://github.com/xor-gate/syncthing-mac/blob/master/template/Contents/Info.plist
I still can not make it work after adding LSMinimumSystemVersion
.
I find your Info.plist
have much more items than mine, I will check all these items tomorrow.
@xor-gate With some luck, the problem is solved by adding:
<key>LSMinimumSystemVersion</key>
<string>10.10</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
Many thanks for your help.
I'm a bit confused reading the code it seems that 16x16 is hardcoded as icon size: https://github.com/getlantern/systray/blob/master/systray_darwin.m#L162
Is that not true? Does the library support other icon sizes for OS X?
Systray only uses the same icon for both normal and retina display which makes systray icon looks not smooth for retina display. To support retina display icon, it may need to update some OC codes. As I am not a OC programmer, hope someone will implement it.