FIX: Do not execute initializers if plugin is disabled.

FIX: Do not execute initializers if plugin is disabled.

diff --git a/assets/javascripts/discourse/initializers/hook-composer.js.es6 b/assets/javascripts/discourse/initializers/hook-composer.js.es6
index b3d2d09..097dad5 100644
--- a/assets/javascripts/discourse/initializers/hook-composer.js.es6
+++ b/assets/javascripts/discourse/initializers/hook-composer.js.es6
@@ -25,6 +25,11 @@ import {
 export default {
   name: "hook-composer",
   initialize(container) {
+    const siteSettings = container.lookup("site-settings:main");
+    if (!siteSettings.encrypt_enabled) {
+      return;
+    }
+
     // Decode composer on reply reload. This usually occurs when a post is
     // edited or a draft is loaded.
     const appEvents = container.lookup("app-events:main");
diff --git a/assets/javascripts/discourse/initializers/hook-decrypt-post.js.es6 b/assets/javascripts/discourse/initializers/hook-decrypt-post.js.es6
index 32fe307..2724061 100644
--- a/assets/javascripts/discourse/initializers/hook-decrypt-post.js.es6
+++ b/assets/javascripts/discourse/initializers/hook-decrypt-post.js.es6
@@ -13,7 +13,12 @@ import showModal from "discourse/lib/show-modal";
 export default {
   name: "hook-decrypt-post",
 
-  initialize() {
+  initialize(container) {
+    const siteSettings = container.lookup("site-settings:main");
+    if (!siteSettings.encrypt_enabled) {
+      return;
+    }
+
     withPluginApi("0.8.25", api => {
       api.reopenWidget("post-contents", {
         html(attrs, state) {
diff --git a/assets/javascripts/discourse/initializers/hook-decrypt-topic.js.es6 b/assets/javascripts/discourse/initializers/hook-decrypt-topic.js.es6
index 8346cbc..78408b6 100644
--- a/assets/javascripts/discourse/initializers/hook-decrypt-topic.js.es6
+++ b/assets/javascripts/discourse/initializers/hook-decrypt-topic.js.es6
@@ -60,6 +60,11 @@ export default {
   name: "hook-decrypt-topic",
 
   initialize(container) {
+    const siteSettings = container.lookup("site-settings:main");
+    if (!siteSettings.encrypt_enabled) {
+      return;
+    }
+
     const appEvents = container.lookup("app-events:main");
     appEvents.on("encrypt:status-changed", decryptTitles);
 
diff --git a/assets/javascripts/discourse/initializers/hook-draft.js.es6 b/assets/javascripts/discourse/initializers/hook-draft.js.es6
index 3c96dcd..144988b 100644
--- a/assets/javascripts/discourse/initializers/hook-draft.js.es6
+++ b/assets/javascripts/discourse/initializers/hook-draft.js.es6
@@ -13,7 +13,12 @@ import Draft from "discourse/models/draft";
 export default {
   name: "hook-draft",
 
-  initialize() {
+  initialize(container) {
+    const siteSettings = container.lookup("site-settings:main");
+    if (!siteSettings.encrypt_enabled) {
+      return;
+    }
+
     Draft.reopenClass({
       save(key, sequence, data) {
         // TODO: https://github.com/emberjs/ember.js/issues/15291
diff --git a/assets/javascripts/discourse/initializers/hook-gather-keys.js.es6 b/assets/javascripts/discourse/initializers/hook-gather-keys.js.es6
index 0e24f02..83662ce 100644
--- a/assets/javascripts/discourse/initializers/hook-gather-keys.js.es6
+++ b/assets/javascripts/discourse/initializers/hook-gather-keys.js.es6
@@ -8,7 +8,12 @@ import {
 export default {
   name: "hook-gather-keys",
 
-  initialize() {
+  initialize(container) {
+    const siteSettings = container.lookup("site-settings:main");
+    if (!siteSettings.encrypt_enabled) {
+      return;
+    }
+
     // Go through the `PreloadStore` and look for any preloaded topic keys.
     for (var storeKey in PreloadStore.data) {
       if (storeKey.includes("topic_")) {
diff --git a/assets/javascripts/discourse/initializers/hook-logout.js.es6 b/assets/javascripts/discourse/initializers/hook-logout.js.es6
index e55886b..b8fbe2b 100644
--- a/assets/javascripts/discourse/initializers/hook-logout.js.es6
+++ b/assets/javascripts/discourse/initializers/hook-logout.js.es6
@@ -3,7 +3,12 @@ import { deleteIndexedDb } from "discourse/plugins/discourse-encrypt/lib/keys_db
 export default {
   name: "hook-logout",
 
-  initialize() {
+  initialize(container) {
+    const siteSettings = container.lookup("site-settings:main");
+    if (!siteSettings.encrypt_enabled) {
+      return;
+    }
+
     if (!Discourse.User.current()) {
       deleteIndexedDb();
     }

GitHub sha: 42c95644

1 Like