From e25fe7a224d4710b7b6451dd174a4408cdd734a5 Mon Sep 17 00:00:00 2001 From: simonljus Date: Thu, 23 Jul 2026 10:41:13 +0200 Subject: [PATCH 1/2] fix(android): resolve promise for loadWithKeys --- .../getcapacitor/community/intercom/intercom/IntercomPlugin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/java/com/getcapacitor/community/intercom/intercom/IntercomPlugin.java b/android/src/main/java/com/getcapacitor/community/intercom/intercom/IntercomPlugin.java index 1647e57..d4d1647 100644 --- a/android/src/main/java/com/getcapacitor/community/intercom/intercom/IntercomPlugin.java +++ b/android/src/main/java/com/getcapacitor/community/intercom/intercom/IntercomPlugin.java @@ -57,6 +57,7 @@ public void loadWithKeys(PluginCall call) { // load parent super.load(); + call.resolve(); } @Override From 5f0c37289dddde9e032ce12403cad02962754f5c Mon Sep 17 00:00:00 2001 From: simonljus Date: Thu, 23 Jul 2026 13:23:26 +0200 Subject: [PATCH 2/2] fix(android): prevent from crashing on start if using loadWithKeys over config --- .../intercom/intercom/IntercomPlugin.java | 56 ++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/com/getcapacitor/community/intercom/intercom/IntercomPlugin.java b/android/src/main/java/com/getcapacitor/community/intercom/intercom/IntercomPlugin.java index d4d1647..f04ff38 100644 --- a/android/src/main/java/com/getcapacitor/community/intercom/intercom/IntercomPlugin.java +++ b/android/src/main/java/com/getcapacitor/community/intercom/intercom/IntercomPlugin.java @@ -38,7 +38,8 @@ public class IntercomPlugin extends Plugin { private static final String EVENT_WINDOW_DID_HIDE = "windowDidHide"; private final IntercomPushClient intercomPushClient = new IntercomPushClient(); - + + private volatile boolean isIntercomInitialized = false; @Override public void load() { // Set up Intercom @@ -50,14 +51,38 @@ public void load() { @PluginMethod public void loadWithKeys(PluginCall call) { - String appId = call.getString("appId", "NO_APP_ID_PASSED"); - String apiKey = call.getString("apiKeyAndroid", "NO_API_KEY_PASSED"); - - Intercom.initialize(this.getActivity().getApplication(), apiKey, appId); + String appId = call.getString("appId"); + String apiKey = call.getString("apiKeyAndroid"); + + if (appId == null || appId.isEmpty() || apiKey == null || apiKey.isEmpty()) { + Logger.error("Intercom", "ERROR: loadWithKeys() called without a valid appId/apiKeyAndroid"); + // load parent + super.load(); + call.reject("loadWithKeys() requires both appId and apiKeyAndroid"); + return; + } + + Exception initError = null; + try { + Intercom.initialize(this.getActivity().getApplication(), apiKey, appId); + isIntercomInitialized = true; + } catch (Exception e) { + isIntercomInitialized = false; + Logger.error("Intercom", "ERROR: Something went wrong when initializing Intercom with provided keys", e); + initError = e; + } // load parent super.load(); - call.resolve(); + + if (isIntercomInitialized) { + call.resolve(); + } else { + call.reject("Failed to initialize Intercom", initError); + } + + + } @Override @@ -71,6 +96,11 @@ public void handleOnStart() { public void run() { //We also initialize intercom here just in case it has died. If Intercom is already set up, this won't do anything. setUpIntercom(); + if (!isIntercomInitialized) { + Logger.error("Intercom", "Skipping handlePushMessage — Intercom is not initialized"); + return; + } + Intercom.client().handlePushMessage(); } } @@ -274,15 +304,27 @@ public void displayArticle(PluginCall call) { } private void setUpIntercom() { + if(isIntercomInitialized){ + return; + } try { // get config CapConfig config = this.bridge.getConfig(); String apiKey = config.getPluginConfiguration("Intercom").getString("androidApiKey"); String appId = config.getPluginConfiguration("Intercom").getString("androidAppId"); + + // check if keys are omitted, possibly calling loadWithKeys later + if (apiKey == null || apiKey.isEmpty() || appId == null || appId.isEmpty()) { + Logger.warn("Intercom", "WARN: androidApiKey/androidAppId missing from capacitor config, assuming the plugin method loadWithKeys() will be called, skipping Intercom.initialize()"); + isIntercomInitialized = false; + return; + } // init intercom sdk Intercom.initialize(this.getActivity().getApplication(), apiKey, appId); + isIntercomInitialized = true; } catch (Exception e) { + isIntercomInitialized = false; Logger.error("Intercom", "ERROR: Something went wrong when initializing Intercom. Check your configurations", e); } } @@ -322,4 +364,4 @@ private static List listFromJSON(JSArray jsonArray) { } return list; } -} +} \ No newline at end of file