From 0d04d39353556fe6ba7c72592f949c984c67fc94 Mon Sep 17 00:00:00 2001 From: Sukhbir Singh Date: Tue, 27 Feb 2018 11:30:54 -0500 Subject: [feat] Display notification to manually fetch messages if Bitmask is shut down If Bitmask is shut down and Thunderbird is still running, notify the user using an alert to refresh the session by manually fetching messages ("Get new messages"). Otherwise if Bitmask has shut down and Thunderbird tries to fetch messages, it will throw up an error and to refresh the session, the user has to manually fetch the messages. There can be better ways of handling this but for now we should just make sure that the user knows why the messages are not being fetched in case Bitmask stops running or is shut down. Another solution can be to check for messages automatically for the user after Bitmask is running to refresh the session but the reason this approach was not preferred was because the user may not wish to check for new messages and force-checking would not be transparent. (Not to forget, the XUL hacks :) This commit also removes a redundant string bundle call. --- .../content/accountWizard/bitmaskMessengerOverlay.js | 20 ++++++++++++++++++-- .../locale/en-US/bitmaskMessengerOverlay.properties | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/chrome/content/accountWizard/bitmaskMessengerOverlay.js b/chrome/content/accountWizard/bitmaskMessengerOverlay.js index 31e7887..d6f9ae1 100644 --- a/chrome/content/accountWizard/bitmaskMessengerOverlay.js +++ b/chrome/content/accountWizard/bitmaskMessengerOverlay.js @@ -7,6 +7,8 @@ XPCOMUtils.defineLazyGetter(this, "_", () => l10nHelper("chrome://bitmask/locale/bitmaskMessengerOverlay.properties") ); +var gNotified = false; + var notificationBar = { onStartHeaders: function() { let currentFolder = gFolderDisplay.displayedFolder.name; @@ -46,9 +48,18 @@ var notificationBar = { } } +function displayAlert(image, title, text) { + try { + let alertsService = Cc["@mozilla.org/alerts-service;1"] + .getService(Ci.nsIAlertsService) + alertsService.showAlertNotification(image, title, text, false, '', null); + } catch (e) { + console.log(text); + } +} + function overlayStartup() { let myPanel = document.getElementById("bitmaskStatusBarPanel"); - let strBundle = document.getElementById("bitmaskMessengerStrings"); // We just need to check if bitmaskd is running and if we were able to // authorize with it using the token from bitmask.js @@ -57,10 +68,15 @@ function overlayStartup() { myPanel.label = _("bitmaskStatusOn", data["mail"]); myPanel.style.color = "green"; myPanel.src = "chrome://bitmask/skin/on.png"; + gNotified = false; }, function(error) { - myPanel.label = strBundle.getString("bitmaskStatusOff"); + myPanel.label = _("bitmaskStatusOff"); myPanel.style.color = "red"; myPanel.src = "chrome://bitmask/skin/off.png"; + if (!gNotified) { + displayAlert("chrome://bitmask/skin/off.png", "Bitmask", _("bitmaskRefreshInbox")); + gNotified = true; + } console.log(error); }); } diff --git a/chrome/locale/en-US/bitmaskMessengerOverlay.properties b/chrome/locale/en-US/bitmaskMessengerOverlay.properties index 59a95a3..5c5aeb7 100644 --- a/chrome/locale/en-US/bitmaskMessengerOverlay.properties +++ b/chrome/locale/en-US/bitmaskMessengerOverlay.properties @@ -2,3 +2,5 @@ bitmaskStatusOn=bitmask is %S bitmaskStatusOff=bitmask is not running bitmaskMsgEncrypted=Bitmask Encrypted Message + +bitmaskRefreshInbox=Bitmask just stopped running. To continue to fetch your messages automatically, make sure Bitmask is running and then fetch your messages manually once to refresh the session. -- cgit v1.2.3