Skip to content

Commit 3df8ef9

Browse files
committed
add feature flag
1 parent 42016ee commit 3df8ef9

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/toolwindow/AmazonQPanel.kt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import kotlinx.coroutines.CoroutineScope
2121
import kotlinx.coroutines.flow.first
2222
import kotlinx.coroutines.launch
2323
import kotlinx.coroutines.withContext
24+
import software.aws.toolkits.core.utils.getLogger
2425
import software.aws.toolkits.jetbrains.core.coroutines.EDT
2526
import software.aws.toolkits.jetbrains.isDeveloperMode
2627
import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQAppInitContext
@@ -47,9 +48,12 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.utils.isCodeTrans
4748
import software.aws.toolkits.resources.message
4849
import java.awt.datatransfer.DataFlavor
4950
import java.awt.dnd.DropTarget
51+
import java.awt.dnd.DropTargetDragEvent
5052
import java.awt.dnd.DropTargetDropEvent
53+
import java.awt.dnd.DropTargetEvent
5154
import java.util.concurrent.CompletableFuture
5255
import javax.swing.JButton
56+
import javax.imageio.ImageIO.read
5357

5458
class AmazonQPanel(val project: Project, private val scope: CoroutineScope) : Disposable {
5559
private val browser = CompletableFuture<Browser>()
@@ -163,7 +167,7 @@ class AmazonQPanel(val project: Project, private val scope: CoroutineScope) : Di
163167

164168
// Width/Height restriction (only for image types)
165169
try {
166-
val img = javax.imageio.ImageIO.read(fileObj)
170+
val img = read(fileObj)
167171
if (img == null) {
168172
errorMessages.add("$fileName: File could not be read as an image.")
169173
continue
@@ -190,23 +194,26 @@ class AmazonQPanel(val project: Project, private val scope: CoroutineScope) : Di
190194
validImages.subList(20, validImages.size).clear()
191195
}
192196

193-
val json = Gson().toJson(validImages).replace("\\", "\\\\").replace("'", "\\'")
197+
val json = Gson().toJson(validImages)
194198
browserInstance.jcefBrowser.cefBrowser.executeJavaScript(
195199
"window.handleNativeDrop('$json')",
196200
browserInstance.jcefBrowser.cefBrowser.url,
197201
0
198202
)
199203

200-
val errorJson = Gson().toJson(errorMessages).replace("\\", "\\\\").replace("'", "\\'")
204+
val errorJson = Gson().toJson(errorMessages)
201205
browserInstance.jcefBrowser.cefBrowser.executeJavaScript(
202206
"window.handleNativeNotify('$errorJson')",
203207
browserInstance.jcefBrowser.cefBrowser.url,
204208
0
205209
)
210+
211+
dtde.dropComplete(true)
212+
} else {
213+
dtde.dropComplete(false)
206214
}
207-
dtde.dropComplete(true)
208215
} catch (e: Exception) {
209-
e.printStackTrace()
216+
LOG.error("Failed to handle file drop operation", e.message)
210217
dtde.dropComplete(false)
211218
}
212219
}
@@ -305,6 +312,12 @@ class AmazonQPanel(val project: Project, private val scope: CoroutineScope) : Di
305312
}
306313
}
307314

315+
companion object {
316+
private val LOG = getLogger<AmazonQPanel>()
317+
318+
fun getInstance(project: Project) = project.service<AmazonQPanel>()
319+
}
320+
308321
override fun dispose() {
309322
}
310323
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class Browser(parent: Disposable, private val webUri: URI, val project: Project)
125125
<script type="text/javascript" charset="UTF-8" src="$webUri" defer onload="init()"></script>
126126
127127
<script type="text/javascript">
128-
let qChat = undefined
128+
129129
const init = () => {
130130
const hybridChatConnector = connectorAdapter.initiateAdapter(
131131
${MeetQSettings.getInstance().reinvent2024OnboardingCount < MAX_ONBOARDING_PAGE_COUNT},
@@ -158,7 +158,7 @@ class Browser(parent: Disposable, private val webUri: URI, val project: Project)
158158
hybridChatConnector,
159159
${CodeWhispererFeatureConfigService.getInstance().getFeatureConfigJsonString()}
160160
);
161-
window.qChat = qChat;
161+
162162
window.handleNativeDrop = function(filePath) {
163163
const parsedFilePath = JSON.parse(filePath);
164164
const contextArray = parsedFilePath.map(fileObj => {

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/ExtendedClientMetadata.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ data class DeveloperProfiles(
2525
val developerProfiles: Boolean,
2626
val mcp: Boolean,
2727
val pinnedContextEnabled: Boolean,
28+
val imageContextEnabled: Boolean = true,
2829
)
2930

3031
data class WindowSettings(
@@ -65,6 +66,7 @@ fun createExtendedClientMetadata(project: Project): ExtendedClientMetadata {
6566
developerProfiles = true,
6667
mcp = true,
6768
pinnedContextEnabled = true,
69+
imageContextEnabled = true,
6870
),
6971
window = WindowSettings(
7072
showSaveFileDialog = true

0 commit comments

Comments
 (0)