Skip to content

Commit

Permalink
Add option to enable/disable inspection in context menu. Fix #83.
Browse files Browse the repository at this point in the history
  • Loading branch information
FelisCatus committed Dec 22, 2014
1 parent 038b428 commit 7388664
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 4 deletions.
3 changes: 3 additions & 0 deletions omega-i18n/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
3 changes: 3 additions & 0 deletions omega-i18n/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
"options_refreshOnProfileChange": {
"message": "当更改情景模式时刷新当前标签"
},
"options_showInspectMenu": {
"message": "右键菜单中,可检查网页元素所使用的代理。"
},
"options_group_switchOptions": {
"message": "切换选项"
},
Expand Down
3 changes: 3 additions & 0 deletions omega-i18n/zh_HK/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
"options_refreshOnProfileChange": {
"message": "當更改情景模式時更新當前標籤"
},
"options_showInspectMenu": {
"message": "右鍵選單中,可檢查網頁元素所使用的代理。"
},
"options_group_switchOptions": {
"message": "切換選項"
},
Expand Down
3 changes: 3 additions & 0 deletions omega-i18n/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
"options_refreshOnProfileChange": {
"message": "當更改情景模式時重新整理當前標籤"
},
"options_showInspectMenu": {
"message": "右鍵選單中,可檢查網頁元素所使用的代理。"
},
"options_group_switchOptions": {
"message": "切換選項"
},
Expand Down
4 changes: 1 addition & 3 deletions omega-target-chromium-extension/background.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -167,8 +167,6 @@ inspect = new OmegaTargetCurrent.Inspect (url, tab) ->
color: action.resultColor
})

inspect.register()

options.setProxyNotControllable(null)
timeout = null

Expand Down
12 changes: 11 additions & 1 deletion omega-target-chromium-extension/src/inspect.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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://*/*"
Expand Down Expand Up @@ -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'
Expand Down
9 changes: 9 additions & 0 deletions omega-target-chromium-extension/src/options.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions omega-target/src/default_options.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = ->
"-quickSwitchProfiles": []
"-revertProxyChanges": false
"-confirmDeletion": true
"-showInspectMenu": true
"-downloadInterval": 1440
"+proxy":
bypassList: [
Expand Down
15 changes: 15 additions & 0 deletions omega-target/src/options.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions omega-web/src/partials/ui.jade
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7388664

Please sign in to comment.