Try to revert proxy settings if possible. Fix #140.

This commit is contained in:
FelisCatus 2015-01-01 20:17:46 +08:00
parent d44a52b593
commit ca71a9a7d9
3 changed files with 11 additions and 5 deletions

View File

@ -175,6 +175,7 @@ options.watchProxyChange (details) ->
return unless details
notControllableBefore = options.proxyNotControllable()
internal = false
noRevert = false
switch details['levelOfControl']
when "controlled_by_other_extensions", "not_controllable"
reason =
@ -183,6 +184,7 @@ options.watchProxyChange (details) ->
else
'app'
options.setProxyNotControllable(reason)
noRevert = true
else
options.setProxyNotControllable(null)
@ -200,7 +202,7 @@ options.watchProxyChange (details) ->
clearTimeout(timeout) if timeout?
parsed = null
timeout = setTimeout (->
options.setExternalProfile(parsed, {noRevert: true, internal: internal})
options.setExternalProfile(parsed, {noRevert: noRevert, internal: internal})
), 500
parsed = options.parseExternalProfile(details)

View File

@ -4,7 +4,7 @@ module.exports = ->
"-refreshOnProfileChange": true
"-startupProfileName": ""
"-quickSwitchProfiles": []
"-revertProxyChanges": false
"-revertProxyChanges": true
"-confirmDeletion": true
"-showInspectMenu": true
"-downloadInterval": 1440

View File

@ -20,6 +20,7 @@ class Options
_storage: null
_state: null
_currentProfileName: null
_revertToProfileName: null
_watchingProfiles: {}
_tempProfile: null
_tempProfileRules: {}
@ -774,11 +775,14 @@ class Options
# @returns {Promise} A promise which is fulfilled when the profile is set
###
setExternalProfile: (profile, args) ->
if not args?.noRevert and @_options['-revertProxyChanges']
if @_options['-revertProxyChanges'] and not @_isSystem
if profile.name != @_currentProfileName and @_currentProfileName
if not @_isSystem
@applyProfile(@_currentProfileName)
if not args?.noRevert
@applyProfile(@_revertToProfileName)
@_revertToProfileName = null
return
else
@_revertToProfileName ?= @_currentProfileName
p = OmegaPac.Profiles.byName(profile.name, @_options)
if p
if args?.internal