Skip to content

Linux + iPhone Continuity / iMessage / SMS

send photo

Zack Bartel5e2b7c578cd4
diff --git a/apple/Info.plist b/apple/Info.plist
index 454970f..9b99c1e 100644
--- a/apple/Info.plist
+++ b/apple/Info.plist
@@ -10,6 +10,8 @@
</array>
<key>NSLocalNetworkUsageDescription</key>
<string>Used to discover and connect to Tether services on your local network.</string>
+ <key>NSPhotoLibraryUsageDescription</key>
+ <string>Used to send photos from your library to your desktop.</string>
<key>UIFileSharingEnabled</key>
<true/>
</dict>
diff --git a/apple/Tether/ViewModels/TetherViewModel.swift b/apple/Tether/ViewModels/TetherViewModel.swift
index 45743de..8c0e454 100644
--- a/apple/Tether/ViewModels/TetherViewModel.swift
+++ b/apple/Tether/ViewModels/TetherViewModel.swift
@@ -261,24 +261,35 @@ final class TetherViewModel {
// MARK: - File Transfer
- /// Send a file to the daemon.
+ /// Send a file to the daemon using its URL.
func sendFile(url: URL) {
- guard url.startAccessingSecurityScopedResource() else {
- errorMessage = "Cannot access file."
- return
- }
-
- let transferId = UUID().uuidString
+ let isSecurityScoped = url.startAccessingSecurityScopedResource()
let filename = url.lastPathComponent
Task.detached { [weak self] in
guard let self else { return }
- defer { url.stopAccessingSecurityScopedResource() }
+ defer { if isSecurityScoped { url.stopAccessingSecurityScopedResource() } }
do {
let fileData = try Data(contentsOf: url)
- let totalSize = Int64(fileData.count)
+ self.sendFile(data: fileData, filename: filename)
+ } catch {
+ await MainActor.run {
+ self.errorMessage = "File transfer failed: \(error.localizedDescription)"
+ }
+ }
+ }
+ }
+ /// Send raw data to the daemon.
+ func sendFile(data fileData: Data, filename: String) {
+ let transferId = UUID().uuidString
+ let totalSize = Int64(fileData.count)
+
+ Task.detached { [weak self] in
+ guard let self else { return }
+
+ do {
await MainActor.run {
let transfer = FileTransfer(
id: transferId,
@@ -334,7 +345,7 @@ final class TetherViewModel {
if let idx = self.activeTransfers.firstIndex(where: { $0.id == transferId }) {
self.activeTransfers[idx].failed = true
}
- self.errorMessage = "File transfer failed: \(error.localizedDescription)"
+ self.errorMessage = "File transfer error from daemon: \(error.localizedDescription)"
}
}
}
diff --git a/apple/Tether/Views/FilesView.swift b/apple/Tether/Views/FilesView.swift
index aed8b10..43ec590 100644
--- a/apple/Tether/Views/FilesView.swift
+++ b/apple/Tether/Views/FilesView.swift
@@ -7,12 +7,14 @@
import SwiftUI
import UniformTypeIdentifiers
+import PhotosUI
struct FilesView: View {
@Environment(TetherViewModel.self) private var viewModel
@Environment(\.openURL) private var openURL
@State private var showDocumentPicker = false
+ @State private var selectedPhotoItem: PhotosPickerItem? = nil
var body: some View {
NavigationStack {
@@ -28,11 +30,17 @@ struct FilesView: View {
.toolbar {
if viewModel.appState == .connected {
ToolbarItem(placement: .topBarTrailing) {
- Button {
- showDocumentPicker = true
- } label: {
- Image(systemName: "plus.circle.fill")
- .foregroundStyle(.teal)
+ HStack(spacing: 16) {
+ PhotosPicker(selection: $selectedPhotoItem, matching: .images) {
+ Image(systemName: "photo.on.rectangle")
+ .foregroundStyle(.teal)
+ }
+ Button {
+ showDocumentPicker = true
+ } label: {
+ Image(systemName: "plus.circle.fill")
+ .foregroundStyle(.teal)
+ }
}
}
}
@@ -51,6 +59,19 @@ struct FilesView: View {
viewModel.errorMessage = "File selection failed: \(error.localizedDescription)"
}
}
+ .onChange(of: selectedPhotoItem) { _, newItem in
+ guard let newItem else { return }
+
+ Task {
+ if let data = try? await newItem.loadTransferable(type: Data.self) {
+ let defaultName = "Image_\(UUID().uuidString.prefix(6)).jpg"
+ viewModel.sendFile(data: data, filename: defaultName)
+ } else {
+ viewModel.errorMessage = "Could not read photo data."
+ }
+ selectedPhotoItem = nil
+ }
+ }
}
}
@@ -78,47 +99,90 @@ struct FilesView: View {
private var connectedView: some View {
ScrollView {
VStack(spacing: 20) {
- // Send File Button
- Button {
- showDocumentPicker = true
- } label: {
- HStack(spacing: 14) {
- ZStack {
- Circle()
- .fill(
- LinearGradient(
- colors: [.teal, .teal.opacity(0.7)],
- startPoint: .topLeading,
- endPoint: .bottomTrailing
+ // Send Actions
+ VStack(spacing: 12) {
+ // Send File Button
+ Button {
+ showDocumentPicker = true
+ } label: {
+ HStack(spacing: 14) {
+ ZStack {
+ Circle()
+ .fill(
+ LinearGradient(
+ colors: [.teal, .teal.opacity(0.7)],
+ startPoint: .topLeading,
+ endPoint: .bottomTrailing
+ )
)
- )
- .frame(width: 48, height: 48)
+ .frame(width: 48, height: 48)
- Image(systemName: "arrow.up.doc.fill")
- .font(.title3)
- .foregroundStyle(.white)
- }
+ Image(systemName: "arrow.up.doc.fill")
+ .font(.title3)
+ .foregroundStyle(.white)
+ }
- VStack(alignment: .leading, spacing: 2) {
- Text("Send a File")
- .font(.body.weight(.semibold))
- .foregroundStyle(.primary)
+ VStack(alignment: .leading, spacing: 2) {
+ Text("Send a File")
+ .font(.body.weight(.semibold))
+ .foregroundStyle(.primary)
- Text("Transfer to your Linux desktop")
+ Text("Transfer documents & archives")
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ }
+
+ Spacer()
+
+ Image(systemName: "chevron.right")
.font(.caption)
- .foregroundStyle(.secondary)
+ .foregroundStyle(.tertiary)
}
+ .padding(16)
+ .background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: 16))
+ }
+ .buttonStyle(.plain)
+
+ // Send Photo Button
+ PhotosPicker(selection: $selectedPhotoItem, matching: .images, photoLibrary: .shared()) {
+ HStack(spacing: 14) {
+ ZStack {
+ Circle()
+ .fill(
+ LinearGradient(
+ colors: [.indigo, .indigo.opacity(0.7)],
+ startPoint: .topLeading,
+ endPoint: .bottomTrailing
+ )
+ )
+ .frame(width: 48, height: 48)
- Spacer()
+ Image(systemName: "photo.fill")
+ .font(.title3)
+ .foregroundStyle(.white)
+ }
- Image(systemName: "chevron.right")
- .font(.caption)
- .foregroundStyle(.tertiary)
+ VStack(alignment: .leading, spacing: 2) {
+ Text("Send a Photo")
+ .font(.body.weight(.semibold))
+ .foregroundStyle(.primary)
+
+ Text("Transfer from photo library")
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ }
+
+ Spacer()
+
+ Image(systemName: "chevron.right")
+ .font(.caption)
+ .foregroundStyle(.tertiary)
+ }
+ .padding(16)
+ .background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: 16))
}
- .padding(16)
- .background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: 16))
+ .buttonStyle(.plain)
}
- .buttonStyle(.plain)
// Active Transfers
if !viewModel.activeTransfers.isEmpty {