fix(enableInstrumentation): sync instrumentation status

test-unit-sauce
Brian Ford 10 years ago
parent f745b92053
commit 738ba58e77

@ -1,9 +1,9 @@
'use strict';
angular.module('batarang.inspected-app', []).
service('inspectedApp', ['$rootScope', inspectedAppService]);
service('inspectedApp', ['$rootScope', '$q', inspectedAppService]);
function inspectedAppService($rootScope) {
function inspectedAppService($rootScope, $q) {
// TODO: maybe state should live elsewhere
var scopes = this.scopes = {},
@ -24,11 +24,23 @@ function inspectedAppService($rootScope) {
this.enableInstrumentation = function (setting) {
setting = !!setting;
chrome.devtools.inspectedWindow.eval(
"window.document.cookie = '__ngDebug=" + setting + ";';" +
"window.document.location.reload();"
"(function () {" +
"var prev = document.cookie.indexOf('__ngDebug=true') !== -1;" +
"if (prev !== " + setting + ") {" +
"window.document.cookie = '__ngDebug=" + setting + ";';" +
"window.document.location.reload();" +
"}" +
"}())"
);
};
this.getInstrumentationStatus = function () {
return $q(function(resolve, reject) {
chrome.devtools.inspectedWindow.eval(
"document.cookie.indexOf('__ngDebug=true') !== -1", resolve);
});
};
/*
* sets window.$scope to the scope of the given id
*/

@ -15,10 +15,9 @@ directive('batTabs', function ($compile, $templateCache, $http, inspectedApp) {
panes.push(pane);
};
$scope.$watch('enabled', function (newVal) {
if (newVal === !!newVal) {
inspectedApp.enableInstrumentation(newVal);
}
inspectedApp.getInstrumentationStatus().then(function (status) {
$scope.enabled = status;
$scope.$watch('enabled', inspectedApp.enableInstrumentation);
});
},
link: function (scope, element, attr) {