Skip to content

Commit 3b92638

Browse files
committed
add api to check if a shortcut exists
1 parent 34afa29 commit 3b92638

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

webui/src/main/kotlin/com/dergoogler/mmrl/webui/interfaces/ModuleInterface.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ class ModuleInterface(
220220
createShortcutInternal(title, icon)
221221
}
222222

223+
private val shortcutManager = context.getSystemService(ShortcutManager::class.java)
224+
225+
@JavascriptInterface
226+
fun hasShortcut(): Boolean {
227+
val id = modId.id
228+
val shortcutId = "shortcut_$id"
229+
return shortcutManager.pinnedShortcuts.any { it.id == shortcutId }
230+
}
231+
223232
private fun createShortcutInternal(title: String, icon: String) {
224233

225234
if (options.cls == null) {
@@ -242,7 +251,6 @@ class ModuleInterface(
242251
return
243252
}
244253

245-
val shortcutManager = context.getSystemService(ShortcutManager::class.java)
246254

247255
if (!shortcutManager.isRequestPinShortcutSupported) {
248256
Toast.makeText(
@@ -252,7 +260,7 @@ class ModuleInterface(
252260
).show()
253261
}
254262

255-
if (shortcutManager.pinnedShortcuts.any { it.id == shortcutId }) {
263+
if (hasShortcut()) {
256264
Toast.makeText(
257265
context,
258266
context.getString(R.string.shortcut_already_exists),

0 commit comments

Comments
 (0)