Skip to content

Commit 5038df1

Browse files
committed
feat: Add option to disable image pasting
- Introduced a new Boolean property `allowImagePasting` in SettingManager (defaulting to true). - Updated the onPaste handler in FirstResponderTextView to only process pasted images when allowed. - Added a toggle in SettingsView for users to enable or disable image pasting.
1 parent f075b87 commit 5038df1

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

Amazon Bedrock Client for Mac.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@
649649
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
650650
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
651651
MACOSX_DEPLOYMENT_TARGET = 13.0;
652-
MARKETING_VERSION = 1.2.6;
652+
MARKETING_VERSION = 1.2.7;
653653
ONLY_ACTIVE_ARCH = YES;
654654
PRODUCT_BUNDLE_IDENTIFIER = "AWS.Amazon-Bedrock-Client-for-Mac";
655655
PRODUCT_NAME = "Amazon Bedrock Debug";
@@ -692,7 +692,7 @@
692692
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
693693
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
694694
MACOSX_DEPLOYMENT_TARGET = 13.0;
695-
MARKETING_VERSION = 1.2.6;
695+
MARKETING_VERSION = 1.2.7;
696696
PRODUCT_BUNDLE_IDENTIFIER = "AWS.Amazon-Bedrock-Client-for-Mac";
697697
PRODUCT_NAME = "Amazon Bedrock";
698698
PROVISIONING_PROFILE_SPECIFIER = "";

Amazon Bedrock Client for Mac/Managers/SettingManager.swift

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class SettingManager: ObservableObject {
4848
@Published var virtualProfile: AWSProfile?
4949
@Published var defaultModelId: String { didSet { saveSettings() } }
5050
@Published var availableModels: [ChatModel] = []
51+
@Published var allowImagePasting: Bool = true
5152

5253
private var cancellables = Set<AnyCancellable>()
5354

Amazon Bedrock Client for Mac/Views/MessageBarView.swift

+12-8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct ImageViewer: View {
2727
struct MessageBarView: View {
2828
var chatID: String
2929
@Binding var userInput: String
30+
@StateObject private var settingManager = SettingManager.shared
3031
@ObservedObject var chatManager: ChatManager = ChatManager.shared
3132
@StateObject var sharedImageDataSource: SharedImageDataSource
3233

@@ -102,14 +103,17 @@ struct MessageBarView: View {
102103
Task { await sendMessage() }
103104
} },
104105
onPaste: { image in
105-
if let compressedData = image.compressedData(maxFileSize: 1024 * 1024, format: .jpeg),
106-
let compressedImage = NSImage(data: compressedData) {
107-
sharedImageDataSource.images.append(compressedImage)
108-
sharedImageDataSource.fileExtensions.append("jpeg")
109-
} else {
110-
sharedImageDataSource.images.append(image)
111-
sharedImageDataSource.fileExtensions.append("png")
112-
}
106+
// Only process the pasted image if image pasting is allowed.
107+
if settingManager.allowImagePasting {
108+
if let compressedData = image.compressedData(maxFileSize: 1024 * 1024, format: .jpeg),
109+
let compressedImage = NSImage(data: compressedData) {
110+
sharedImageDataSource.images.append(compressedImage)
111+
sharedImageDataSource.fileExtensions.append("jpeg")
112+
} else {
113+
sharedImageDataSource.images.append(image)
114+
sharedImageDataSource.fileExtensions.append("png")
115+
}
116+
}
113117
}
114118
)
115119
.frame(minHeight: 40, maxHeight: calculatedHeight)

Amazon Bedrock Client for Mac/Views/SettingsView.swift

+1
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ struct AdvancedSettingsView: View {
268268
.textFieldStyle(RoundedBorderTextFieldStyle())
269269
.frame(maxWidth: 400)
270270

271+
Toggle("Allow Image Pasting", isOn: $settingsManager.allowImagePasting)
271272
Toggle("Enable Logging", isOn: $settingsManager.enableDebugLog)
272273
}
273274
.padding(.top, 10)

0 commit comments

Comments
 (0)