Target static shortcuts at the active app variant - #146
Conversation
📝 WalkthroughWalkthroughThe build now generates variant-specific shortcut resources with the correct application package. A Robolectric test parses the generated shortcuts and verifies package attributes, target classes, shortcut counts, and expected identifiers. ChangesShortcut Resource Generation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant AndroidVariant
participant GenerateShortcutResourcesTask
participant shortcuts_template_xml
participant GeneratedResources
AndroidVariant->>GenerateShortcutResourcesTask: configure targetPackage
GenerateShortcutResourcesTask->>shortcuts_template_xml: load and replace placeholder
GenerateShortcutResourcesTask->>GeneratedResources: write shortcuts.xml
AndroidVariant->>GeneratedResources: add generated res source
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
eb71084 to
131583f
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
buildSrc/src/main/kotlin/Helpers.kt (1)
281-326: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider extracting the XML template out of the Kotlin string literal.
Embedding the full shortcuts XML as a raw Kotlin string means no XML/Android-resource tooling (syntax highlighting,
@string/@drawablereference validation, lint) applies to it, and future edits to the shortcut list happen inside build logic rather than a resource file. Moving the markup to a template resource with a placeholder keeps the content declarative and easier to review/diff.♻️ Proposed refactor
- private fun renderShortcuts(packageName: String) = - """ - <?xml version="1.0" encoding="utf-8"?> - <shortcuts xmlns:android="http://schemas.android.com/apk/res/android"> - <shortcut - android:icon="`@drawable/ic_qu_shadowsocks_launcher`" - android:shortcutId="toggle" - android:shortcutLongLabel="`@string/quick_toggle`" - android:shortcutShortLabel="`@string/quick_toggle`"> - <intent - android:action="android.intent.action.MAIN" - android:targetClass="io.nekohasekai.sagernet.QuickToggleShortcut" - android:targetPackage="$packageName" /> - </shortcut> - ... - </shortcuts> - """.trimIndent() + "\n" + private fun renderShortcuts(packageName: String): String { + val template = javaClass.getResourceAsStream("/shortcuts-template.xml") + ?.bufferedReader() + ?.readText() + ?: error("shortcuts-template.xml resource not found on classpath") + return template.replace("{{TARGET_PACKAGE}}", packageName) + }New file
buildSrc/src/main/resources/shortcuts-template.xmlwould hold the same markup with{{TARGET_PACKAGE}}in place of$packageName.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@buildSrc/src/main/kotlin/Helpers.kt` around lines 281 - 326, Extract the shortcuts XML from the Kotlin string in renderShortcuts into buildSrc/src/main/resources/shortcuts-template.xml, preserving the existing markup and replacing the package interpolation with {{TARGET_PACKAGE}}. Update renderShortcuts to load that template resource and substitute the target package placeholder, retaining the trailing newline behavior and all existing shortcut definitions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@buildSrc/src/main/kotlin/Helpers.kt`:
- Around line 281-326: Extract the shortcuts XML from the Kotlin string in
renderShortcuts into buildSrc/src/main/resources/shortcuts-template.xml,
preserving the existing markup and replacing the package interpolation with
{{TARGET_PACKAGE}}. Update renderShortcuts to load that template resource and
substitute the target package placeholder, retaining the trailing newline
behavior and all existing shortcut definitions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 740645bb-af71-4b6f-9ce6-5fed53046d92
📒 Files selected for processing (3)
app/src/main/res/xml/shortcuts.xmlapp/src/test/java/io/nekohasekai/sagernet/ui/ShortcutTargetPackageTest.ktbuildSrc/src/main/kotlin/Helpers.kt
💤 Files with no reviewable changes (1)
- app/src/main/res/xml/shortcuts.xml
131583f to
46da1d3
Compare
46da1d3 to
79788ce
Compare
|
Verified on Android: all four static shortcuts resolved inside the installed debug variant without launch errors. Existing app data remained intact. |
Summary
Validation
Greptile Summary
This PR makes static shortcuts point at the active app package. The main changes are:
shortcuts.xmlper Android variant.Confidence Score: 5/5
This looks safe to merge.
Important Files Changed
Reviews (4): Last reviewed commit: "fix(shortcuts): target the active applic..." | Re-trigger Greptile