diff --git a/android/app/src/main/kotlin/com/follow/clash/plugins/AppPlugin.kt b/android/app/src/main/kotlin/com/follow/clash/plugins/AppPlugin.kt index e562051f8c..8805c19053 100644 --- a/android/app/src/main/kotlin/com/follow/clash/plugins/AppPlugin.kt +++ b/android/app/src/main/kotlin/com/follow/clash/plugins/AppPlugin.kt @@ -134,7 +134,11 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware } "initShortcuts" -> { - initShortcuts(call.arguments as String) + val labels = call.arguments + if (labels is Map<*, *>) { + @Suppress("UNCHECKED_CAST") + initShortcuts(labels as Map) + } result.success(true) } @@ -190,21 +194,51 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware } } - private fun initShortcuts(label: String) { - val shortcut = with(ShortcutInfoCompat.Builder(GlobalState.application, "toggle")) { - setShortLabel(label) - setIcon( + private fun initShortcuts(labels: Map) { + val startLabel = labels["start"] ?: "Start" + val stopLabel = labels["stop"] ?: "Stop" + val toggleLabel = labels["toggle"] ?: return + val shortcuts = listOf( + buildShortcut( + id = "start", + label = startLabel, + action = QuickAction.START, + iconRes = R.drawable.ic_shortcut_start, + ), + buildShortcut( + id = "stop", + label = stopLabel, + action = QuickAction.STOP, + iconRes = R.drawable.ic_shortcut_stop, + ), + buildShortcut( + id = "toggle", + label = toggleLabel, + action = QuickAction.TOGGLE, + iconRes = R.mipmap.ic_launcher_round, + ), + ) + ShortcutManagerCompat.setDynamicShortcuts( + GlobalState.application, shortcuts + ) + } + + private fun buildShortcut( + id: String, + label: String, + action: QuickAction, + iconRes: Int, + ): ShortcutInfoCompat { + return ShortcutInfoCompat.Builder(GlobalState.application, id) + .setShortLabel(label) + .setIcon( IconCompat.createWithResource( GlobalState.application, - R.mipmap.ic_launcher_round, + iconRes, ) ) - setIntent(QuickAction.TOGGLE.quickIntent) - build() - } - ShortcutManagerCompat.setDynamicShortcuts( - GlobalState.application, listOf(shortcut) - ) + .setIntent(action.quickIntent) + .build() } private fun tip(message: String?) { diff --git a/android/app/src/main/res/drawable/ic_shortcut_start.xml b/android/app/src/main/res/drawable/ic_shortcut_start.xml new file mode 100644 index 0000000000..9bbfdd1146 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_shortcut_start.xml @@ -0,0 +1,16 @@ + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/drawable/ic_shortcut_stop.xml b/android/app/src/main/res/drawable/ic_shortcut_stop.xml new file mode 100644 index 0000000000..5e26e69ed8 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_shortcut_stop.xml @@ -0,0 +1,16 @@ + + + + + + + \ No newline at end of file diff --git a/lib/plugins/app.dart b/lib/plugins/app.dart index 612b7cc40e..db9437a50f 100644 --- a/lib/plugins/app.dart +++ b/lib/plugins/app.dart @@ -78,7 +78,11 @@ class App { Future initShortcuts() async { return methodChannel.invokeMethod( 'initShortcuts', - currentAppLocalizations.toggle, + { + 'start': currentAppLocalizations.start, + 'stop': currentAppLocalizations.stop, + 'toggle': currentAppLocalizations.toggle, + }, ); }