Gracefully disable mac attachment pickers in sandbox

This commit is contained in:
jack
2025-10-14 22:21:17 +02:00
parent f7859f7b04
commit b619c4259d
+13 -26
View File
@@ -75,6 +75,9 @@ struct ContentView: View {
@State private var selectedPhotoPickerItem: PhotosPickerItem? @State private var selectedPhotoPickerItem: PhotosPickerItem?
#endif #endif
@State private var showAttachmentActions = false @State private var showAttachmentActions = false
#if os(macOS)
@State private var showAttachmentUnavailableAlert = false
#endif
@ScaledMetric(relativeTo: .body) private var headerHeight: CGFloat = 44 @ScaledMetric(relativeTo: .body) private var headerHeight: CGFloat = 44
@ScaledMetric(relativeTo: .subheadline) private var headerPeerIconSize: CGFloat = 11 @ScaledMetric(relativeTo: .subheadline) private var headerPeerIconSize: CGFloat = 11
@ScaledMetric(relativeTo: .subheadline) private var headerPeerCountFontSize: CGFloat = 12 @ScaledMetric(relativeTo: .subheadline) private var headerPeerCountFontSize: CGFloat = 12
@@ -205,13 +208,12 @@ struct ContentView: View {
Task { await handlePhotoSelection(item) } Task { await handlePhotoSelection(item) }
} }
#else #else
.fileImporter(isPresented: $showImageImporter, allowedContentTypes: [.image], allowsMultipleSelection: false) { result in .alert("Attachments Unavailable", isPresented: $showAttachmentUnavailableAlert, actions: {
handleImportResult(result, handler: handleImportedImage) Button("OK", role: .cancel) {}
} }, message: {
Text("File and photo pickers require additional entitlements on macOS preview builds.")
})
#endif #endif
.fileImporter(isPresented: $showFileImporter, allowedContentTypes: [.data], allowsMultipleSelection: false) { result in
handleImportResult(result, handler: handleImportedFile)
}
.sheet(isPresented: Binding( .sheet(isPresented: Binding(
get: { imagePreviewURL != nil }, get: { imagePreviewURL != nil },
set: { presenting in if !presenting { imagePreviewURL = nil } } set: { presenting in if !presenting { imagePreviewURL = nil } }
@@ -229,12 +231,16 @@ struct ContentView: View {
#else #else
Button("Image") { Button("Image") {
showAttachmentActions = false showAttachmentActions = false
DispatchQueue.main.async { showImageImporter = true } showAttachmentUnavailableAlert = true
} }
#endif #endif
Button("File") { Button("File") {
showAttachmentActions = false showAttachmentActions = false
#if os(iOS)
DispatchQueue.main.async { showFileImporter = true } DispatchQueue.main.async { showFileImporter = true }
#else
showAttachmentUnavailableAlert = true
#endif
} }
Button("Cancel", role: .cancel) {} Button("Cancel", role: .cancel) {}
} }
@@ -1846,24 +1852,6 @@ private extension ContentView {
} }
var attachmentButton: some View { var attachmentButton: some View {
#if os(macOS)
Menu {
Button("Image") {
showImageImporter = false
DispatchQueue.main.async { showImageImporter = true }
}
Button("File") {
showFileImporter = false
DispatchQueue.main.async { showFileImporter = true }
}
} label: {
Image(systemName: "paperclip.circle.fill")
.font(.bitchatSystem(size: 24))
.foregroundColor(composerAccentColor)
.frame(width: 36, height: 36)
}
.menuStyle(.borderlessButton)
#else
Button(action: { showAttachmentActions = true }) { Button(action: { showAttachmentActions = true }) {
Image(systemName: "paperclip.circle.fill") Image(systemName: "paperclip.circle.fill")
.font(.bitchatSystem(size: 24)) .font(.bitchatSystem(size: 24))
@@ -1871,7 +1859,6 @@ private extension ContentView {
.frame(width: 36, height: 36) .frame(width: 36, height: 36)
} }
.buttonStyle(.plain) .buttonStyle(.plain)
#endif
} }
var sendOrMicButton: some View { var sendOrMicButton: some View {