From a9c631ad26b4f16874ec19ff9ecb32c6b2b5de3d Mon Sep 17 00:00:00 2001 From: joshliebe Date: Mon, 31 Mar 2025 15:34:15 +0100 Subject: [PATCH] Add Duck.ai chat download killswitch --- .../duckchat/impl/AIChatDownloadFeature.kt | 32 +++++++++++++++++++ .../duckchat/impl/DuckChatWebViewActivity.kt | 9 +++++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/AIChatDownloadFeature.kt diff --git a/duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/AIChatDownloadFeature.kt b/duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/AIChatDownloadFeature.kt new file mode 100644 index 000000000000..89bcc5e98b0a --- /dev/null +++ b/duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/AIChatDownloadFeature.kt @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 DuckDuckGo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.duckduckgo.duckchat.impl + +import com.duckduckgo.anvil.annotations.ContributesRemoteFeature +import com.duckduckgo.di.scopes.AppScope +import com.duckduckgo.feature.toggles.api.Toggle + +@ContributesRemoteFeature( + scope = AppScope::class, + featureName = "aiChatDownload", +) + +interface AIChatDownloadFeature { + + @Toggle.DefaultValue(true) + fun self(): Toggle +} diff --git a/duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/DuckChatWebViewActivity.kt b/duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/DuckChatWebViewActivity.kt index ec9c89bb4db4..b36c3e75e8b2 100644 --- a/duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/DuckChatWebViewActivity.kt +++ b/duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/DuckChatWebViewActivity.kt @@ -107,6 +107,9 @@ class DuckChatWebViewActivity : DuckDuckGoActivity(), DownloadConfirmationDialog @Inject lateinit var duckChat: DuckChatInternal + @Inject + lateinit var aiChatDownloadFeature: AIChatDownloadFeature + private val binding: ActivityDuckChatWebviewBinding by viewBinding() private var pendingFileDownload: PendingFileDownload? = null @@ -163,7 +166,11 @@ class DuckChatWebViewActivity : DuckDuckGoActivity(), DownloadConfirmationDialog } it.setDownloadListener { url, _, contentDisposition, mimeType, _ -> - requestFileDownload(url, contentDisposition, mimeType) + appCoroutineScope.launch(dispatcherProvider.io()) { + if (aiChatDownloadFeature.self().isEnabled()) { + requestFileDownload(url, contentDisposition, mimeType) + } + } } contentScopeScripts.register(