Update availableProfiles list when profiles change. Fix #25.

This commit is contained in:
FelisCatus 2014-09-21 11:19:16 +08:00
parent 19430c9283
commit 419935b959
3 changed files with 38 additions and 24 deletions

View File

@ -5,7 +5,6 @@ Profiles = require './profiles'
# coffeelint: disable=missing_fat_arrows # coffeelint: disable=missing_fat_arrows
module.exports = module.exports =
ascii: (str) -> ascii: (str) ->
throw new Error "WTF"
str.replace /[\u0080-\uffff]/g, (char) -> str.replace /[\u0080-\uffff]/g, (char) ->
hex = char.charCodeAt(0).toString(16) hex = char.charCodeAt(0).toString(16)
result = '\\u' result = '\\u'

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "__MSG_manifest_app_name__", "name": "__MSG_manifest_app_name__",
"version": "2.1.1", "version": "2.1.2",
"description": "__MSG_manifest_app_description__", "description": "__MSG_manifest_app_description__",
"icons": { "icons": {
"16": "img/icons/omega-16.png", "16": "img/icons/omega-16.png",

View File

@ -185,18 +185,23 @@ class Options
_setOptions: (changes, args) => _setOptions: (changes, args) =>
removed = [] removed = []
checkRev = args?.checkRevision ? false checkRev = args?.checkRevision ? false
profilesChanged = false
currentProfileAffected = false currentProfileAffected = false
for own key, value of changes for own key, value of changes
if typeof value == 'undefined' if typeof value == 'undefined'
delete @_options[key] delete @_options[key]
removed.push(key) removed.push(key)
if key == '+' + @_currentProfileName if key[0] == '+'
currentProfileAffected = 'removed' profilesChanged = true
if key == '+' + @_currentProfileName
currentProfileAffected = 'removed'
else else
if checkRev and key[0] == '+' and @_options[key] if key[0] == '+'
result = OmegaPac.Revision.compare(@_options[key].revision, if checkRev and @_options[key]
value.revision) result = OmegaPac.Revision.compare(@_options[key].revision,
continue if result >= 0 value.revision)
continue if result >= 0
profilesChanged = true
@_options[key] = value @_options[key] = value
if not currentProfileAffected and @_watchingProfiles[key] if not currentProfileAffected and @_watchingProfiles[key]
currentProfileAffected = 'changed' currentProfileAffected = 'changed'
@ -205,6 +210,8 @@ class Options
@applyProfile(@fallbackProfileName) @applyProfile(@fallbackProfileName)
when 'changed' when 'changed'
@applyProfile(@_currentProfileName) @applyProfile(@_currentProfileName)
else
@_setAvailableProfiles() if profilesChanged
if args?.persist ? true if args?.persist ? true
for key in removed for key in removed
delete changes[key] delete changes[key]
@ -264,6 +271,28 @@ class Options
ast = OmegaPac.PacGenerator.compress(ast) ast = OmegaPac.PacGenerator.compress(ast)
Promise.resolve ast.print_to_string() 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. # Apply the profile by name.
# @param {?string} name The name of the profile, or null for default. # @param {?string} name The name of the profile, or null for default.
@ -283,27 +312,13 @@ class Options
@_isSystem = options?.system || (profile.profileType == 'SystemProfile') @_isSystem = options?.system || (profile.profileType == 'SystemProfile')
@_watchingProfiles = OmegaPac.Profiles.allReferenceSet(profile, @_options) @_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({ @_state.set({
'currentProfileName': @_currentProfileName 'currentProfileName': @_currentProfileName
'isSystemProfile': @_isSystem 'isSystemProfile': @_isSystem
'availableProfiles': profiles
'validResultProfiles': results
'currentProfileCanAddRule': profile.rules? 'currentProfileCanAddRule': profile.rules?
}) })
@_setAvailableProfiles()
@currentProfileChanged(options?.reason) @currentProfileChanged(options?.reason)
if options? and options.proxy == false if options? and options.proxy == false
return Promise.resolve() return Promise.resolve()