Skip to content

Add App Shortcuts for service control (start/stop/toggle)#676

Open
sleshep wants to merge 1 commit intoMetaCubeX:mainfrom
sleshep:main
Open

Add App Shortcuts for service control (start/stop/toggle)#676
sleshep wants to merge 1 commit intoMetaCubeX:mainfrom
sleshep:main

Conversation

@sleshep
Copy link

@sleshep sleshep commented Mar 4, 2026

Add dynamic App Shortcuts for external automation

Background

The app already supports external control via intent actions (START_CLASH / STOP_CLASH / TOGGLE_CLASH) through ExternalControlActivity, and provides a Quick Settings tile via TileService. However, using these intent actions requires third-party tools like Tasker to send intents manually.

Many Android launchers and built-in automation tools (such as Samsung Routines) can natively discover and trigger App Shortcuts, but the app doesn't currently register any. Adding App Shortcuts would allow users to control the Clash service without installing additional apps.

What this PR does

Registers three dynamic App Shortcuts via ShortcutManagerCompat on app launch:

Shortcut Action Icon
Toggle Clash ACTION_TOGGLE_CLASH ic_baseline_swap_vertical_circle
Start Clash ACTION_START_CLASH ic_baseline_flash_on
Stop Clash ACTION_STOP_CLASH ic_baseline_stop

These shortcuts:

  • Appear when long-pressing the app icon on any launcher
  • Can be dragged to the home screen as one-tap widgets
  • Are discoverable by Samsung Routines, Tasker, and other automation tools
  • Support i18n (English + Chinese)

Why dynamic shortcuts (not static XML)

  • shortcuts.xml requires android:targetPackage which doesn't support ${applicationId} placeholder
  • The project has multiple flavors (alpha/meta) with different applicationId, dynamic shortcuts resolve the package name at runtime
  • Allows future enhancement (e.g., updating shortcuts based on running state)

Changes

  • app/.../MainApplication.kt — Added setupShortcuts() method called in onCreate() (main process only)
  • design/.../values/strings.xml — Added 6 English shortcut label strings
  • design/.../values-zh/strings.xml — Added 6 Chinese shortcut label strings

Compatibility

  • Uses ShortcutManagerCompat from AndroidX (already a dependency)
  • Gracefully ignored on API < 25 (Android 7.0 and below)
  • No impact on existing functionality

…tines)

Register toggle/start/stop shortcuts via ShortcutManagerCompat on app launch,
enabling Samsung Routines and other launchers to control the Clash service
through long-press app icon shortcuts.
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.

1 participant