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

View File

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