From ee144e20a7b10d5bb6d6ba2b6af8ca857242559e Mon Sep 17 00:00:00 2001 From: FelisCatus Date: Sat, 4 Oct 2014 15:55:03 +0800 Subject: [PATCH] Attach rule list to auto on upgrade. --- omega-i18n/en/messages.json | 5 ++++ omega-i18n/zh/messages.json | 5 ++++ .../src/options.coffee | 5 +++- .../src/upgrade.coffee | 28 +++++++++---------- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/omega-i18n/en/messages.json b/omega-i18n/en/messages.json index fbada70..0a52ed1 100644 --- a/omega-i18n/en/messages.json +++ b/omega-i18n/en/messages.json @@ -17,6 +17,11 @@ "description": "Displayed when the background page is loading." }, + "upgrade_profile_auto" : { + "message": "Auto Switch", + "description": "Legacy AutoSwitch mode will be converted to a profile with this name." + }, + "profile_direct" : { "message": "[Direct]" }, diff --git a/omega-i18n/zh/messages.json b/omega-i18n/zh/messages.json index 698eb83..d537ff0 100644 --- a/omega-i18n/zh/messages.json +++ b/omega-i18n/zh/messages.json @@ -17,6 +17,11 @@ "description": "应用后台页面正在加载时显示。" }, + "upgrade_profile_auto" : { + "message": "自动切换", + "description": "旧版自动切换模式升级时将变成一个情景模式,其名称如上。" + }, + "profile_direct" : { "message": "[直接连接]" }, diff --git a/omega-target-chromium-extension/src/options.coffee b/omega-target-chromium-extension/src/options.coffee index 092cd31..4aa592a 100644 --- a/omega-target-chromium-extension/src/options.coffee +++ b/omega-target-chromium-extension/src/options.coffee @@ -200,9 +200,12 @@ class ChromeOptions extends OmegaTarget.Options if not options?['schemaVersion'] if options?['config'] or localStorage['config'] oldOptions = if options?['config'] then options else localStorage + i18n = { + upgrade_profile_auto: chrome.i18n.getMessage('upgrade_profile_auto') + } try # Upgrade from SwitchySharp. - upgraded = require('./upgrade')(oldOptions) + upgraded = require('./upgrade')(oldOptions, i18n) catch ex OmegaTarget.Log.error(ex) if upgraded diff --git a/omega-target-chromium-extension/src/upgrade.coffee b/omega-target-chromium-extension/src/upgrade.coffee index 3db7aea..2cda10f 100644 --- a/omega-target-chromium-extension/src/upgrade.coffee +++ b/omega-target-chromium-extension/src/upgrade.coffee @@ -1,7 +1,7 @@ OmegaTarget = require('omega-target') OmegaPac = OmegaTarget.OmegaPac -module.exports = (oldOptions) -> +module.exports = (oldOptions, i18n) -> config = try JSON.parse(oldOptions['config']) if config options = changes ? {} @@ -16,27 +16,29 @@ module.exports = (oldOptions) -> options['-downloadInterval'] = parseInt(config['ruleListReload']) || 15 - profile = OmegaPac.Profiles.create( + auto = OmegaPac.Profiles.create( profileType: 'SwitchProfile' - name: 'auto' + name: i18n.upgrade_profile_auto color: '#55bb55' - defaultProfileName: 'rulelist' + defaultProfileName: 'direct' # We will set this to rulelist.name soon. ) - OmegaPac.Profiles.updateRevision(profile) - options[OmegaPac.Profiles.nameAsKey(profile.name)] = profile + OmegaPac.Profiles.updateRevision(auto) + options[OmegaPac.Profiles.nameAsKey(auto.name)] = auto - profile = OmegaPac.Profiles.create( + rulelist = OmegaPac.Profiles.create( profileType: 'RuleListProfile' - name: 'rulelist' + name: '__ruleListOf_' + auto.name color: '#dd6633' format: if config['ruleListAutoProxy'] then 'AutoProxy' else 'Switchy' defaultProfileName: 'direct' sourceUrl: config['ruleListUrl'] || '' ) - options[OmegaPac.Profiles.nameAsKey(profile.name)] = profile + options[OmegaPac.Profiles.nameAsKey(rulelist.name)] = rulelist - nameMap = {'auto': 'auto', 'direct': 'direct'} + auto.defaultProfileName = rulelist.name + + nameMap = {'auto': auto.name, 'direct': 'direct'} oldProfiles = (try JSON.parse(oldOptions['profiles'])) || {} colorTranslations = 'blue': '#99ccee' @@ -119,9 +121,8 @@ module.exports = (oldOptions) -> options['-quickSwitchProfiles'] = if not quickSwitch? then [] else quickSwitch.map (p) -> nameMap[p] - profile = OmegaPac.Profiles.byName('rulelist', options) if config['ruleListProfileId'] - profile.matchProfileName = + rulelist.matchProfileName = nameMap[config['ruleListProfileId']] || 'direct' defaultRule = try JSON.parse(oldOptions['defaultRule']) @@ -131,8 +132,7 @@ module.exports = (oldOptions) -> rules = try JSON.parse(oldOptions['rules']) if rules - profile = OmegaPac.Profiles.byName('auto', options) - profile.rules = for own _, rule of rules + auto.rules = for own _, rule of rules profileName: nameMap[rule['profileId']] || 'direct' condition: conditionType: