Skip to content

Commit

Permalink
Issue 5888: Improve logic for when to open first-run page
Browse files Browse the repository at this point in the history
  • Loading branch information
janodvarko committed Oct 12, 2012
1 parent 682d677 commit 4472328
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 40 deletions.
2 changes: 1 addition & 1 deletion extension/bootstrap.js
Expand Up @@ -67,7 +67,7 @@ function startup(params, reason)
// Load Firebug into all existing browser windows.
var enumerator = Services.wm.getEnumerator("navigator:browser");
while (enumerator.hasMoreElements())
FirebugLoader.loadIntoWindow(enumerator.getNext());
FirebugLoader.loadIntoWindow(enumerator.getNext(), reason);

// Listen for new windows, Firebug must be loaded into them too.
Services.obs.addObserver(windowWatcher, "chrome-document-global-created", false);
Expand Down
97 changes: 59 additions & 38 deletions extension/content/firebug/firefox/browserOverlay.js
Expand Up @@ -509,13 +509,6 @@ Firebug.GlobalUI =
});
},

openFirstRunPage: function()
{
var version = Firebug.GlobalUI.getVersion();
url = firstRunPage + version;
gBrowser.selectedTab = gBrowser.addTab(url, null, null, null);
},

setPosition: function(newPosition)
{
// todo
Expand Down Expand Up @@ -606,7 +599,64 @@ Firebug.GlobalUI =

win.nsContextMenu.prototype.setTarget = this.setTargetOriginal;
win.nsContextMenu.prototype.initItems = this.initItemsOriginal;
}
},

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// First Run Page

loadFirstRunPage: function(win, reason)
{
if (checkFirebugVersion(PrefLoader.getPref("currentVersion")) <= 0)
return;

// Do not show the first run page when Firebug is being updated. It'll be displayed
// the next time the browser is restarted
// # ADDON_UPGRADE == 7
if (reason == 7)
return;

// Open the page in the top most window, so the user can see it immediately.
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
if (wm.getMostRecentWindow("navigator:browser") == win.top)
{
// Update the preference to make sure the page is not displayed again.
// To avoid being annoying when Firefox crashes, forcibly save it, too.
var version = Firebug.GlobalUI.getVersion();
PrefLoader.setPref("currentVersion", version);

if (PrefLoader.getPref("showFirstRunPage"))
{
var timeout = setTimeout(function()
{
if (window.closed)
return;

Firebug.GlobalUI.openFirstRunPage();
}, 1000);

window.addEventListener("unload", function()
{
clearTimeout(timeout);
}, false);
}
}
},

openFirstRunPage: function()
{
var version = Firebug.GlobalUI.getVersion();
url = firstRunPage + version;

// Open the firstRunPage in background
/*gBrowser.selectedTab = */gBrowser.addTab(url, null, null, null);

// Make sure prefs are stored, otherwise the firstRunPage would be displayed
// again if Firefox crashes.
setTimeout(function()
{
PrefLoader.forceSave();
}, 400);
},
}

// ********************************************************************************************* //
Expand Down Expand Up @@ -1273,9 +1323,7 @@ var elements = cloneArray(document.getElementsByClassName("fbInternational"));
Locale.internationalizeElements(document, elements, ["label", "tooltiptext", "aria-label"]);

// ********************************************************************************************* //
// First Run Page

var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
// Version Checker

function checkFirebugVersion(currentVersion)
{
Expand All @@ -1290,33 +1338,6 @@ function checkFirebugVersion(currentVersion)
return versionChecker.compare(version, currentVersion);
}

if (checkFirebugVersion(PrefLoader.getPref("currentVersion")) > 0)
{
// Open the page in the top most window, so the user can see it immediately.
if (wm.getMostRecentWindow("navigator:browser") == window.top)
{
// Don't forget to update the preference, so the page is not displayed again
var version = Firebug.GlobalUI.getVersion();
PrefLoader.setPref("currentVersion", version);

if (PrefLoader.getPref("showFirstRunPage"))
{
var timeout = setTimeout(function()
{
if (window.closed)
return;

Firebug.GlobalUI.openFirstRunPage();
}, 1000);

window.addEventListener("unload", function()
{
clearTimeout(timeout);
}, false);
}
}
}

// ********************************************************************************************* //
// All Pages Activation" is on

Expand Down
3 changes: 2 additions & 1 deletion extension/modules/loader.js
Expand Up @@ -132,7 +132,7 @@ var FirebugLoader =
delete win.FBL;
},

loadIntoWindow: function(win)
loadIntoWindow: function(win, reason)
{
// This is the place where the global Firebug object is created. This object represents
// the entire application and all consequently created namespaces and variables should be
Expand All @@ -144,6 +144,7 @@ var FirebugLoader =
loadSubscript("chrome://firebug/content/firefox/browserOverlay.js", win);

win.Firebug.GlobalUI.loadContextMenuOverlay(win);
win.Firebug.GlobalUI.loadFirstRunPage(win, reason);

// Firebug extensions should initialize here.
this.dispatchToScopes("topWindowLoad", [win]);
Expand Down
6 changes: 6 additions & 0 deletions extension/modules/prefLoader.js
Expand Up @@ -144,12 +144,18 @@ function setPref(name, value)
return value;
}

function forceSave()
{
Services.prefs.savePrefFile(null);
}

// ********************************************************************************************* //
// Registration

PrefLoader.loadDefaultPrefs = loadDefaultPrefs;
PrefLoader.clearDefaultPrefs = clearDefaultPrefs;
PrefLoader.getPref = getPref;
PrefLoader.setPref = setPref;
PrefLoader.forceSave = forceSave;

// ********************************************************************************************* //

0 comments on commit 4472328

Please sign in to comment.