Conversation
Add _initialized flag to prevent "Intercom not initialized" crash when Intercom methods are called before initIntercom() completes. All Intercom operations now check _initialized before proceeding. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the 'Intercom not initialized' crash by introducing an _initialized flag to guard against race conditions. The approach is sound, however, I've found a critical logic bug in the initIntercom method that could leave the manager in an incorrect state. Additionally, there's an opportunity to refactor some duplicated logic to improve maintainability. My review includes specific comments and suggestions to address these points.
| Future<void> initIntercom() async { | ||
| if (Env.intercomAppId == null) return; | ||
| return PlatformService.executeIfSupportedAsync( | ||
| _isIntercomEnabled, | ||
| await PlatformService.executeIfSupportedAsync( | ||
| PlatformService.isIntercomSupported && (Env.intercomAppId != null && Env.intercomAppId!.isNotEmpty), | ||
| () => intercom.initialize( | ||
| Env.intercomAppId!, | ||
| iosApiKey: Env.intercomIOSApiKey, | ||
| androidApiKey: Env.intercomAndroidApiKey, | ||
| ), | ||
| ); | ||
| _initialized = true; | ||
| } |
There was a problem hiding this comment.
The early return on line 29 if Env.intercomAppId is null prevents _initialized from ever being set to true. This leaves the IntercomManager in a perpetual 'initializing' state, which is incorrect as the initialization process has completed (by doing nothing).
The check for Env.intercomAppId != null on line 31 is sufficient. By removing the early return, _initialized will be correctly set to true after the initialization attempt, and _isIntercomEnabled will correctly evaluate to false if Intercom is not configured, preventing any calls.
Future<void> initIntercom() async {
await PlatformService.executeIfSupportedAsync(
PlatformService.isIntercomSupported && (Env.intercomAppId != null && Env.intercomAppId!.isNotEmpty),
() => intercom.initialize(
Env.intercomAppId!,
iosApiKey: Env.intercomIOSApiKey,
androidApiKey: Env.intercomAndroidApiKey,
),
);
_initialized = true;
}| bool get _isIntercomEnabled => | ||
| PlatformService.isIntercomSupported && (Env.intercomAppId != null && Env.intercomAppId!.isNotEmpty); | ||
| _initialized && | ||
| PlatformService.isIntercomSupported && | ||
| (Env.intercomAppId != null && Env.intercomAppId!.isNotEmpty); |
There was a problem hiding this comment.
To improve readability and avoid duplicating logic, consider extracting the condition for whether Intercom is configured into its own private getter. This condition is used here and also in initIntercom.
bool get _isIntercomConfigured =>
PlatformService.isIntercomSupported &&
(Env.intercomAppId != null && Env.intercomAppId!.isNotEmpty);
bool get _isIntercomEnabled => _initialized && _isIntercomConfigured;You would then also use _isIntercomConfigured inside initIntercom.
Set _initialized=true on unsupported platforms and when API key is empty so methods degrade gracefully. Only leave _initialized=false on actual initialization failure. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
fixed in #4624 |
|
Hey @aaravgarg 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! 💜 |
Summary
_initializedflag toIntercomManagerto guard all Intercom callsinitIntercom()completes_isIntercomEnabledcheck now includes the initialization flag, so all operations silently skip if not yet initializedCrash Stats
Test plan
🤖 Generated with Claude Code