Skip to content

Commit

Permalink
Fix externalProfile watcher after refactoring. Fix #1607.
Browse files Browse the repository at this point in the history
  • Loading branch information
FelisCatus committed Aug 27, 2018
1 parent 2ad6ffa commit e2d9293
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 117 deletions.
6 changes: 4 additions & 2 deletions omega-target-chromium-extension/src/coffee/background.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions omega-target-chromium-extension/src/module/options.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ 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')
Url = require('url')

class ChromeOptions extends OmegaTarget.Options
_inspect: null
parseExternalProfile: (details) ->
parseExternalProfile(details, @_options, @_fixedProfileConfig.bind(this))

fetchUrl: fetchUrl

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
OmegaTarget = require('omega-target')
OmegaPac = OmegaTarget.OmegaPac
Promise = OmegaTarget.Promise
chromeApiPromisify = require('../chrome_api').chromeApiPromisify
ProxyImpl = require('./proxy_impl')
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion omega-web/src/popup.jade
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit e2d9293

Please sign in to comment.