getlantern / systray

a cross platfrom Go library to place an icon and menu in the notification area
Apache License 2.0
3.34k stars 464 forks source link

Feature request: support retina display for OS X #8

Open liudanking opened 9 years ago

liudanking commented 9 years ago

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.

myleshorton commented 9 years ago

@carsonefv or @Derekf5 you guys want to take a look at this?

xor-gate commented 8 years ago

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"

See: https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html#//apple_ref/doc/uid/TP40012302-CH7-SW13

liudanking commented 8 years ago

@xor-gate Awesome! It woks like a charm.

liudanking commented 8 years ago

@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.

xor-gate commented 8 years ago

The icon is gone? You must make sure you load the tiff as byte array and not the png.

liudanking commented 8 years ago

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.

xor-gate commented 8 years ago

Probably the application bundle loader is not properly configured to have support for multiimage. Could you paste your Plist.info?

liudanking commented 8 years ago

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>
xor-gate commented 8 years ago

Try adding:

    <key>LSMinimumSystemVersion</key>
    <string>10.10</string>

Probably it changes behaviour how the Foundation.framework is loaded and the image load process.

As: https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html

See my Info.plist: https://github.com/xor-gate/syncthing-mac/blob/master/template/Contents/Info.plist

liudanking commented 8 years ago

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.

liudanking commented 8 years ago

@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.

meskio commented 6 years ago

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?