Bug 1626066 - Combine previously separate calendar load (and unload) functions. r=darktrojan
authorPaul Morris <paul@thunderbird.net>
Thu, 02 Apr 2020 13:43:04 +0300
changeset 38670 51af2ea087fc6b75847adbe79eb0fbb97431d3d6
parent 38669 4c4e4de548fab79aae78dbf69c3f3b0296300ec1
child 38671 b4dc69d562b20fdf3e3710d712673440dd11bb30
push id400
push userclokep@gmail.com
push dateMon, 04 May 2020 18:56:09 +0000
reviewersdarktrojan
bugs1626066
Bug 1626066 - Combine previously separate calendar load (and unload) functions. r=darktrojan
calendar/base/content/calendar-chrome-startup.js
calendar/lightning/content/messenger-overlay-sidebar.js
--- a/calendar/base/content/calendar-chrome-startup.js
+++ b/calendar/base/content/calendar-chrome-startup.js
@@ -2,30 +2,43 @@
  * 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 ../../lightning/content/messenger-overlay-sidebar.js */
 /* import-globals-from calendar-command-controller.js */
 /* import-globals-from calendar-management.js */
 /* import-globals-from calendar-ui-utils.js */
 /* import-globals-from calendar-views-utils.js */
-/* globals PanelUI */
+
+/* globals calSwitchToMode, changeMode, PanelUI, setUpInvitationsManager,
+ *         tearDownInvitationsManager,
+ */
 
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var { AppConstants } = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 var { calendarDeactivator } = ChromeUtils.import(
   "resource:///modules/calendar/calCalendarDeactivator.jsm"
 );
 
 /* exported commonInitCalendar, commonFinishCalendar */
 
 /**
- * Common initialization steps for calendar chrome windows.
+ * Does calendar initialization steps for a given chrome window. Called at
+ * startup as the application window is loaded, before tabs are restored.
  */
-async function commonInitCalendar() {
+async function loadCalendarComponent() {
+  await uninstallLightningAddon();
+
+  // Check if the binary component was loaded.
+  checkCalendarBinaryComponent();
+
+  document
+    .getElementById("calendarDisplayDeck")
+    .addEventListener("select", LtnObserveDisplayDeckChange, true);
+
   // load locale specific default values for preferences
   setLocaleDefaultPreferences();
 
   // Move around toolbarbuttons and whatever is needed in the UI.
   migrateCalendarUI();
 
   // Load the Calendar Manager
   await loadCalendarManager();
@@ -79,23 +92,59 @@ async function commonInitCalendar() {
    * happen, the initial "onLoad" will already have been triggered at this
    * point (see bug 714431 comment 29). We thus inconditionnally invoke
    * calendarUpdateNewItemsCommand until somebody writes code that enables the
    * checking of the calendar readiness (getProperty("ready") ?).
    */
   calendarUpdateNewItemsCommand();
 
   // Prepare the Today Pane, and if it is ready, display it.
-  TodayPane.onLoad();
+  await TodayPane.onLoad();
+
+  // Add an unload function to the window so we don't leak any listeners.
+  window.addEventListener("unload", unloadCalendarComponent);
+
+  setUpInvitationsManager();
+
+  let filter = document.getElementById("task-tree-filtergroup");
+  filter.value = filter.value || "all";
+  changeMode();
+
+  let mailContextPopup = document.getElementById("mailContext");
+  if (mailContextPopup) {
+    mailContextPopup.addEventListener("popupshowing", gCalSetupMailContext.popup);
+  }
+
+  // Set up customizeDone handlers for our toolbars.
+  let toolbox = document.getElementById("calendar-toolbox");
+  toolbox.customizeDone = function(aEvent) {
+    MailToolboxCustomizeDone(aEvent, "CustomizeCalendarToolbar");
+  };
+  toolbox = document.getElementById("task-toolbox");
+  toolbox.customizeDone = function(aEvent) {
+    MailToolboxCustomizeDone(aEvent, "CustomizeTaskToolbar");
+  };
+
+  updateTodayPaneButton();
+
+  Services.obs.notifyObservers(window, "lightning-startup-done");
 }
 
 /**
- * Common unload steps for calendar chrome windows.
+ * Does unload steps for a given calendar chrome window.
  */
-function commonFinishCalendar() {
+function unloadCalendarComponent() {
+  tearDownInvitationsManager();
+
+  // Remove listener for mailContext.
+  let mailContextPopup = document.getElementById("mailContext");
+  if (mailContextPopup) {
+    mailContextPopup.removeEventListener("popupshowing", gCalSetupMailContext.popup);
+  }
+
   // Unload the calendar manager
   unloadCalendarManager();
 
   // Remove the command controller
   removeCalendarCommandController();
 
   // Clean up window pref observers
   calendarWindowPrefs.cleanup();
--- a/calendar/lightning/content/messenger-overlay-sidebar.js
+++ b/calendar/lightning/content/messenger-overlay-sidebar.js
@@ -17,62 +17,16 @@
  *         tearDownInvitationsManager,
  */
 
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var { AddonManager } = ChromeUtils.import("resource://gre/modules/AddonManager.jsm");
 var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
 
 /**
- * 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);
-
-  // Take care of common initialization
-  await commonInitCalendar();
-
-  // Add an unload function to the window so we don't leak any listeners
-  window.addEventListener("unload", ltnFinish);
-
-  setUpInvitationsManager();
-
-  let filter = document.getElementById("task-tree-filtergroup");
-  filter.value = filter.value || "all";
-  changeMode();
-
-  let mailContextPopup = document.getElementById("mailContext");
-  if (mailContextPopup) {
-    mailContextPopup.addEventListener("popupshowing", gCalSetupMailContext.popup);
-  }
-
-  // Setup customizeDone handlers for our toolbars
-  let toolbox = document.getElementById("calendar-toolbox");
-  toolbox.customizeDone = function(aEvent) {
-    MailToolboxCustomizeDone(aEvent, "CustomizeCalendarToolbar");
-  };
-  toolbox = document.getElementById("task-toolbox");
-  toolbox.customizeDone = function(aEvent) {
-    MailToolboxCustomizeDone(aEvent, "CustomizeTaskToolbar");
-  };
-
-  updateTodayPaneButton();
-
-  Services.obs.notifyObservers(window, "lightning-startup-done");
-}
-
-/**
  * Uninstall the Lightning calendar addon, now that calendar is in Thunderbird.
  */
 async function uninstallLightningAddon() {
   try {
     let addon = await AddonManager.getAddonByID("{e2fda1a4-762b-4020-b5ad-a41df1933103}");
     if (addon) {
       await addon.uninstall();
     }
@@ -191,29 +145,16 @@ function LtnObserveDisplayDeckChange(eve
     (gCurrentMode == "calendar" || gCurrentMode == "task") &&
     id != "calendar-view-box" &&
     id != "calendar-task-box"
   ) {
     calSwitchToMode("mail");
   }
 }
 
-function ltnFinish() {
-  tearDownInvitationsManager();
-
-  // Remove listener for mailContext.
-  let mailContextPopup = document.getElementById("mailContext");
-  if (mailContextPopup) {
-    mailContextPopup.removeEventListener("popupshowing", gCalSetupMailContext.popup);
-  }
-
-  // Common finish steps
-  commonFinishCalendar();
-}
-
 var gCalSetupMailContext = {
   popup() {
     let hasSelection = gFolderDisplay.selectedMessage != null;
     // Disable the convert menu altogether.
     setElementValue("mailContext-calendar-convert-menu", !hasSelection && "true", "hidden");
   },
 };