mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-19 21:06:10 +00:00
iOS: Add ability to save photos to gallery
This commit is contained in:
1 parent
5e62f3e107
commit
394aaa8093
11 files changed
+3038
-22
No files matched your search
@@ -50,19 +50,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
deletePartiallyReceivedFiles()
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.delegate?.connectionWasTerminated(connection: self, error: self.lastError)
|
||||
|
||||
if !self.downloadedFiles.isEmpty {
|
||||
|
||||
#if os(macOS)
|
||||
if Settings.shared.openFinderAfterReceiving {
|
||||
log("[SaveFilesManager] Opening \(self.downloadedFiles.count) file(s) in Finder.")
|
||||
NSWorkspace.shared.activateFileViewerSelecting(self.downloadedFiles)
|
||||
}
|
||||
#else
|
||||
FileManager.default.openDocumentFolder()
|
||||
#endif
|
||||
}
|
||||
self.delegate?.connectionWasTerminated(connection: self, savedFiles: self.downloadedFiles, error: self.lastError)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
|
||||
}
|
||||
|
||||
|
||||
func connectionWasTerminated(connection: InboundNearbyConnection, error: Error?) {
|
||||
func connectionWasTerminated(connection: InboundNearbyConnection, savedFiles: [URL], error: Error?) {
|
||||
incomingConnections.removeValue(forKey: connection.id)
|
||||
|
||||
// If there are no more incoming connections, we can stop accessing the save directory
|
||||
@@ -238,7 +238,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
|
||||
|
||||
if !connection.wasUserRejected {
|
||||
inboundAppDelegates.forEach { delegate in
|
||||
delegate.connectionWasTerminated(connectionID: connection.id, from: connection.remoteDeviceInfo ?? RemoteDeviceInfo(name: "UnknownDevice".localized(), type: .unknown), wasPlainTextTransfer: connection.isPlainTextTransfer, error: error)
|
||||
delegate.connectionWasTerminated(connectionID: connection.id, from: connection.remoteDeviceInfo ?? RemoteDeviceInfo(name: "UnknownDevice".localized(), type: .unknown), savedFiles: savedFiles, wasPlainTextTransfer: connection.isPlainTextTransfer, error: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ protocol InboundNearbyConnectionDelegate {
|
||||
func obtainUserConsent(transfer: TransferMetadata, device: RemoteDeviceInfo, connection: InboundNearbyConnection)
|
||||
func obtainedUserConsentAutomatically(transfer: TransferMetadata, device: RemoteDeviceInfo, connection: InboundNearbyConnection)
|
||||
func updatedTransferProgress(connection: InboundNearbyConnection, progress: Double)
|
||||
func connectionWasTerminated(connection: InboundNearbyConnection, error: Error?)
|
||||
func connectionWasTerminated(connection: InboundNearbyConnection, savedFiles: [URL], error: Error?)
|
||||
func showPlusScreen()
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ protocol OutboundNearbyConnectionDelegate {
|
||||
public protocol InboundAppDelegate: AnyObject {
|
||||
func obtainUserConsent(transfer: TransferMetadata, device: RemoteDeviceInfo)
|
||||
func obtainedUserConsentAutomatically(transfer: TransferMetadata, device: RemoteDeviceInfo)
|
||||
func connectionWasTerminated(connectionID: String, from device: RemoteDeviceInfo, wasPlainTextTransfer: Bool, error: Error?)
|
||||
func connectionWasTerminated(connectionID: String, from device: RemoteDeviceInfo, savedFiles: [URL], wasPlainTextTransfer: Bool, error: Error?)
|
||||
func transferProgress(connectionID: String, progress: Double)
|
||||
func showPlusScreen()
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ struct EXIFUtils {
|
||||
|
||||
|
||||
/// Returns the EXIF original date of an image file, adjusted to the current time zone.
|
||||
private static func exifOriginalDate(from url: URL) -> Date? {
|
||||
static func exifOriginalDate(from url: URL) -> Date? {
|
||||
guard let imageSource = CGImageSourceCreateWithURL(url as CFURL, nil),
|
||||
let properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? [CFString: Any],
|
||||
let exif = properties[kCGImagePropertyExifDictionary] as? [CFString: Any],
|
||||
@@ -56,10 +56,34 @@ struct EXIFUtils {
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
let offsetString = exif[kCGImagePropertyExifOffsetTimeOriginal] as? String
|
||||
|
||||
let formatter = DateFormatter()
|
||||
formatter.locale = Locale(identifier: "en_US_POSIX")
|
||||
formatter.calendar = Calendar(identifier: .gregorian)
|
||||
formatter.dateFormat = "yyyy:MM:dd HH:mm:ss"
|
||||
formatter.timeZone = TimeZone.current // Use the current device time zone
|
||||
|
||||
let offsetSeconds = offsetString.flatMap(secondsFromOffsetString)
|
||||
if let seconds = offsetSeconds {
|
||||
formatter.timeZone = TimeZone(secondsFromGMT: seconds)
|
||||
} else {
|
||||
// Fallback: treat as device local
|
||||
formatter.timeZone = TimeZone.current
|
||||
}
|
||||
|
||||
return formatter.date(from: dateString)
|
||||
}
|
||||
|
||||
|
||||
static private func secondsFromOffsetString(_ s: String) -> Int? {
|
||||
// Expect formats like "+02:00" or "-05:30"
|
||||
guard s.count == 6, (s.first == "+" || s.first == "-") else { return nil }
|
||||
let sign = s.first == "-" ? -1 : 1
|
||||
let parts = s.dropFirst().split(separator: ":")
|
||||
guard parts.count == 2,
|
||||
let hours = Int(parts[0]),
|
||||
let minutes = Int(parts[1]) else { return nil }
|
||||
return sign * (hours * 3600 + minutes * 60)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user