Skip to content

Commit

Permalink
Update availableProfiles list when profiles change. Fix #25.
Browse files Browse the repository at this point in the history
  • Loading branch information
FelisCatus committed Sep 21, 2014
1 parent 19430c9 commit 419935b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
1 change: 0 additions & 1 deletion omega-pac/src/pac_generator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Profiles = require './profiles'
# coffeelint: disable=missing_fat_arrows
module.exports =
ascii: (str) ->
throw new Error "WTF"
str.replace /[\u0080-\uffff]/g, (char) ->
hex = char.charCodeAt(0).toString(16)
result = '\\u'
Expand Down
2 changes: 1 addition & 1 deletion omega-target-chromium-extension/overlay/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "__MSG_manifest_app_name__",
"version": "2.1.1",
"version": "2.1.2",
"description": "__MSG_manifest_app_description__",
"icons": {
"16": "img/icons/omega-16.png",
Expand Down
59 changes: 37 additions & 22 deletions omega-target/src/options.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,23 @@ class Options
_setOptions: (changes, args) =>
removed = []
checkRev = args?.checkRevision ? false
profilesChanged = false
currentProfileAffected = false
for own key, value of changes
if typeof value == 'undefined'
delete @_options[key]
removed.push(key)
if key == '+' + @_currentProfileName
currentProfileAffected = 'removed'
if key[0] == '+'
profilesChanged = true
if key == '+' + @_currentProfileName
currentProfileAffected = 'removed'
else
if checkRev and key[0] == '+' and @_options[key]
result = OmegaPac.Revision.compare(@_options[key].revision,
value.revision)
continue if result >= 0
if key[0] == '+'
if checkRev and @_options[key]
result = OmegaPac.Revision.compare(@_options[key].revision,
value.revision)
continue if result >= 0
profilesChanged = true
@_options[key] = value
if not currentProfileAffected and @_watchingProfiles[key]
currentProfileAffected = 'changed'
Expand All @@ -205,6 +210,8 @@ class Options
@applyProfile(@fallbackProfileName)
when 'changed'
@applyProfile(@_currentProfileName)
else
@_setAvailableProfiles() if profilesChanged
if args?.persist ? true
for key in removed
delete changes[key]
Expand Down Expand Up @@ -264,6 +271,28 @@ class Options
ast = OmegaPac.PacGenerator.compress(ast)
Promise.resolve ast.print_to_string()

_setAvailableProfiles: ->
profile = if @_currentProfileName then @currentProfile() else null
profiles = {}
currentIncludable = profile && OmegaPac.Profiles.isIncludable(profile)
if not profile or not OmegaPac.Profiles.isInclusive(profile)
results = []
OmegaPac.Profiles.each @_options, (key, profile) ->
profiles[key] =
name: profile.name
profileType: profile.profileType
color: profile.color
builtin: !!profile.builtin
if results? and currentIncludable
results.push(profile.name)
if profile and OmegaPac.Profiles.isInclusive(profile)
results = OmegaPac.Profiles.validResultProfilesFor(profile, @_options)
results = results.map (profile) -> profile.name
@_state.set({
'availableProfiles': profiles
'validResultProfiles': results
})

###*
# Apply the profile by name.
# @param {?string} name The name of the profile, or null for default.
Expand All @@ -283,27 +312,13 @@ class Options
@_isSystem = options?.system || (profile.profileType == 'SystemProfile')
@_watchingProfiles = OmegaPac.Profiles.allReferenceSet(profile, @_options)

if not OmegaPac.Profiles.isInclusive(profile)
results = []
profiles = {}
OmegaPac.Profiles.each @_options, (key, profile) ->
profiles[key] =
name: profile.name
profileType: profile.profileType
color: profile.color
builtin: !!profile.builtin
if results? and OmegaPac.Profiles.isIncludable(profile)
results.push(profile.name)
if OmegaPac.Profiles.isInclusive(profile)
results = OmegaPac.Profiles.validResultProfilesFor(profile, @_options)
results = results.map (profile) -> profile.name
@_state.set({
'currentProfileName': @_currentProfileName
'isSystemProfile': @_isSystem
'availableProfiles': profiles
'validResultProfiles': results
'currentProfileCanAddRule': profile.rules?
})
@_setAvailableProfiles()

@currentProfileChanged(options?.reason)
if options? and options.proxy == false
return Promise.resolve()
Expand Down

0 comments on commit 419935b

Please sign in to comment.