Add option to enable/disable inspection in context menu. Fix #83.

This commit is contained in:
FelisCatus 2014-12-22 19:34:24 +08:00
parent 038b428619
commit 73886642bf
10 changed files with 53 additions and 4 deletions

View File

@ -157,6 +157,9 @@
"options_refreshOnProfileChange": {
"message": "Refresh current tab on profile change."
},
"options_showInspectMenu": {
"message": "Allow inspecting proxy used for page elements via context menu."
},
"options_group_switchOptions": {
"message": "Switch Options"
},

View File

@ -157,6 +157,9 @@
"options_refreshOnProfileChange": {
"message": "当更改情景模式时刷新当前标签"
},
"options_showInspectMenu": {
"message": "右键菜单中,可检查网页元素所使用的代理。"
},
"options_group_switchOptions": {
"message": "切换选项"
},

View File

@ -157,6 +157,9 @@
"options_refreshOnProfileChange": {
"message": "當更改情景模式時更新當前標籤"
},
"options_showInspectMenu": {
"message": "右鍵選單中,可檢查網頁元素所使用的代理。"
},
"options_group_switchOptions": {
"message": "切換選項"
},

View File

@ -157,6 +157,9 @@
"options_refreshOnProfileChange": {
"message": "當更改情景模式時重新整理當前標籤"
},
"options_showInspectMenu": {
"message": "右鍵選單中,可檢查網頁元素所使用的代理。"
},
"options_group_switchOptions": {
"message": "切換選項"
},

View File

@ -143,7 +143,7 @@ if chrome.runtime.id != OmegaTargetCurrent.SwitchySharp.extId
tabs = new OmegaTargetCurrent.ChromeTabs(actionForUrl)
tabs.watch()
inspect = new OmegaTargetCurrent.Inspect (url, tab) ->
options._inspect = new OmegaTargetCurrent.Inspect (url, tab) ->
if url == tab.url
options.clearBadge()
tabs.processTab(tab)
@ -167,8 +167,6 @@ inspect = new OmegaTargetCurrent.Inspect (url, tab) ->
color: action.resultColor
})
inspect.register()
options.setProxyNotControllable(null)
timeout = null

View File

@ -3,14 +3,16 @@ OmegaPac = OmegaTarget.OmegaPac
Promise = OmegaTarget.Promise
module.exports = class Inspect
_enabled: false
constructor: (@onInspect) ->
register: ->
enable: ->
# 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
return unless chrome.i18n.getUILanguage?
return if @_enabled
webResource = [
"http://*/*"
@ -56,6 +58,14 @@ module.exports = class Inspect
targetUrlPatterns: webResource
})
@_enabled = true
disable: ->
return unless @_enabled
for own menuId of @propForMenuItem
try chrome.contextMenus.remove(menuId)
@_enabled = false
propForMenuItem:
'inspectPage': 'pageUrl'
'inspectFrame': 'frameUrl'

View File

@ -9,6 +9,7 @@ parseExternalProfile = require('./parse_external_profile')
ProxyAuth = require('./proxy_auth')
class ChromeOptions extends OmegaTarget.Options
_inspect: null
parseExternalProfile: (details) ->
parseExternalProfile(details, @_options, @_fixedProfileConfig.bind(this))
@ -178,6 +179,14 @@ class ChromeOptions extends OmegaTarget.Options
chrome.browserAction.setPopup({popup: 'popup.html'})
Promise.resolve()
setInspect: (settings) ->
if @_inspect
if settings.showMenu
@_inspect.enable()
else
@_inspect.disable()
return Promise.resolve()
_alarms: null
schedule: (name, periodInMinutes, callback) ->
name = 'omega.' + name

View File

@ -6,6 +6,7 @@ module.exports = ->
"-quickSwitchProfiles": []
"-revertProxyChanges": false
"-confirmDeletion": true
"-showInspectMenu": true
"-downloadInterval": 1440
"+proxy":
bypassList: [

View File

@ -263,6 +263,12 @@ class Options
if changes['-downloadInterval']?
@schedule 'updateProfile', @_options['-downloadInterval'], =>
@updateProfile()
if changes['-showInspectMenu']? or changes == @_options
showMenu = @_options['-showInspectMenu']
if not showMenu?
showMenu = true
@_setOptions({'-showInspectMenu': true}, {persist: true})
@setInspect(showMenu: showMenu)
handler()
@_storage.watch null, handler
@ -281,6 +287,15 @@ class Options
else
@setQuickSwitch(null)
###*
# Apply the settings related to element proxy inspection.
# In base class, this method is not implemented and will not do anything.
# @param {{}} settings
# @param {boolean} settings.showMenu Whether to show the menu or not
# @returns {Promise} A promise which is fulfilled when the settings apply
###
setInspect: -> Promise.resolve()
###*
# @callback watchCallback
# @param {Object.<string, {}>} changes A map from keys to values.

View File

@ -10,6 +10,10 @@ section.settings-group
label
input#refresh-on-profile-change(type='checkbox' ng-model='options["-refreshOnProfileChange"]')
span {{'options_refreshOnProfileChange' | tr}}
div.checkbox
label
input(type='checkbox' ng-model='options["-showInspectMenu"]')
span {{'options_showInspectMenu' | tr}}
section.settings-group
h3 {{'options_group_switchOptions' | tr}}
div.form-group