Browse Source

Fix startup and shutdown sequence, disabling add-on didn't work when adapter wasn't running. May also improve P4TB-395.

master
Jörg Knobloch 1 year ago
parent
commit
79b87dd948
3 changed files with 38 additions and 14 deletions
  1. +7
    -5
      addon/content/modules/pEpServer.js
  2. +2
    -1
      addon/content/pEpForThunderbird.js
  3. +29
    -8
      addon/content/pepmsghdrview.js

+ 7
- 5
addon/content/modules/pEpServer.js View File

@ -101,11 +101,13 @@ class pEpServer {
this.log.error("XMLHttpRequest failed", err2.message);
// This file is used in the test suite, hence calling this at the top doesn't work.
let { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
Services.prompt.alert(
win,
win.pEp.pEpHdrView.getLocaleMessage("alertTitle"),
win.pEp.pEpHdrView.getLocaleMessage("alertMessage"),
);
if (win.pEp) { // Can be gone if someone disabled the add-on.
Services.prompt.alert(
win,
win.pEp.pEpHdrView.getLocaleMessage("alertTitle"),
win.pEp.pEpHdrView.getLocaleMessage("alertMessage"),
);
}
reject(err2);
}), functionName == "pollForEvents" ? 10000 : 5000);
});


+ 2
- 1
addon/content/pEpForThunderbird.js View File

@ -66,6 +66,7 @@ class pEpForThunderbird extends pEp {
this.isControllerAlert = false;
this.alertFolder = null;
this.passphrasePromptActive = false;
this.pEpFolderCleanupTimer = null;
this.MOZ_APP_VERSION = parseInt(AppConstants.MOZ_APP_VERSION, 10);
this.platform = AppConstants.platform;
@ -221,7 +222,7 @@ class pEpForThunderbird extends pEp {
.map((factory) => factory.unregister());
this.factories = {};
this.pEpFolderCleanupTimer.cancel();
if (this.pEpFolderCleanupTimer) this.pEpFolderCleanupTimer.cancel();
if (this.pollSession) {
// Reset controller global before actually closing the session.


+ 29
- 8
addon/content/pepmsghdrview.js View File

@ -155,26 +155,35 @@ var pEpHdrView = {
pEpController.log.debug("pEpHdrView: init()");
this.win = win;
this.localeMessagesMap = localeMessagesMap;
// Step 1: UI.
this.initUI(win);
pEpController.init(localeMessagesMap);
// Step 2: pEp column.
columnOverlay.init(win);
this.tb_CanDetachAttachments = this.win.CanDetachAttachments;
// Usually the column handler is added when the window loads.
// In our setup it's added later and we may miss the first notification.
// So we fire one ourserves.
// So we fire one ourselves.
if (win.gDBView && win.document.documentElement.getAttribute("windowtype") == "mail:3pane") {
Services.obs.notifyObservers(null, "MsgCreateDBView");
}
// Step 3: Attachment hack.
this.tb_CanDetachAttachments = this.win.CanDetachAttachments;
// Step 4: Header listener.
this.headerListener = {
onStartHeaders: this.onStartHeaders.bind(this),
onEndHeaders: () => {},
};
win.gMessageListeners.push(this.headerListener);
// Step 5: trust changes observer.
Services.obs.addObserver(this, "pEp-trust-changed");
// Step 6: Finally the controller. This can fail if no adapter is running.
pEpController.init(localeMessagesMap);
},
openOptions() {
@ -216,19 +225,31 @@ var pEpHdrView = {
destroy() {
pEpController.log.debug("pEpHdrView: destroy()");
// Undo everything we did in step 1 to 6 during `init()`.
// Step 1: UI.
const privacyNode = this.win.document.getElementById(TAG_PRIVACY_NODE_ID);
if (privacyNode) privacyNode.remove();
Services.obs.removeObserver(this, "pEp-trust-changed");
// Step 2: pEp column.
columnOverlay.destroy();
// Step 3: Attachment hack.
this.win.CanDetachAttachments = this.tb_CanDetachAttachments;
// Step 4: Header listener.
for (let i = 0; i < this.win.gMessageListeners.length; i++) {
if (this.win.gMessageListeners[i] === this.headerListener) {
this.win.gMessageListeners.splice(i, 1);
break;
}
}
columnOverlay.destroy();
pEpController.shutdown();
this.win.CanDetachAttachments = this.tb_CanDetachAttachments;
// Step 5: trust changes observer.
Services.obs.removeObserver(this, "pEp-trust-changed");
// Step 6: Finally the controller.
pEpController.shutdown();
},
observe(aSubject, aTopic, aData) {


Loading…
Cancel
Save