fix(enableInstrumentation): sync instrumentation status

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

@ -1,9 +1,9 @@
'use strict'; 'use strict';
angular.module('batarang.inspected-app', []). 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 // TODO: maybe state should live elsewhere
var scopes = this.scopes = {}, var scopes = this.scopes = {},
@ -24,11 +24,23 @@ function inspectedAppService($rootScope) {
this.enableInstrumentation = function (setting) { this.enableInstrumentation = function (setting) {
setting = !!setting; setting = !!setting;
chrome.devtools.inspectedWindow.eval( chrome.devtools.inspectedWindow.eval(
"window.document.cookie = '__ngDebug=" + setting + ";';" + "(function () {" +
"window.document.location.reload();" "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 * sets window.$scope to the scope of the given id
*/ */

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