From 170f9faa87ec72cc422f1da129ff5f5576caff73 Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Mon, 14 Jul 2014 22:46:52 -0400 Subject: [Firefox add-on] Window activation events more robusts when several windows Since there is only one active tab across all the windows, switching between two windows will generate both a window activation, and tab activation event for the window being switched to. By keeping track of the previously focused window, we disable the activation event for the window being switched to. --- firefox-addon/lib/main.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/firefox-addon/lib/main.js b/firefox-addon/lib/main.js index 5814792..285397b 100644 --- a/firefox-addon/lib/main.js +++ b/firefox-addon/lib/main.js @@ -4,6 +4,8 @@ var Request = require("sdk/request").Request; var prefs = require("sdk/simple-prefs").prefs; var XMLHttpRequest = require("sdk/net/xhr").XMLHttpRequest; +var previous_window = null; + function log(url, title){ var data = JSON.stringify({ url: url, time: Date.now(), @@ -21,6 +23,14 @@ function logTab(tab) { } tabs.on("activate", function () { logTab(tabs.activeTab) }); + tabs.on("pageshow", logTab ); -windows.on("activate", function () { logTab(tabs.activeTab) }); -windows.on("deactivate", function () { log(null, null) }); +windows.on("activate", function (window) { + if (previous_window != window) { + previous_window = window; + return; + } + logTab(tabs.activeTab) ; +}); + +windows.on("deactivate", function (window) { log(null, null) }); -- cgit v1.2.3-70-g09d2