Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Issue 5888: Improve logic for when to open first-run page

  • Loading branch information...
commit d349c955b3a29e8b21a305b894c55c39a1e07a7c 1 parent df657ef
Jan Odvarko authored October 11, 2012
2  extension/bootstrap.js
@@ -66,7 +66,7 @@ function startup(params, reason)
66 66
     // Load Firebug into all existing browser windows.
67 67
     var enumerator = Services.wm.getEnumerator("navigator:browser");
68 68
     while (enumerator.hasMoreElements())
69  
-        FirebugLoader.loadIntoWindow(enumerator.getNext());
  69
+        FirebugLoader.loadIntoWindow(enumerator.getNext(), reason);
70 70
 
71 71
     // Listen for new windows, Firebug must be loaded into them too.
72 72
     Services.ww.registerNotification(windowWatcher);
97  extension/content/firebug/firefox/browserOverlay.js
@@ -509,13 +509,6 @@ Firebug.GlobalUI =
509 509
         });
510 510
     },
511 511
 
512  
-    openFirstRunPage: function()
513  
-    {
514  
-        var version = Firebug.GlobalUI.getVersion();
515  
-        url = firstRunPage + version;
516  
-        gBrowser.selectedTab = gBrowser.addTab(url, null, null, null);
517  
-    },
518  
-
519 512
     setPosition: function(newPosition)
520 513
     {
521 514
         // todo
@@ -606,7 +599,64 @@ Firebug.GlobalUI =
606 599
 
607 600
         win.nsContextMenu.prototype.setTarget = this.setTargetOriginal;
608 601
         win.nsContextMenu.prototype.initItems = this.initItemsOriginal;
609  
-    }
  602
+    },
  603
+
  604
+    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  605
+    // First Run Page
  606
+
  607
+    loadFirstRunPage: function(win, reason)
  608
+    {
  609
+        if (checkFirebugVersion(PrefLoader.getPref("currentVersion")) <= 0)
  610
+            return;
  611
+
  612
+        // Do not show the first run page when Firebug is being updated. It'll be displayed
  613
+        // the next time the browser is restarted
  614
+        // # ADDON_UPGRADE == 7
  615
+        if (reason == 7)
  616
+            return;
  617
+
  618
+        // Open the page in the top most window, so the user can see it immediately.
  619
+        var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
  620
+        if (wm.getMostRecentWindow("navigator:browser") == win.top)
  621
+        {
  622
+            // Update the preference to make sure the page is not displayed again.
  623
+            // To avoid being annoying when Firefox crashes, forcibly save it, too.
  624
+            var version = Firebug.GlobalUI.getVersion();
  625
+            PrefLoader.setPref("currentVersion", version);
  626
+
  627
+            if (PrefLoader.getPref("showFirstRunPage"))
  628
+            {
  629
+                var timeout = setTimeout(function()
  630
+                {
  631
+                    if (window.closed)
  632
+                        return;
  633
+
  634
+                    Firebug.GlobalUI.openFirstRunPage();
  635
+                }, 1000);
  636
+
  637
+                window.addEventListener("unload", function()
  638
+                {
  639
+                    clearTimeout(timeout);
  640
+                }, false);
  641
+            }
  642
+        }
  643
+    },
  644
+
  645
+    openFirstRunPage: function()
  646
+    {
  647
+        var version = Firebug.GlobalUI.getVersion();
  648
+        url = firstRunPage + version;
  649
+
  650
+        // Open the firstRunPage in background
  651
+        /*gBrowser.selectedTab = */gBrowser.addTab(url, null, null, null);
  652
+
  653
+        // Make sure prefs are stored, otherwise the firstRunPage would be displayed
  654
+        // again if Firefox crashes.
  655
+        setTimeout(function()
  656
+        {
  657
+            PrefLoader.forceSave();
  658
+        }, 400);
  659
+    },
610 660
 }
611 661
 
612 662
 // ********************************************************************************************* //
@@ -1273,9 +1323,7 @@ var elements = cloneArray(document.getElementsByClassName("fbInternational"));
1273 1323
 Locale.internationalizeElements(document, elements, ["label", "tooltiptext", "aria-label"]);
1274 1324
 
1275 1325
 // ********************************************************************************************* //
1276  
-// First Run Page
1277  
-
1278  
-var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
  1326
+// Version Checker
1279 1327
 
1280 1328
 function checkFirebugVersion(currentVersion)
1281 1329
 {
@@ -1290,33 +1338,6 @@ function checkFirebugVersion(currentVersion)
1290 1338
     return versionChecker.compare(version, currentVersion);
1291 1339
 }
1292 1340
 
1293  
-if (checkFirebugVersion(PrefLoader.getPref("currentVersion")) > 0)
1294  
-{
1295  
-    // Open the page in the top most window, so the user can see it immediately.
1296  
-    if (wm.getMostRecentWindow("navigator:browser") == window.top)
1297  
-    {
1298  
-        // Don't forget to update the preference, so the page is not displayed again
1299  
-        var version = Firebug.GlobalUI.getVersion();
1300  
-        PrefLoader.setPref("currentVersion", version);
1301  
-
1302  
-        if (PrefLoader.getPref("showFirstRunPage"))
1303  
-        {
1304  
-            var timeout = setTimeout(function()
1305  
-            {
1306  
-                if (window.closed)
1307  
-                    return;
1308  
-
1309  
-                Firebug.GlobalUI.openFirstRunPage();
1310  
-            }, 1000);
1311  
-
1312  
-            window.addEventListener("unload", function()
1313  
-            {
1314  
-                clearTimeout(timeout);
1315  
-            }, false);
1316  
-        }
1317  
-    }
1318  
-}
1319  
-
1320 1341
 // ********************************************************************************************* //
1321 1342
 // All Pages Activation" is on
1322 1343
 
3  extension/modules/loader.js
@@ -132,7 +132,7 @@ var FirebugLoader =
132 132
         delete win.FBL;
133 133
     },
134 134
 
135  
-    loadIntoWindow: function(win)
  135
+    loadIntoWindow: function(win, reason)
136 136
     {
137 137
         // This is the place where the global Firebug object is created. This object represents
138 138
         // the entire application and all consequently created namespaces and variables should be
@@ -144,6 +144,7 @@ var FirebugLoader =
144 144
         loadSubscript("chrome://firebug/content/firefox/browserOverlay.js", win);
145 145
 
146 146
         win.Firebug.GlobalUI.loadContextMenuOverlay(win);
  147
+        win.Firebug.GlobalUI.loadFirstRunPage(win, reason);
147 148
 
148 149
         // Firebug extensions should initialize here.
149 150
         this.dispatchToScopes("topWindowLoad", [win]);
6  extension/modules/prefLoader.js
@@ -144,6 +144,11 @@ function setPref(name, value)
144 144
     return value;
145 145
 }
146 146
 
  147
+function forceSave()
  148
+{
  149
+    Services.prefs.savePrefFile(null);
  150
+}
  151
+
147 152
 // ********************************************************************************************* //
148 153
 // Registration
149 154
 
@@ -151,5 +156,6 @@ PrefLoader.loadDefaultPrefs = loadDefaultPrefs;
151 156
 PrefLoader.clearDefaultPrefs = clearDefaultPrefs;
152 157
 PrefLoader.getPref = getPref;
153 158
 PrefLoader.setPref = setPref;
  159
+PrefLoader.forceSave = forceSave;
154 160
 
155 161
 // ********************************************************************************************* //

0 notes on commit d349c95

Please sign in to comment.
Something went wrong with that request. Please try again.