Skip to content

Conversation

@ucswift
Copy link
Member

@ucswift ucswift commented Jan 24, 2026

Summary by CodeRabbit

  • Chores
    • Enhanced Android build system to better handle module imports during application initialization.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 24, 2026

📝 Walkthrough

Walkthrough

The Android application augmentation now extracts the package name from MainApplication.kt's first line and automatically inserts the MediaButtonPackage import statement after the package declaration if not already present, in addition to registering the package.

Changes

Cohort / File(s) Summary
Media Button Import Insertion
plugins/withMediaButtonModule.js
Added logic to derive package name from MainApplication.kt and conditionally insert MediaButtonPackage import statement after the package declaration, with logging support

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A hop and a skip, imports now sync,
Package names parsed without a blink,
MediaButton imports find their place,
Perfectly positioned in the file's space!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'RU-T46 Native PPT Android fix' references a ticket/issue identifier and mentions Android, but lacks specificity about the actual technical change made to the codebase. Consider adding a brief description of the specific fix, such as 'RU-T46: Add MediaButtonPackage import to Android MainApplication' to clarify what problem is being addressed.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@plugins/withMediaButtonModule.js`:
- Around line 484-493: The current package detection uses a line-start regex
that fails if the file has a BOM, blank lines, or comments, causing the import
not to be inserted while still logging success; update the logic that computes
packageMatch/mainApplication.contents: use a multiline-tolerant regex (e.g.,
match first occurrence of /^\s*package\s+([^\s]+)/m) or locate the package
declaration with a search for "package " and capture its end position, then only
perform the replace/insert of importStatement and call
console.log('[withMediaButtonModule] Added MediaButtonPackage import') if the
contents were actually modified (i.e., packageMatch found and
mainApplication.contents changed); keep references to packageMatch, packageName,
importStatement and the replace insertion logic in withMediaButtonModule.

Comment on lines +484 to +493
// Get the package name from the first line of the file
const packageMatch = mainApplication.contents.match(/^package\s+([^\s]+)/);
const packageName = packageMatch ? packageMatch[1] : 'com.resgrid.unit';

// Add import statement for MediaButtonPackage after the package declaration
const importStatement = `import ${packageName}.MediaButtonPackage`;
if (!mainApplication.contents.includes(importStatement)) {
// Add import after the package declaration line
mainApplication.contents = mainApplication.contents.replace(/^(package\s+[^\n]+\n)/, `$1${importStatement}\n`);
console.log('[withMediaButtonModule] Added MediaButtonPackage import');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Handle non-first-line package declarations and avoid false “import added” logs.

If MainApplication.kt starts with a BOM, blank line, or header comment, ^package won’t match, so the import won’t be inserted even though the log says it was. Consider a multiline-safe match and guard if the package declaration isn’t found.

🛠️ Suggested fix
-      const packageMatch = mainApplication.contents.match(/^package\s+([^\s]+)/);
+      const packageMatch = mainApplication.contents.match(/^\s*package\s+([A-Za-z0-9_.]+)\s*$/m);
       const packageName = packageMatch ? packageMatch[1] : 'com.resgrid.unit';

       // Add import statement for MediaButtonPackage after the package declaration
       const importStatement = `import ${packageName}.MediaButtonPackage`;
-      if (!mainApplication.contents.includes(importStatement)) {
-        // Add import after the package declaration line
-        mainApplication.contents = mainApplication.contents.replace(/^(package\s+[^\n]+\n)/, `$1${importStatement}\n`);
-        console.log('[withMediaButtonModule] Added MediaButtonPackage import');
-      }
+      if (!mainApplication.contents.includes(importStatement)) {
+        if (packageMatch) {
+          // Add import after the package declaration line
+          mainApplication.contents = mainApplication.contents.replace(
+            /^\s*package\s+[^\n]+\n/m,
+            (match) => `${match}${importStatement}\n`
+          );
+          console.log('[withMediaButtonModule] Added MediaButtonPackage import');
+        } else {
+          console.warn('[withMediaButtonModule] Package declaration not found; skipped MediaButtonPackage import');
+        }
+      }
🤖 Prompt for AI Agents
In `@plugins/withMediaButtonModule.js` around lines 484 - 493, The current package
detection uses a line-start regex that fails if the file has a BOM, blank lines,
or comments, causing the import not to be inserted while still logging success;
update the logic that computes packageMatch/mainApplication.contents: use a
multiline-tolerant regex (e.g., match first occurrence of
/^\s*package\s+([^\s]+)/m) or locate the package declaration with a search for
"package " and capture its end position, then only perform the replace/insert of
importStatement and call console.log('[withMediaButtonModule] Added
MediaButtonPackage import') if the contents were actually modified (i.e.,
packageMatch found and mainApplication.contents changed); keep references to
packageMatch, packageName, importStatement and the replace insertion logic in
withMediaButtonModule.

@ucswift
Copy link
Member Author

ucswift commented Jan 24, 2026

Approve

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is approved.

@ucswift ucswift merged commit 11d8758 into master Jan 24, 2026
14 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants