Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

voiceSearchAvailability.isVoiceSearchAvailable to (duckChat.isEnabled() && duckChat.wasOpenedBefore())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use duckChat.isEnabled() which was not available before.

Copy link
Preview

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The complex boolean expression for duckAiEnabled should be extracted to improve readability. Consider creating a separate variable or method for the DuckChat availability check.

Copilot uses AI. Check for mistakes.

}
val duckAiIntent = withContext(dispatcherProvider.io()) {
duckChat.createDuckChatIntent()
}
val duckAiEnabled = duckAiIntent != null

logcat { "SearchWidgetConfigurator voiceSearchEnabled=$voiceSearchEnabled, duckAiEnabled=$duckAiEnabled" }

Expand All @@ -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)
}
}
Expand All @@ -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 }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built the intent directly here.

Copy link
Preview

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The intent creation and action setting should be separated for better readability. Consider creating the intent first, then setting the action on a separate line.

Suggested change
val intent = BrowserActivity.intent(context, openDuckChat = true).also { it.action = Intent.ACTION_VIEW }
val intent = BrowserActivity.intent(context, openDuckChat = true)
intent.action = Intent.ACTION_VIEW

Copilot uses AI. Check for mistakes.

return PendingIntent.getActivity(context, 2, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.duckduckgo.duckchat.api

import android.content.Intent
import android.net.Uri

/**
Expand All @@ -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?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed as it's not needed anymore.


/**
* Auto-prompts the DuckChat WebView with the provided [String] query.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,21 +380,6 @@ class RealDuckChat @Inject constructor(
openDuckChat(emptyMap())
}

override suspend fun createDuckChatIntent(): Intent? {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed as it's not needed anymore.

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)
Expand Down
Loading