mirror of
https://github.com/zero-peak/ZeroOmega.git
synced 2025-01-22 23:08:13 -05:00
Make chrome.contextMenus and some browserAction APIs optional.
This commit is contained in:
parent
2442d1af5f
commit
227e189a73
@ -3,28 +3,30 @@ localStorage['log'] = ''
|
|||||||
localStorage['logLastError'] = ''
|
localStorage['logLastError'] = ''
|
||||||
|
|
||||||
window.OmegaContextMenuQuickSwitchHandler = -> null
|
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.
|
if chrome.contextMenus?
|
||||||
# https://developer.chrome.com/extensions/contextMenus
|
# We don't need this API. However its presence indicates that Chrome >= 35
|
||||||
if chrome.i18n.getUILanguage?
|
# which provides info.checked we need in contextMenu callback.
|
||||||
# We must create the menu item here before others to make it first in menu.
|
# 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({
|
chrome.contextMenus.create({
|
||||||
id: 'enableQuickSwitch'
|
title: chrome.i18n.getMessage('popup_reportIssues')
|
||||||
title: chrome.i18n.getMessage('contextMenu_enableQuickSwitch')
|
|
||||||
type: 'checkbox'
|
|
||||||
checked: false
|
|
||||||
contexts: ["browser_action"]
|
contexts: ["browser_action"]
|
||||||
onclick: (info) -> window.OmegaContextMenuQuickSwitchHandler(info)
|
onclick: OmegaDebug.reportIssue
|
||||||
})
|
})
|
||||||
|
|
||||||
chrome.contextMenus.create({
|
chrome.contextMenus.create({
|
||||||
title: chrome.i18n.getMessage('popup_reportIssues')
|
title: chrome.i18n.getMessage('popup_errorLog')
|
||||||
contexts: ["browser_action"]
|
contexts: ["browser_action"]
|
||||||
onclick: OmegaDebug.reportIssue
|
onclick: OmegaDebug.downloadLog
|
||||||
})
|
})
|
||||||
|
|
||||||
chrome.contextMenus.create({
|
|
||||||
title: chrome.i18n.getMessage('popup_errorLog')
|
|
||||||
contexts: ["browser_action"]
|
|
||||||
onclick: OmegaDebug.downloadLog
|
|
||||||
})
|
|
||||||
|
@ -22,7 +22,7 @@ module.exports = class ExternalApi
|
|||||||
return unless @disabled
|
return unless @disabled
|
||||||
|
|
||||||
@options.setProxyNotControllable(null)
|
@options.setProxyNotControllable(null)
|
||||||
chrome.browserAction.setPopup({popup: 'popup/index.html'})
|
chrome.browserAction.setPopup?({popup: 'popup/index.html'})
|
||||||
@options.reloadQuickSwitch()
|
@options.reloadQuickSwitch()
|
||||||
@disabled = false
|
@disabled = false
|
||||||
@options.clearBadge()
|
@options.clearBadge()
|
||||||
@ -49,7 +49,7 @@ module.exports = class ExternalApi
|
|||||||
if @knownExts[port.sender.id] >= 32
|
if @knownExts[port.sender.id] >= 32
|
||||||
reason = 'upgrade'
|
reason = 'upgrade'
|
||||||
@options.setProxyNotControllable reason, {text: 'X', color: '#5ab432'}
|
@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'})
|
port.postMessage({action: 'state', state: 'disabled'})
|
||||||
when 'enable'
|
when 'enable'
|
||||||
@reenable()
|
@reenable()
|
||||||
|
@ -8,6 +8,7 @@ module.exports = class Inspect
|
|||||||
@onInspect = onInspect
|
@onInspect = onInspect
|
||||||
|
|
||||||
enable: ->
|
enable: ->
|
||||||
|
return unless chrome.contextMenus?
|
||||||
# We don't need this API. However its presence indicates that Chrome >= 35,
|
# We don't need this API. However its presence indicates that Chrome >= 35,
|
||||||
# which provides the menuItemId we need in contextMenu callback.
|
# which provides the menuItemId we need in contextMenu callback.
|
||||||
# https://developer.chrome.com/extensions/contextMenus
|
# https://developer.chrome.com/extensions/contextMenus
|
||||||
|
@ -78,7 +78,7 @@ class ChromeOptions extends OmegaTarget.Options
|
|||||||
if @_proxyNotControllable
|
if @_proxyNotControllable
|
||||||
@setBadge()
|
@setBadge()
|
||||||
else
|
else
|
||||||
chrome.browserAction.setBadgeText(text: '')
|
chrome.browserAction.setBadgeText?(text: '')
|
||||||
return
|
return
|
||||||
|
|
||||||
_formatBypassItem: (condition) ->
|
_formatBypassItem: (condition) ->
|
||||||
@ -261,7 +261,7 @@ class ChromeOptions extends OmegaTarget.Options
|
|||||||
if not @_quickSwitchContextMenuCreated
|
if not @_quickSwitchContextMenuCreated
|
||||||
@_quickSwitchContextMenuCreated = true
|
@_quickSwitchContextMenuCreated = true
|
||||||
if quickSwitch
|
if quickSwitch
|
||||||
chrome.contextMenus.update('enableQuickSwitch', {checked: true})
|
chrome.contextMenus?.update('enableQuickSwitch', {checked: true})
|
||||||
window.OmegaContextMenuQuickSwitchHandler = (info) =>
|
window.OmegaContextMenuQuickSwitchHandler = (info) =>
|
||||||
changes = {}
|
changes = {}
|
||||||
changes['-enableQuickSwitch'] = info.checked
|
changes['-enableQuickSwitch'] = info.checked
|
||||||
@ -273,7 +273,7 @@ class ChromeOptions extends OmegaTarget.Options
|
|||||||
)
|
)
|
||||||
|
|
||||||
if quickSwitch
|
if quickSwitch
|
||||||
chrome.browserAction.setPopup({popup: ''})
|
chrome.browserAction.setPopup?({popup: ''})
|
||||||
if not @_quickSwitchInit
|
if not @_quickSwitchInit
|
||||||
@_quickSwitchInit = true
|
@_quickSwitchInit = true
|
||||||
chrome.browserAction.onClicked.addListener (tab) =>
|
chrome.browserAction.onClicked.addListener (tab) =>
|
||||||
@ -290,7 +290,7 @@ class ChromeOptions extends OmegaTarget.Options
|
|||||||
return if url.substr(0, 4) == 'moz-'
|
return if url.substr(0, 4) == 'moz-'
|
||||||
chrome.tabs.reload(tab.id)
|
chrome.tabs.reload(tab.id)
|
||||||
else
|
else
|
||||||
chrome.browserAction.setPopup({popup: 'popup/index.html'})
|
chrome.browserAction.setPopup?({popup: 'popup/index.html'})
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
|
|
||||||
setInspect: (settings) ->
|
setInspect: (settings) ->
|
||||||
|
@ -39,7 +39,7 @@ class ChromeTabs
|
|||||||
processTab: (tab, changeInfo) ->
|
processTab: (tab, changeInfo) ->
|
||||||
if @_badgeTab
|
if @_badgeTab
|
||||||
for own id of @_badgeTab
|
for own id of @_badgeTab
|
||||||
try chrome.browserAction.setBadgeText(text: '', tabId: id)
|
try chrome.browserAction.setBadgeText?(text: '', tabId: id)
|
||||||
@_badgeTab = null
|
@_badgeTab = null
|
||||||
if not tab.url? or tab.url.indexOf("chrome") == 0
|
if not tab.url? or tab.url.indexOf("chrome") == 0
|
||||||
if @_defaultAction
|
if @_defaultAction
|
||||||
@ -56,8 +56,8 @@ class ChromeTabs
|
|||||||
setTabBadge: (tab, badge) ->
|
setTabBadge: (tab, badge) ->
|
||||||
@_badgeTab ?= {}
|
@_badgeTab ?= {}
|
||||||
@_badgeTab[tab.id] = true
|
@_badgeTab[tab.id] = true
|
||||||
chrome.browserAction.setBadgeText(text: badge.text, tabId: tab.id)
|
chrome.browserAction.setBadgeText?(text: badge.text, tabId: tab.id)
|
||||||
chrome.browserAction.setBadgeBackgroundColor(
|
chrome.browserAction.setBadgeBackgroundColor?(
|
||||||
color: badge.color
|
color: badge.color
|
||||||
tabId: tab.id
|
tabId: tab.id
|
||||||
)
|
)
|
||||||
@ -77,11 +77,11 @@ class ChromeTabs
|
|||||||
|
|
||||||
_chromeSetIcon: (params) ->
|
_chromeSetIcon: (params) ->
|
||||||
try
|
try
|
||||||
chrome.browserAction.setIcon(params, @ignoreError)
|
chrome.browserAction.setIcon?(params, @ignoreError)
|
||||||
catch
|
catch
|
||||||
# Some legacy Chrome versions will panic if there are other icon sizes.
|
# Some legacy Chrome versions will panic if there are other icon sizes.
|
||||||
params.imageData = {19: params.imageData[19], 38: params.imageData[38]}
|
params.imageData = {19: params.imageData[19], 38: params.imageData[38]}
|
||||||
chrome.browserAction.setIcon(params, @ignoreError)
|
chrome.browserAction.setIcon?(params, @ignoreError)
|
||||||
|
|
||||||
clearIcon: (tabId) ->
|
clearIcon: (tabId) ->
|
||||||
return unless @_defaultAction?.icon?
|
return unless @_defaultAction?.icon?
|
||||||
|
Loading…
Reference in New Issue
Block a user