diff --git a/omega-target-chromium-extension/src/coffee/background_preload.coffee b/omega-target-chromium-extension/src/coffee/background_preload.coffee index e2de513..ced9727 100644 --- a/omega-target-chromium-extension/src/coffee/background_preload.coffee +++ b/omega-target-chromium-extension/src/coffee/background_preload.coffee @@ -3,28 +3,30 @@ localStorage['log'] = '' localStorage['logLastError'] = '' window.OmegaContextMenuQuickSwitchHandler = -> null -# We don't need this API. However its presence indicates that Chrome >= 35 -# which provides info.checked we need in contextMenu callback. -# https://developer.chrome.com/extensions/contextMenus -if chrome.i18n.getUILanguage? - # We must create the menu item here before others to make it first in menu. + +if chrome.contextMenus? + # We don't need this API. However its presence indicates that Chrome >= 35 + # which provides info.checked we need in contextMenu callback. + # https://developer.chrome.com/extensions/contextMenus + if chrome.i18n.getUILanguage? + # We must create the menu item here before others to make it first in menu. + chrome.contextMenus.create({ + id: 'enableQuickSwitch' + title: chrome.i18n.getMessage('contextMenu_enableQuickSwitch') + type: 'checkbox' + checked: false + contexts: ["browser_action"] + onclick: (info) -> window.OmegaContextMenuQuickSwitchHandler(info) + }) + chrome.contextMenus.create({ - id: 'enableQuickSwitch' - title: chrome.i18n.getMessage('contextMenu_enableQuickSwitch') - type: 'checkbox' - checked: false + title: chrome.i18n.getMessage('popup_reportIssues') contexts: ["browser_action"] - onclick: (info) -> window.OmegaContextMenuQuickSwitchHandler(info) + onclick: OmegaDebug.reportIssue }) -chrome.contextMenus.create({ - title: chrome.i18n.getMessage('popup_reportIssues') - contexts: ["browser_action"] - onclick: OmegaDebug.reportIssue -}) - -chrome.contextMenus.create({ - title: chrome.i18n.getMessage('popup_errorLog') - contexts: ["browser_action"] - onclick: OmegaDebug.downloadLog -}) + chrome.contextMenus.create({ + title: chrome.i18n.getMessage('popup_errorLog') + contexts: ["browser_action"] + onclick: OmegaDebug.downloadLog + }) diff --git a/omega-target-chromium-extension/src/module/external_api.coffee b/omega-target-chromium-extension/src/module/external_api.coffee index 6768809..8f58534 100644 --- a/omega-target-chromium-extension/src/module/external_api.coffee +++ b/omega-target-chromium-extension/src/module/external_api.coffee @@ -22,7 +22,7 @@ module.exports = class ExternalApi return unless @disabled @options.setProxyNotControllable(null) - chrome.browserAction.setPopup({popup: 'popup/index.html'}) + chrome.browserAction.setPopup?({popup: 'popup/index.html'}) @options.reloadQuickSwitch() @disabled = false @options.clearBadge() @@ -49,7 +49,7 @@ module.exports = class ExternalApi if @knownExts[port.sender.id] >= 32 reason = 'upgrade' @options.setProxyNotControllable reason, {text: 'X', color: '#5ab432'} - chrome.browserAction.setPopup({popup: 'popup/index.html'}) + chrome.browserAction.setPopup?({popup: 'popup/index.html'}) port.postMessage({action: 'state', state: 'disabled'}) when 'enable' @reenable() diff --git a/omega-target-chromium-extension/src/module/inspect.coffee b/omega-target-chromium-extension/src/module/inspect.coffee index 279ca64..7fa2375 100644 --- a/omega-target-chromium-extension/src/module/inspect.coffee +++ b/omega-target-chromium-extension/src/module/inspect.coffee @@ -8,6 +8,7 @@ module.exports = class Inspect @onInspect = onInspect enable: -> + return unless chrome.contextMenus? # We don't need this API. However its presence indicates that Chrome >= 35, # which provides the menuItemId we need in contextMenu callback. # https://developer.chrome.com/extensions/contextMenus diff --git a/omega-target-chromium-extension/src/module/options.coffee b/omega-target-chromium-extension/src/module/options.coffee index 42e8a90..a3d0228 100644 --- a/omega-target-chromium-extension/src/module/options.coffee +++ b/omega-target-chromium-extension/src/module/options.coffee @@ -78,7 +78,7 @@ class ChromeOptions extends OmegaTarget.Options if @_proxyNotControllable @setBadge() else - chrome.browserAction.setBadgeText(text: '') + chrome.browserAction.setBadgeText?(text: '') return _formatBypassItem: (condition) -> @@ -261,7 +261,7 @@ class ChromeOptions extends OmegaTarget.Options if not @_quickSwitchContextMenuCreated @_quickSwitchContextMenuCreated = true if quickSwitch - chrome.contextMenus.update('enableQuickSwitch', {checked: true}) + chrome.contextMenus?.update('enableQuickSwitch', {checked: true}) window.OmegaContextMenuQuickSwitchHandler = (info) => changes = {} changes['-enableQuickSwitch'] = info.checked @@ -273,7 +273,7 @@ class ChromeOptions extends OmegaTarget.Options ) if quickSwitch - chrome.browserAction.setPopup({popup: ''}) + chrome.browserAction.setPopup?({popup: ''}) if not @_quickSwitchInit @_quickSwitchInit = true chrome.browserAction.onClicked.addListener (tab) => @@ -290,7 +290,7 @@ class ChromeOptions extends OmegaTarget.Options return if url.substr(0, 4) == 'moz-' chrome.tabs.reload(tab.id) else - chrome.browserAction.setPopup({popup: 'popup/index.html'}) + chrome.browserAction.setPopup?({popup: 'popup/index.html'}) Promise.resolve() setInspect: (settings) -> diff --git a/omega-target-chromium-extension/src/module/tabs.coffee b/omega-target-chromium-extension/src/module/tabs.coffee index 4fda0ce..7dc5104 100644 --- a/omega-target-chromium-extension/src/module/tabs.coffee +++ b/omega-target-chromium-extension/src/module/tabs.coffee @@ -39,7 +39,7 @@ class ChromeTabs processTab: (tab, changeInfo) -> if @_badgeTab for own id of @_badgeTab - try chrome.browserAction.setBadgeText(text: '', tabId: id) + try chrome.browserAction.setBadgeText?(text: '', tabId: id) @_badgeTab = null if not tab.url? or tab.url.indexOf("chrome") == 0 if @_defaultAction @@ -56,8 +56,8 @@ class ChromeTabs setTabBadge: (tab, badge) -> @_badgeTab ?= {} @_badgeTab[tab.id] = true - chrome.browserAction.setBadgeText(text: badge.text, tabId: tab.id) - chrome.browserAction.setBadgeBackgroundColor( + chrome.browserAction.setBadgeText?(text: badge.text, tabId: tab.id) + chrome.browserAction.setBadgeBackgroundColor?( color: badge.color tabId: tab.id ) @@ -77,11 +77,11 @@ class ChromeTabs _chromeSetIcon: (params) -> try - chrome.browserAction.setIcon(params, @ignoreError) + chrome.browserAction.setIcon?(params, @ignoreError) catch # Some legacy Chrome versions will panic if there are other icon sizes. params.imageData = {19: params.imageData[19], 38: params.imageData[38]} - chrome.browserAction.setIcon(params, @ignoreError) + chrome.browserAction.setIcon?(params, @ignoreError) clearIcon: (tabId) -> return unless @_defaultAction?.icon?