Bug 1615453 - Fix calendar tabs when they are focused at startup. r=darktrojan
authorPaul Morris <paul@thunderbird.net>
Fri, 14 Feb 2020 11:18:46 -0500
changeset 37364 c43ae2963d75b26195d0f8567c99fd66bf9e747e
parent 37363 f1ad9a7a77903025d4b88c101c34d38321202b24
child 37365 e8abde27176eba6a6d585787ac1c035c61a53c97
push id2566
push userclokep@gmail.com
push dateMon, 09 Mar 2020 19:20:31 +0000
treeherdercomm-beta@a352facfa0a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdarktrojan
bugs1615453
Bug 1615453 - Fix calendar tabs when they are focused at startup. r=darktrojan
calendar/lightning/content/messenger-overlay-sidebar.js
mail/base/content/msgMail3PaneWindow.js
--- a/calendar/lightning/content/messenger-overlay-sidebar.js
+++ b/calendar/lightning/content/messenger-overlay-sidebar.js
@@ -1,16 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* exported refreshUIBits, switchCalendarView, rescheduleInvitationsUpdate,
- *          openInvitationsDialog, onToolbarsPopupShowingWithMode,
- *          InitViewCalendarPaneMenu, calendarOnToolbarsPopupShowing,
- *          customizeMailToolbarForTabType, gCurrentMode
+/* exported calendarOnToolbarsPopupShowing, customizeMailToolbarForTabType,
+ *          gCurrentMode, InitViewCalendarPaneMenu, loadCalendarComponent,
+ *          onToolbarsPopupShowingWithMode, openInvitationsDialog, refreshUIBits,
+ *          rescheduleInvitationsUpdate, switchCalendarView
  */
 
 /* import-globals-from ../../base/content/calendar-command-controller.js */
 /* import-globals-from ../../base/content/calendar-invitations-manager.js */
 /* import-globals-from ../../base/content/today-pane.js */
 /* import-globals-from lightning-item-panel.js */
 
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
@@ -369,17 +369,21 @@ var calendarItemTabType = {
 
 window.addEventListener("load", e => {
   let tabmail = document.getElementById("tabmail");
   tabmail.registerTabType(calendarTabType);
   tabmail.registerTabType(calendarItemTabType);
   tabmail.registerTabMonitor(calendarTabMonitor);
 });
 
-async function ltnOnLoad(event) {
+/**
+ * Loads the calendar component. Called once at startup as the application
+ * window is loaded, before tabs are restored.
+ */
+async function loadCalendarComponent() {
   await uninstallLightningAddon();
 
   // Check if the binary component was loaded
   checkCalendarBinaryComponent();
 
   document
     .getElementById("calendarDisplayDeck")
     .addEventListener("select", LtnObserveDisplayDeckChange, true);
@@ -761,18 +765,16 @@ var gCalSetupMailContext = {
 function calInitMessageMenu() {
   calInitMessageMenu.origFunc();
 
   document.getElementById("markMenu").disabled = gCurrentMode != "mail";
 }
 calInitMessageMenu.origFunc = InitMessageMenu;
 InitMessageMenu = calInitMessageMenu;
 
-window.addEventListener("load", ltnOnLoad, { capture: false, once: true });
-
 /**
  * Get the toolbox id for the current tab type.
  *
  * @return {string}  A toolbox id or null
  */
 function getToolboxIdForCurrentTabType() {
   // A mapping from calendar tab types to toolbox ids.
   const calendarToolboxIds = {
--- a/mail/base/content/msgMail3PaneWindow.js
+++ b/mail/base/content/msgMail3PaneWindow.js
@@ -1,14 +1,15 @@
 /**
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* import-globals-from ../../../../toolkit/modules/PageMenu.jsm */
+/* import-globals-from ../../../calendar/lightning/content/messenger-overlay-sidebar.js */
 /* import-globals-from ../../../mailnews/base/prefs/content/accountUtils.js */
 /* import-globals-from ../../../mailnews/base/util/MailnewsMigrator.jsm */
 /* import-globals-from ../../components/newmailaccount/content/accountProvisionerTab.js */
 /* import-globals-from ../../components/preferences/preferencesTab.js */
 /* import-globals-from messenger-customization.js */
 /* import-globals-from commandglue.js */
 /* import-globals-from folderDisplay.js */
 /* import-globals-from folderPane.js */
@@ -840,16 +841,19 @@ function getWindowStateForSessionPersist
  * @param aDontRestoreFirstTab If this is true, the first tab will not be
  *                             restored, and will continue to retain focus at
  *                             the end. This is needed if the window was opened
  *                             with a folder or a message as an argument.
  *
  * @return true if the restoration was successful, false otherwise.
  */
 async function atStartupRestoreTabs(aDontRestoreFirstTab) {
+  // The calendar component needs to be loaded before restoring any calendar tabs.
+  await loadCalendarComponent();
+
   let state = await SessionStoreManager.loadingWindow(window);
   if (state) {
     let tabsState = state.tabs;
     let tabmail = document.getElementById("tabmail");
     tabmail.restoreTabs(tabsState, aDontRestoreFirstTab);
   }
 
   // it's now safe to load extra Tabs.