From 4c06bb7d9284b92b1c11a18787a3189221704446 Mon Sep 17 00:00:00 2001
From: didierfred <didierfred@gmail.com>
Date: Mon, 16 Apr 2018 16:17:00 +0200
Subject: [PATCH] add lock to open only one config tab in window

---
 manifest.json |  2 +-
 popup/menu.js | 23 ++++++++++++++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/manifest.json b/manifest.json
index 70d0cc6..000b24f 100644
--- a/manifest.json
+++ b/manifest.json
@@ -10,7 +10,7 @@
   },
 
   "permissions": [
-    "activeTab","storage","webRequest", "webRequestBlocking", "<all_urls>" 
+    "activeTab","storage","webRequest", "webRequestBlocking", "<all_urls>" ,"tabs"
   ],
   
   "background": {
diff --git a/popup/menu.js b/popup/menu.js
index b90cdc7..8af4f76 100644
--- a/popup/menu.js
+++ b/popup/menu.js
@@ -41,7 +41,24 @@ function start_modify()
 
 function start_config()
 	{
-	//var strWindowFeatures = "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,width=800,height=600";
-	// window.open("config.html","Simple Modify Headers",strWindowFeatures);
-	browser.tabs.create({url:"config.html"});
+	var promise_tabs =  browser.tabs.query({currentWindow: true});
+	promise_tabs.then(loadConfigTab);
+	}	
+	
+	
+function loadConfigTab(tabs)
+	{
+	var config_tab;
+	
+	// search for config tab 
+	for (let tab of tabs) 
+		{
+			if (tab.url.startsWith(browser.extension.getURL(""))) config_tab = tab;
+		}
+		
+	// config tab exits , put the focus on it 
+    if (config_tab) browser.tabs.update(config_tab.id,{active:true})
+
+	// else create a new tab
+	else browser.tabs.create({url:"config.html"});
 	}
-- 
GitLab