ryanackley avatar ryanackley committed 0607956

docked window workaround

Comments (0)

Files changed (6)

BackgroundMsgSupport.js

 		chrome.extension.sendRequest({key: 'loadProject', type: type, path: path, url: url}, function(response){
 			callback(response);
 		});
+	},
+	registerWatch : function(callback){
+		chrome.extension.sendRequest({key: 'registerWatch'}, callback);
 	}
 }
-var FileWatcher = function(tabId, project, path, fsRoot){
+var FileWatcher = function(port, project, path, fsRoot){
+	this.port = port;
+	var tabId = port.sender.tab.id;
 	this.tabId = tabId;
 	this.project = project;
 	this.recentUpdateHandler = new RecentUpdateHandler(2000);
 		}
 		var urls = this.project.urlsForFilePath(path)
 		if (urls && urls.length){
-			var port = chrome.tabs.connect(this.tabId, {name: 'fileChange'});
+			//var port = chrome.tabs.connect(this.tabId, {name: 'fileChange'});
 			var ran = Math.round(Math.random()*10000000);
 			var self = this;
 			urls.asyncEach(function(url, done){
 				var sendContentToDevtools = function(data){
-					port.postMessage({url: url, content: data});
+					self.port.postMessage({url: url, content: data});
 					done();
 				}
 				
 				}
 			}, 
 			function(){
-				port.disconnect();
+				//port.disconnect();
 			});
 		}
 	},

ProjectManager.js

 		currentProject.matchedResourceMap = {};
 		sendResponse();
 	},
-	watchDirectory : function(tabId, path){
+	watchDirectory : function(port){
+		var tabId = port.sender.tab.id;
+		var path = port.name;
 		if (!this.watchersByTab[tabId]){
 			var currentProject = this.projectsByTab[tabId];
-			this.watchersByTab[tabId] = new FileWatcher(tabId, currentProject, path, this.fsRoot);
+			this.watchersByTab[tabId] = new FileWatcher(port, currentProject, path, this.fsRoot);
+			//sendResponse();
 		}
 	},
+	
 	cleanUp : function(tabId){
 		if (this.projectsByTab[tabId])
 			delete this.projectsByTab[tabId];

ResourceChecker.js

 		}
 	}
 };
-chrome.extension.onConnect.addListener(function(port) {
+/*chrome.extension.onConnect.addListener(function(port) {
 	if (port.name == 'fileChange'){
 		port.onMessage.addListener(fileChangeListener);
 	}
-});
+});*/
 					projectManager.resetProject(sender.tab.id, sendResponse);
 				}
 				else if (request.key == 'watchDirectory'){
-					projectManager.watchDirectory(sender.tab.id, request.path);
+					projectManager.watchDirectory(sender.tab.id, request.path, sendResponse);
 				}
 				else if (request.key == 'loadProject'){
 					projectManager.loadProject(sender.tab.id, request.type, request.path, request.url, sendResponse);
 				}
+				else if (request.key == 'registerWatch'){
+					projectManager.registerWatch(sender.tab.id, sendResponse);
+				}
 				else{
 					sendResponse({});
 				}
 				
 		  });
-		  
+		  chrome.extension.onConnect.addListener(function(port){
+		  	projectManager.watchDirectory(port);
+		  });
 		  chrome.tabs.onRemoved.addListener(function(tabId, removeInfo) {
 		  		projectManager.cleanUp(tabId);
 		  });
 // Most of the logic happens in devtools.html since it loads right away
 var projectState = {};
 var inspectedLocation;
+var watchPort;
 
 var loadProject = function(type, path){
 	checkResources();
 	registerNavListener();
-	backgroundMsgSupport.watchDirectory(path, function(){});
+	
+	if (watchPort){
+		watchPort.disconnect();
+	}
+	watchPort = chrome.extension.connect({name:path});
+	watchPort.onMessage.addListener(fileChangeListener);
 	
 	projectState = {type: type, path: path};
 	if (type != 'fileUrl'){
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.