Added an option to automatically launch the final search result app when it becomes the only item in the menu

This commit is contained in:
ottoptj 2024-09-08 09:50:32 +03:00
commit 2a5710c6bb
3 changed files with 15 additions and 1 deletions

View file

@ -854,7 +854,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
} }
private suspend fun applySearchFilter(newFilteredApps: MutableList<Triple<LauncherActivityInfo, UserHandle, Int>>) { private suspend fun applySearchFilter(newFilteredApps: MutableList<Triple<LauncherActivityInfo, UserHandle, Int>>) {
if (!listsEqual(installedApps, newFilteredApps)) { if (sharedPreferenceManager.isAutoLaunchEnabled() && newFilteredApps.size == 1) {
appUtils.launchApp(newFilteredApps[0].first.applicationInfo.packageName, newFilteredApps[0].second)
} else if (!listsEqual(installedApps, newFilteredApps)) {
updateMenu(newFilteredApps) updateMenu(newFilteredApps)
installedApps = newFilteredApps installedApps = newFilteredApps

View file

@ -204,6 +204,10 @@ class SharedPreferenceManager (private val context: Context) {
return preferences.getBoolean("autoKeyboard", false) return preferences.getBoolean("autoKeyboard", false)
} }
fun isAutoLaunchEnabled(): Boolean {
return preferences.getBoolean("autoLaunch", false)
}
fun areContactsEnabled(): Boolean { fun areContactsEnabled(): Boolean {
return preferences.getBoolean("contactsEnabled", false) return preferences.getBoolean("contactsEnabled", false)
} }

View file

@ -77,6 +77,14 @@
android:title="Automatically Open Keyboard" android:title="Automatically Open Keyboard"
app:dependency="searchEnabled" app:dependency="searchEnabled"
app:key="autoKeyboard" /> app:key="autoKeyboard" />
<SwitchPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="false"
android:title="Automatic App Opening"
app:dependency="searchEnabled"
app:key="autoLaunch"
app:summary="Automatically launch an app when it's the last search result" />
</PreferenceCategory> </PreferenceCategory>