mirror of
https://github.com/zero-peak/ZeroOmega.git
synced 2025-01-22 15:08:12 -05:00
Fix externalProfile watcher after refactoring. Fix #1607.
This commit is contained in:
parent
2ad6ffa3c0
commit
e2d9293e5a
@ -253,10 +253,12 @@ proxyImpl.watchProxyChange (details) ->
|
||||
clearTimeout(timeout) if timeout?
|
||||
parsed = null
|
||||
timeout = setTimeout (->
|
||||
options.setExternalProfile(parsed, {noRevert: noRevert, internal: internal})
|
||||
if parsed
|
||||
options.setExternalProfile(parsed,
|
||||
{noRevert: noRevert, internal: internal})
|
||||
), 500
|
||||
|
||||
parsed = options.parseExternalProfile(details)
|
||||
parsed = proxyImpl.parseExternalProfile(details, options._options)
|
||||
return
|
||||
|
||||
external = false
|
||||
|
@ -2,7 +2,6 @@ OmegaTarget = require('omega-target')
|
||||
OmegaPac = OmegaTarget.OmegaPac
|
||||
Promise = OmegaTarget.Promise
|
||||
querystring = require('querystring')
|
||||
parseExternalProfile = require('./parse_external_profile')
|
||||
WebRequestMonitor = require('./web_request_monitor')
|
||||
ChromePort = require('./chrome_port')
|
||||
fetchUrl = require('./fetch_url')
|
||||
@ -10,8 +9,6 @@ Url = require('url')
|
||||
|
||||
class ChromeOptions extends OmegaTarget.Options
|
||||
_inspect: null
|
||||
parseExternalProfile: (details) ->
|
||||
parseExternalProfile(details, @_options, @_fixedProfileConfig.bind(this))
|
||||
|
||||
fetchUrl: fetchUrl
|
||||
|
||||
|
@ -1,110 +0,0 @@
|
||||
OmegaTarget = require('omega-target')
|
||||
OmegaPac = OmegaTarget.OmegaPac
|
||||
|
||||
module.exports = (details, options, fixedProfileConfig) ->
|
||||
if details.name
|
||||
details
|
||||
else
|
||||
switch details.value.mode
|
||||
when 'system'
|
||||
OmegaPac.Profiles.byName('system')
|
||||
when 'direct'
|
||||
OmegaPac.Profiles.byName('direct')
|
||||
when 'auto_detect'
|
||||
OmegaPac.Profiles.create({
|
||||
profileType: 'PacProfile'
|
||||
name: ''
|
||||
pacUrl: 'http://wpad/wpad.dat'
|
||||
})
|
||||
when 'pac_script'
|
||||
url = details.value.pacScript.url
|
||||
if url
|
||||
profile = null
|
||||
OmegaPac.Profiles.each options, (key, p) ->
|
||||
if p.profileType == 'PacProfile' and p.pacUrl == url
|
||||
profile = p
|
||||
profile ? OmegaPac.Profiles.create({
|
||||
profileType: 'PacProfile'
|
||||
name: ''
|
||||
pacUrl: url
|
||||
})
|
||||
else do ->
|
||||
profile = null
|
||||
script = details.value.pacScript.data
|
||||
OmegaPac.Profiles.each options, (key, p) ->
|
||||
if p.profileType == 'PacProfile' and p.pacScript == script
|
||||
profile = p
|
||||
return profile if profile
|
||||
# Try to parse the prefix used by this class.
|
||||
script = script.trim()
|
||||
magic = '/*OmegaProfile*'
|
||||
if script.substr(0, magic.length) == magic
|
||||
end = script.indexOf('*/')
|
||||
if end > 0
|
||||
i = magic.length
|
||||
tokens = script.substring(magic.length, end).split('*')
|
||||
[profileName, revision] = tokens
|
||||
try
|
||||
profileName = JSON.parse(profileName)
|
||||
catch _
|
||||
profileName = null
|
||||
if profileName and revision
|
||||
profile = OmegaPac.Profiles.byName(profileName, options)
|
||||
if OmegaPac.Revision.compare(profile.revision, revision) == 0
|
||||
return profile
|
||||
return OmegaPac.Profiles.create({
|
||||
profileType: 'PacProfile'
|
||||
name: ''
|
||||
pacScript: script
|
||||
})
|
||||
when 'fixed_servers'
|
||||
props = ['proxyForHttp', 'proxyForHttps', 'proxyForFtp',
|
||||
'fallbackProxy', 'singleProxy']
|
||||
proxies = {}
|
||||
for prop in props
|
||||
result = OmegaPac.Profiles.pacResult(details.value.rules[prop])
|
||||
if prop == 'singleProxy' and details.value.rules[prop]?
|
||||
proxies['fallbackProxy'] = result
|
||||
else
|
||||
proxies[prop] = result
|
||||
bypassSet = {}
|
||||
bypassCount = 0
|
||||
if details.value.rules.bypassList
|
||||
for pattern in details.value.rules.bypassList
|
||||
bypassSet[pattern] = true
|
||||
bypassCount++
|
||||
if bypassSet['<local>']
|
||||
for host in OmegaPac.Conditions.localHosts when bypassSet[host]
|
||||
delete bypassSet[host]
|
||||
bypassCount--
|
||||
profile = null
|
||||
OmegaPac.Profiles.each options, (key, p) ->
|
||||
return if p.profileType != 'FixedProfile'
|
||||
return if p.bypassList.length != bypassCount
|
||||
for condition in p.bypassList
|
||||
return unless bypassSet[condition.pattern]
|
||||
rules = fixedProfileConfig(p).rules
|
||||
if rules['singleProxy']
|
||||
rules['fallbackProxy'] = rules['singleProxy']
|
||||
delete rules['singleProxy']
|
||||
return unless rules?
|
||||
for prop in props when rules[prop] or proxies[prop]
|
||||
if OmegaPac.Profiles.pacResult(rules[prop]) != proxies[prop]
|
||||
return
|
||||
profile = p
|
||||
if profile
|
||||
profile
|
||||
else
|
||||
profile = OmegaPac.Profiles.create({
|
||||
profileType: 'FixedProfile'
|
||||
name: ''
|
||||
})
|
||||
for prop in props when details.value.rules[prop]
|
||||
if prop == 'singleProxy'
|
||||
profile['fallbackProxy'] = details.value.rules[prop]
|
||||
else
|
||||
profile[prop] = details.value.rules[prop]
|
||||
profile.bypassList =
|
||||
for own pattern of bypassSet
|
||||
{conditionType: 'BypassCondition', pattern: pattern}
|
||||
profile
|
@ -8,6 +8,7 @@ class ProxyImpl
|
||||
@isSupported: -> false
|
||||
applyProfile: (profile, meta) -> Promise.reject()
|
||||
watchProxyChange: (callback) -> null
|
||||
parseExternalProfile: (details, options) -> null
|
||||
_profileNotFound: (name) ->
|
||||
@log.error("Profile #{name} not found! Things may go very, very wrong.")
|
||||
return OmegaPac.Profiles.create({
|
||||
|
@ -1,4 +1,5 @@
|
||||
OmegaTarget = require('omega-target')
|
||||
OmegaPac = OmegaTarget.OmegaPac
|
||||
Promise = OmegaTarget.Promise
|
||||
chromeApiPromisify = require('../chrome_api').chromeApiPromisify
|
||||
ProxyImpl = require('./proxy_impl')
|
||||
@ -83,8 +84,115 @@ class SettingsProxyImpl extends ProxyImpl
|
||||
if not @_proxyChangeWatchers?
|
||||
@_proxyChangeWatchers = []
|
||||
if chrome?.proxy?.settings?.onChange?
|
||||
chrome.proxy.settings.onChange.addListener @_proxyChangeListener
|
||||
chrome.proxy.settings.onChange.addListener(
|
||||
@_proxyChangeListener.bind(this))
|
||||
@_proxyChangeWatchers.push(callback)
|
||||
return
|
||||
parseExternalProfile: (details, options) ->
|
||||
if details.name
|
||||
return details
|
||||
switch details.value.mode
|
||||
when 'system'
|
||||
OmegaPac.Profiles.byName('system')
|
||||
when 'direct'
|
||||
OmegaPac.Profiles.byName('direct')
|
||||
when 'auto_detect'
|
||||
OmegaPac.Profiles.create({
|
||||
profileType: 'PacProfile'
|
||||
name: ''
|
||||
pacUrl: 'http://wpad/wpad.dat'
|
||||
})
|
||||
when 'pac_script'
|
||||
url = details.value.pacScript.url
|
||||
if url
|
||||
profile = null
|
||||
OmegaPac.Profiles.each options, (key, p) ->
|
||||
if p.profileType == 'PacProfile' and p.pacUrl == url
|
||||
profile = p
|
||||
profile ? OmegaPac.Profiles.create({
|
||||
profileType: 'PacProfile'
|
||||
name: ''
|
||||
pacUrl: url
|
||||
})
|
||||
else do ->
|
||||
profile = null
|
||||
script = details.value.pacScript.data
|
||||
OmegaPac.Profiles.each options, (key, p) ->
|
||||
if p.profileType == 'PacProfile' and p.pacScript == script
|
||||
profile = p
|
||||
return profile if profile
|
||||
# Try to parse the prefix used by this class.
|
||||
script = script.trim()
|
||||
magic = '/*OmegaProfile*'
|
||||
if script.substr(0, magic.length) == magic
|
||||
end = script.indexOf('*/')
|
||||
if end > 0
|
||||
i = magic.length
|
||||
tokens = script.substring(magic.length, end).split('*')
|
||||
[profileName, revision] = tokens
|
||||
try
|
||||
profileName = JSON.parse(profileName)
|
||||
catch _
|
||||
profileName = null
|
||||
if profileName and revision
|
||||
profile = OmegaPac.Profiles.byName(profileName, options)
|
||||
if OmegaPac.Revision.compare(profile.revision, revision) == 0
|
||||
return profile
|
||||
return OmegaPac.Profiles.create({
|
||||
profileType: 'PacProfile'
|
||||
name: ''
|
||||
pacScript: script
|
||||
})
|
||||
when 'fixed_servers'
|
||||
props = ['proxyForHttp', 'proxyForHttps', 'proxyForFtp',
|
||||
'fallbackProxy', 'singleProxy']
|
||||
proxies = {}
|
||||
for prop in props
|
||||
result = OmegaPac.Profiles.pacResult(details.value.rules[prop])
|
||||
if prop == 'singleProxy' and details.value.rules[prop]?
|
||||
proxies['fallbackProxy'] = result
|
||||
else
|
||||
proxies[prop] = result
|
||||
bypassSet = {}
|
||||
bypassCount = 0
|
||||
if details.value.rules.bypassList
|
||||
for pattern in details.value.rules.bypassList
|
||||
bypassSet[pattern] = true
|
||||
bypassCount++
|
||||
if bypassSet['<local>']
|
||||
for host in OmegaPac.Conditions.localHosts when bypassSet[host]
|
||||
delete bypassSet[host]
|
||||
bypassCount--
|
||||
profile = null
|
||||
OmegaPac.Profiles.each options, (key, p) =>
|
||||
return if p.profileType != 'FixedProfile'
|
||||
return if p.bypassList.length != bypassCount
|
||||
for condition in p.bypassList
|
||||
return unless bypassSet[condition.pattern]
|
||||
rules = @_fixedProfileConfig(p).rules
|
||||
if rules['singleProxy']
|
||||
rules['fallbackProxy'] = rules['singleProxy']
|
||||
delete rules['singleProxy']
|
||||
return unless rules?
|
||||
for prop in props when rules[prop] or proxies[prop]
|
||||
if OmegaPac.Profiles.pacResult(rules[prop]) != proxies[prop]
|
||||
return
|
||||
profile = p
|
||||
if profile
|
||||
profile
|
||||
else
|
||||
profile = OmegaPac.Profiles.create({
|
||||
profileType: 'FixedProfile'
|
||||
name: ''
|
||||
})
|
||||
for prop in props when details.value.rules[prop]
|
||||
if prop == 'singleProxy'
|
||||
profile['fallbackProxy'] = details.value.rules[prop]
|
||||
else
|
||||
profile[prop] = details.value.rules[prop]
|
||||
profile.bypassList =
|
||||
for own pattern of bypassSet
|
||||
{conditionType: 'BypassCondition', pattern: pattern}
|
||||
profile
|
||||
|
||||
module.exports = SettingsProxyImpl
|
||||
|
@ -36,7 +36,7 @@ html(lang='en' ng-app='omegaPopup' ng-controller='PopupCtrl' ng-csp)
|
||||
span(omega-profile-icon='externalProfile' icon='getIcon(externalProfile, "normal")' options='availableProfiles' disp-name='dispNameFilter')
|
||||
= ' '
|
||||
span(ng-show='!nameExternal.open') {{'popup_externalProfile' | tr}}
|
||||
input.form-control(ng-show='!!nameExternal.open' ng-model='externalProfile.name' ng-blur='nameExternalForm.submit()'
|
||||
input.form-control(ng-show='!!nameExternal.open' ng-model='externalProfile.name' ng-blur='nameExternalForm.$valid && saveExternal()'
|
||||
placeholder='{{"popup_externalProfileName" | tr}}' ui-validate='validateProfileName' autofocus)
|
||||
li.request-info(ng-show='!!requestInfoProvided' class='bg-warning')
|
||||
a(href='#' role='button' ng-click='showRequestInfo = true' data-shortcut='requestInfo')
|
||||
|
Loading…
Reference in New Issue
Block a user