diff --git a/app/src/main/java/com/duckduckgo/widget/SearchWidgetConfigurator.kt b/app/src/main/java/com/duckduckgo/widget/SearchWidgetConfigurator.kt index 6d1b1dbff9ff..2cad58823209 100644 --- a/app/src/main/java/com/duckduckgo/widget/SearchWidgetConfigurator.kt +++ b/app/src/main/java/com/duckduckgo/widget/SearchWidgetConfigurator.kt @@ -21,6 +21,7 @@ import android.content.Context import android.content.Intent import android.view.View import android.widget.RemoteViews +import com.duckduckgo.app.browser.BrowserActivity import com.duckduckgo.app.browser.R import com.duckduckgo.app.systemsearch.SystemSearchActivity import com.duckduckgo.common.utils.DispatcherProvider @@ -41,13 +42,9 @@ class SearchWidgetConfigurator @Inject constructor( remoteViews: RemoteViews, fromFavWidget: Boolean, ) { - val voiceSearchEnabled = withContext(dispatcherProvider.io()) { - voiceSearchAvailability.isVoiceSearchAvailable + val (voiceSearchEnabled, duckAiEnabled) = withContext(dispatcherProvider.io()) { + voiceSearchAvailability.isVoiceSearchAvailable to (duckChat.isEnabled() && duckChat.wasOpenedBefore()) } - val duckAiIntent = withContext(dispatcherProvider.io()) { - duckChat.createDuckChatIntent() - } - val duckAiEnabled = duckAiIntent != null logcat { "SearchWidgetConfigurator voiceSearchEnabled=$voiceSearchEnabled, duckAiEnabled=$duckAiEnabled" } @@ -63,7 +60,7 @@ class SearchWidgetConfigurator @Inject constructor( } if (duckAiEnabled) { - val pendingIntent = buildDuckAiPendingIntent(context, duckAiIntent!!) + val pendingIntent = buildDuckAiPendingIntent(context) remoteViews.setOnClickPendingIntent(R.id.duckAi, pendingIntent) } } @@ -79,8 +76,8 @@ class SearchWidgetConfigurator @Inject constructor( private fun buildDuckAiPendingIntent( context: Context, - intent: Intent, ): PendingIntent { + val intent = BrowserActivity.intent(context, openDuckChat = true).also { it.action = Intent.ACTION_VIEW } return PendingIntent.getActivity(context, 2, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } } diff --git a/duckchat/duckchat-api/src/main/java/com/duckduckgo/duckchat/api/DuckChat.kt b/duckchat/duckchat-api/src/main/java/com/duckduckgo/duckchat/api/DuckChat.kt index f34dc673b746..6b748e0f4227 100644 --- a/duckchat/duckchat-api/src/main/java/com/duckduckgo/duckchat/api/DuckChat.kt +++ b/duckchat/duckchat-api/src/main/java/com/duckduckgo/duckchat/api/DuckChat.kt @@ -16,7 +16,6 @@ package com.duckduckgo.duckchat.api -import android.content.Intent import android.net.Uri /** @@ -36,14 +35,6 @@ interface DuckChat { */ fun openDuckChat() - /** - * Creates an Intent that can be used to launch the DuckChat WebView. - * Does not actually open DuckChat, just prepares the Intent. - * - * @return Intent that can be used to open DuckChat, or null if DuckChat cannot be opened. - */ - suspend fun createDuckChatIntent(): Intent? - /** * Auto-prompts the DuckChat WebView with the provided [String] query. */ diff --git a/duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/RealDuckChat.kt b/duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/RealDuckChat.kt index aed6bae11437..def4c5a8ecac 100644 --- a/duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/RealDuckChat.kt +++ b/duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/RealDuckChat.kt @@ -380,21 +380,6 @@ class RealDuckChat @Inject constructor( openDuckChat(emptyMap()) } - override suspend fun createDuckChatIntent(): Intent? { - logcat { "Duck.ai: createDuckChatIntent" } - if (!isDuckChatEnabled || !isDuckChatUserEnabled || !wasOpenedBefore()) { - logcat { "Duck.ai: createDuckChatIntent. DuckChat is not enabled or opened before, returning null" } - return null - } - - val parameters = addChatParameters("", autoPrompt = false) - val url = appendParameters(parameters, duckChatLink) - - return browserNav.openDuckChat(context, duckChatUrl = url, hasSessionActive = true) - .apply { - flags = Intent.FLAG_ACTIVITY_NEW_TASK - } - } override fun openDuckChatWithAutoPrompt(query: String) { logcat { "Duck.ai: openDuckChatWithAutoPrompt query $query" } val parameters = addChatParameters(query, autoPrompt = true)