diff --git a/omega-target-chromium-extension/background.coffee b/omega-target-chromium-extension/background.coffee index ae44032..f57dcc9 100644 --- a/omega-target-chromium-extension/background.coffee +++ b/omega-target-chromium-extension/background.coffee @@ -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 diff --git a/omega-target-chromium-extension/omega_target_web.coffee b/omega-target-chromium-extension/omega_target_web.coffee index 74880bd..dafb9f7 100644 --- a/omega-target-chromium-extension/omega_target_web.coffee +++ b/omega-target-chromium-extension/omega_target_web.coffee @@ -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) -> diff --git a/omega-web/src/coffee/popup.coffee b/omega-web/src/coffee/popup.coffee index 6170716..5a4344f 100644 --- a/omega-web/src/coffee/popup.coffee +++ b/omega-web/src/coffee/popup.coffee @@ -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}