fix(tray): Retina tray icon with template image for dark menu bar mode

This commit is contained in:
Ben Gotow 2015-11-17 15:36:52 -08:00
parent 74252d58d9
commit 3a16484d7d
4 changed files with 9 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

View file

@ -75,11 +75,17 @@ class TrayStore extends NylasStore {
const imgHandlers = { const imgHandlers = {
'darwin': ()=> { 'darwin': ()=> {
const img = new Image(); const img = new Image();
// This is synchronous because it's a data url // toDataUrl always returns the @1x image data, so the assets/darwin/
// contains an "@2x" image /without/ the @2x extension
img.src = this._baseIcon.toDataUrl(); img.src = this._baseIcon.toDataUrl();
const count = this._unreadCount || ''; const count = this._unreadCount || '';
const canvas = canvasWithSystemTrayIconAndText(img, count.toString()); const canvas = canvasWithSystemTrayIconAndText(img, count.toString());
return NativeImage.createFromDataUrl(canvas.toDataURL()); const pngData = NativeImage.createFromDataUrl(canvas.toDataURL()).toPng();
// creating from a buffer allows us to specify that the image is @2x
const out2x = NativeImage.createFromBuffer(pngData, 2);
out2x.setTemplateImage(true);
return out2x;
}, },
'default': ()=> { 'default': ()=> {
return unreadCount > 0 ? this._unreadIcon : this._baseIcon; return unreadCount > 0 ? this._unreadIcon : this._baseIcon;

View file

@ -82,7 +82,7 @@ CanvasUtils =
canvas = SystemTrayCanvas canvas = SystemTrayCanvas
w = img.width w = img.width
h = img.height h = img.height
font = '14px Nylas-Pro, sans-serif' font = '26px Nylas-Pro, sans-serif'
textWidth = if text.length > 0 then CanvasUtils.measureTextInCanvas(text, font) + 2 else 0 textWidth = if text.length > 0 then CanvasUtils.measureTextInCanvas(text, font) + 2 else 0
canvas.width = w + textWidth canvas.width = w + textWidth