From e0d400cc8f431f5711e0496a7c68ddd27f2e2f00 Mon Sep 17 00:00:00 2001 From: FelisCatus Date: Sun, 26 Feb 2017 20:40:25 -0500 Subject: [PATCH] Do not setIcon if icon cannot be drawn. Fix #715. --- .../background.coffee | 27 ++++++++++--------- .../src/tabs.coffee | 2 ++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/omega-target-chromium-extension/background.coffee b/omega-target-chromium-extension/background.coffee index 794d26f..fa44620 100644 --- a/omega-target-chromium-extension/background.coffee +++ b/omega-target-chromium-extension/background.coffee @@ -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 diff --git a/omega-target-chromium-extension/src/tabs.coffee b/omega-target-chromium-extension/src/tabs.coffee index 8ba3309..e82b79d 100644 --- a/omega-target-chromium-extension/src/tabs.coffee +++ b/omega-target-chromium-extension/src/tabs.coffee @@ -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