Skip to content

Commit

Permalink
feat: Add option to disable image pasting
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
didhd committed Feb 17, 2025
1 parent f075b87 commit 5038df1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Amazon Bedrock Client for Mac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.2.6;
MARKETING_VERSION = 1.2.7;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "AWS.Amazon-Bedrock-Client-for-Mac";
PRODUCT_NAME = "Amazon Bedrock Debug";
Expand Down Expand Up @@ -692,7 +692,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.2.6;
MARKETING_VERSION = 1.2.7;
PRODUCT_BUNDLE_IDENTIFIER = "AWS.Amazon-Bedrock-Client-for-Mac";
PRODUCT_NAME = "Amazon Bedrock";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class SettingManager: ObservableObject {
@Published var virtualProfile: AWSProfile?
@Published var defaultModelId: String { didSet { saveSettings() } }
@Published var availableModels: [ChatModel] = []
@Published var allowImagePasting: Bool = true

private var cancellables = Set<AnyCancellable>()

Expand Down
20 changes: 12 additions & 8 deletions Amazon Bedrock Client for Mac/Views/MessageBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct ImageViewer: View {
struct MessageBarView: View {
var chatID: String
@Binding var userInput: String
@StateObject private var settingManager = SettingManager.shared
@ObservedObject var chatManager: ChatManager = ChatManager.shared
@StateObject var sharedImageDataSource: SharedImageDataSource

Expand Down Expand Up @@ -102,14 +103,17 @@ struct MessageBarView: View {
Task { await sendMessage() }
} },
onPaste: { image in
if let compressedData = image.compressedData(maxFileSize: 1024 * 1024, format: .jpeg),
let compressedImage = NSImage(data: compressedData) {
sharedImageDataSource.images.append(compressedImage)
sharedImageDataSource.fileExtensions.append("jpeg")
} else {
sharedImageDataSource.images.append(image)
sharedImageDataSource.fileExtensions.append("png")
}
// Only process the pasted image if image pasting is allowed.
if settingManager.allowImagePasting {
if let compressedData = image.compressedData(maxFileSize: 1024 * 1024, format: .jpeg),
let compressedImage = NSImage(data: compressedData) {
sharedImageDataSource.images.append(compressedImage)
sharedImageDataSource.fileExtensions.append("jpeg")
} else {
sharedImageDataSource.images.append(image)
sharedImageDataSource.fileExtensions.append("png")
}
}
}
)
.frame(minHeight: 40, maxHeight: calculatedHeight)
Expand Down
1 change: 1 addition & 0 deletions Amazon Bedrock Client for Mac/Views/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ struct AdvancedSettingsView: View {
.textFieldStyle(RoundedBorderTextFieldStyle())
.frame(maxWidth: 400)

Toggle("Allow Image Pasting", isOn: $settingsManager.allowImagePasting)
Toggle("Enable Logging", isOn: $settingsManager.enableDebugLog)
}
.padding(.top, 10)
Expand Down

0 comments on commit 5038df1

Please sign in to comment.