Do not setIcon if icon cannot be drawn. Fix #715.

This commit is contained in:
FelisCatus 2017-02-26 20:40:25 -05:00
parent 964155ed36
commit e0d400cc8f
2 changed files with 17 additions and 12 deletions

View File

@ -33,19 +33,22 @@ drawIcon = (resultColor, profileColor) ->
cacheKey = "omega+#{resultColor ? ''}+#{profileColor}"
icon = iconCache[cacheKey]
return icon if icon
if not drawContext?
drawContext = document.getElementById('canvas-icon').getContext('2d')
try
if not drawContext?
drawContext = document.getElementById('canvas-icon').getContext('2d')
icon = {}
for size in [16, 24, 32]
drawContext.scale(size, size)
drawContext.clearRect(0, 0, 1, 1)
if resultColor?
drawOmega drawContext, resultColor, profileColor
else
drawOmega drawContext, profileColor
drawContext.setTransform(1, 0, 0, 1, 0, 0)
icon[size] = drawContext.getImageData(0, 0, size, size)
icon = {}
for size in [16, 24, 32]
drawContext.scale(size, size)
drawContext.clearRect(0, 0, 1, 1)
if resultColor?
drawOmega drawContext, resultColor, profileColor
else
drawOmega drawContext, profileColor
drawContext.setTransform(1, 0, 0, 1, 0, 0)
icon[size] = drawContext.getImageData(0, 0, size, size)
catch
icon = null
return iconCache[cacheKey] = icon

View File

@ -63,6 +63,7 @@ class ChromeTabs
)
setIcon: (icon, tabId) ->
return unless icon?
if tabId?
chrome.browserAction.setIcon({
imageData: icon
@ -72,6 +73,7 @@ class ChromeTabs
chrome.browserAction.setIcon({imageData: icon}, @ignoreError)
clearIcon: (tabId) ->
return unless @_defaultAction?.icon?
chrome.browserAction.setIcon({
imageData: @_defaultAction.icon
tabId: tabId