From 738ba58e7725ce82c48a9a418b07f68745522a4a Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Thu, 11 Dec 2014 13:06:22 -0800 Subject: [PATCH] fix(enableInstrumentation): sync instrumentation status --- .../components/inspected-app/inspected-app.js | 20 +++++++++++++++---- panel/components/tabs/tabs.js | 7 +++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/panel/components/inspected-app/inspected-app.js b/panel/components/inspected-app/inspected-app.js index fc39256..16fcb35 100644 --- a/panel/components/inspected-app/inspected-app.js +++ b/panel/components/inspected-app/inspected-app.js @@ -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 */ diff --git a/panel/components/tabs/tabs.js b/panel/components/tabs/tabs.js index b993c63..0a4ed10 100644 --- a/panel/components/tabs/tabs.js +++ b/panel/components/tabs/tabs.js @@ -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) {