Discard reply when applying profile in popup menu.

This would make profile switching appear to be much faster especially
for compiled profiles. Fix #211.
This commit is contained in:
FelisCatus 2015-02-09 16:35:14 +08:00
parent 8eaf7cae64
commit a54e02b503
3 changed files with 22 additions and 6 deletions

View File

@ -285,6 +285,7 @@ chrome.runtime.onMessage.addListener (request, sender, respond) ->
return
promise = Promise.resolve().then -> method.apply(target, request.args)
return if request.noReply
promise.then (result) ->
if request.method == 'updateProfile'
@ -297,4 +298,4 @@ chrome.runtime.onMessage.addListener (request, sender, respond) ->
respond(error: encodeError(error))
# Wait for my response!
return true
return true unless request.noReply

View File

@ -8,6 +8,12 @@ angular.module('omegaTarget', []).factory 'omegaTarget', ($q) ->
err
else
obj
callBackgroundNoReply = (method, args...) ->
chrome.runtime.sendMessage({
method: method
args: args
noReply: true
})
callBackground = (method, args...) ->
d = $q['defer']()
chrome.runtime.sendMessage({
@ -92,6 +98,8 @@ angular.module('omegaTarget', []).factory 'omegaTarget', ($q) ->
return d.promise
applyProfile: (name) ->
callBackground('applyProfile', name)
applyProfileNoReply: (name) ->
callBackgroundNoReply('applyProfile', name)
addTempRule: (domain, profileName) ->
callBackground('addTempRule', domain, profileName)
addCondition: (condition, profileName) ->

View File

@ -125,15 +125,22 @@ module.controller 'PopupCtrl', ($scope, $window, $q, omegaTarget,
$scope.openOptions("#/profile/#{pname}?help=condition")
$scope.applyProfile = (profile) ->
omegaTarget.applyProfile(profile.name).then(->
if refreshOnProfileChange
return omegaTarget.refreshActivePage()
).then(->
next = ->
if profile.profileType == 'SwitchProfile'
return omegaTarget.state('web.switchGuide').then (switchGuide) ->
if switchGuide == 'showOnFirstUse'
return $scope.openOptions("#/profile/#{profile.name}")
).then ->
if not refreshOnProfileChange
omegaTarget.applyProfileNoReply(profile.name)
apply = next()
else
apply = omegaTarget.applyProfile(profile.name).then(->
return omegaTarget.refreshActivePage()
).then(next)
if apply
apply.then -> $window.close()
else
$window.close()
$scope.tempRuleMenu = {open: false}