mirror of
https://github.com/grishka/NearDrop.git
synced 2026-04-03 01:36:15 +02:00
Allow receiving text into .txt files
closes #166, closes #147, closes #112, closes #178, closes #123, closes #110
This commit is contained in:
@@ -839,7 +839,7 @@
|
|||||||
CODE_SIGN_ENTITLEMENTS = NearDrop/NearDrop.entitlements;
|
CODE_SIGN_ENTITLEMENTS = NearDrop/NearDrop.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 8;
|
CURRENT_PROJECT_VERSION = 9;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
|
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
|
||||||
INFOPLIST_KEY_LSUIElement = YES;
|
INFOPLIST_KEY_LSUIElement = YES;
|
||||||
@@ -851,7 +851,7 @@
|
|||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.15;
|
MACOSX_DEPLOYMENT_TARGET = 10.15;
|
||||||
MARKETING_VERSION = 2.0.4;
|
MARKETING_VERSION = 2.1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = me.grishka.NearDrop;
|
PRODUCT_BUNDLE_IDENTIFIER = me.grishka.NearDrop;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
@@ -871,7 +871,7 @@
|
|||||||
CODE_SIGN_ENTITLEMENTS = NearDrop/NearDrop.entitlements;
|
CODE_SIGN_ENTITLEMENTS = NearDrop/NearDrop.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 8;
|
CURRENT_PROJECT_VERSION = 9;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
|
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
|
||||||
INFOPLIST_KEY_LSUIElement = YES;
|
INFOPLIST_KEY_LSUIElement = YES;
|
||||||
@@ -883,7 +883,7 @@
|
|||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.15;
|
MACOSX_DEPLOYMENT_TARGET = 10.15;
|
||||||
MARKETING_VERSION = 2.0.4;
|
MARKETING_VERSION = 2.1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = me.grishka.NearDrop;
|
PRODUCT_BUNDLE_IDENTIFIER = me.grishka.NearDrop;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
|
|||||||
@@ -124,6 +124,16 @@ class InboundNearbyConnection: NearbyConnection{
|
|||||||
}
|
}
|
||||||
try sendDisconnectionAndDisconnect()
|
try sendDisconnectionAndDisconnect()
|
||||||
return true
|
return true
|
||||||
|
}else if let fileInfo=transferredFiles[id]{
|
||||||
|
fileInfo.fileHandle?.write(payload)
|
||||||
|
transferredFiles[id]!.bytesTransferred+=Int64(payload.count)
|
||||||
|
fileInfo.progress?.completedUnitCount=transferredFiles[id]!.bytesTransferred
|
||||||
|
try fileInfo.fileHandle?.close()
|
||||||
|
transferredFiles[id]!.fileHandle=nil
|
||||||
|
fileInfo.progress?.unpublish()
|
||||||
|
transferredFiles.removeValue(forKey: id)
|
||||||
|
try sendDisconnectionAndDisconnect()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -270,27 +280,32 @@ class InboundNearbyConnection: NearbyConnection{
|
|||||||
currentState = .receivedPairedKeyResult
|
currentState = .receivedPairedKeyResult
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func makeFileDestinationURL(_ initialDest:URL) -> URL{
|
||||||
|
var dest=initialDest
|
||||||
|
if FileManager.default.fileExists(atPath: dest.path){
|
||||||
|
var counter=1
|
||||||
|
var path:String
|
||||||
|
let ext=dest.pathExtension
|
||||||
|
let baseUrl=dest.deletingPathExtension()
|
||||||
|
repeat{
|
||||||
|
path="\(baseUrl.path) (\(counter))"
|
||||||
|
if !ext.isEmpty{
|
||||||
|
path+=".\(ext)"
|
||||||
|
}
|
||||||
|
counter+=1
|
||||||
|
}while FileManager.default.fileExists(atPath: path)
|
||||||
|
dest=URL(fileURLWithPath: path)
|
||||||
|
}
|
||||||
|
return dest
|
||||||
|
}
|
||||||
|
|
||||||
private func processIntroductionFrame(_ frame:Sharing_Nearby_Frame) throws{
|
private func processIntroductionFrame(_ frame:Sharing_Nearby_Frame) throws{
|
||||||
guard frame.hasV1, frame.v1.hasIntroduction else { throw NearbyError.requiredFieldMissing("shareNearbyFrame.v1.introduction") }
|
guard frame.hasV1, frame.v1.hasIntroduction else { throw NearbyError.requiredFieldMissing("shareNearbyFrame.v1.introduction") }
|
||||||
currentState = .waitingForUserConsent
|
currentState = .waitingForUserConsent
|
||||||
if frame.v1.introduction.fileMetadata.count>0 && frame.v1.introduction.textMetadata.isEmpty{
|
if frame.v1.introduction.fileMetadata.count>0 && frame.v1.introduction.textMetadata.isEmpty{
|
||||||
let downloadsDirectory=(try FileManager.default.url(for: .downloadsDirectory, in: .userDomainMask, appropriateFor: nil, create: true)).resolvingSymlinksInPath()
|
let downloadsDirectory=(try FileManager.default.url(for: .downloadsDirectory, in: .userDomainMask, appropriateFor: nil, create: true)).resolvingSymlinksInPath()
|
||||||
for file in frame.v1.introduction.fileMetadata{
|
for file in frame.v1.introduction.fileMetadata{
|
||||||
var dest=downloadsDirectory.appendingPathComponent(file.name)
|
let dest=makeFileDestinationURL(downloadsDirectory.appendingPathComponent(file.name))
|
||||||
if FileManager.default.fileExists(atPath: dest.path){
|
|
||||||
var counter=1
|
|
||||||
var path:String
|
|
||||||
let ext=dest.pathExtension
|
|
||||||
let baseUrl=dest.deletingPathExtension()
|
|
||||||
repeat{
|
|
||||||
path="\(baseUrl.path) (\(counter))"
|
|
||||||
if !ext.isEmpty{
|
|
||||||
path+=".\(ext)"
|
|
||||||
}
|
|
||||||
counter+=1
|
|
||||||
}while FileManager.default.fileExists(atPath: path)
|
|
||||||
dest=URL(fileURLWithPath: path)
|
|
||||||
}
|
|
||||||
let info=InternalFileInfo(meta: FileMetadata(name: file.name, size: file.size, mimeType: file.mimeType),
|
let info=InternalFileInfo(meta: FileMetadata(name: file.name, size: file.size, mimeType: file.mimeType),
|
||||||
payloadID: file.payloadID,
|
payloadID: file.payloadID,
|
||||||
destinationURL: dest)
|
destinationURL: dest)
|
||||||
@@ -308,6 +323,18 @@ class InboundNearbyConnection: NearbyConnection{
|
|||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.delegate?.obtainUserConsent(for: metadata, from: self.remoteDeviceInfo!, connection: self)
|
self.delegate?.obtainUserConsent(for: metadata, from: self.remoteDeviceInfo!, connection: self)
|
||||||
}
|
}
|
||||||
|
}else if case .text=meta.type{
|
||||||
|
let downloadsDirectory=(try FileManager.default.url(for: .downloadsDirectory, in: .userDomainMask, appropriateFor: nil, create: true)).resolvingSymlinksInPath()
|
||||||
|
let dateFormatter=DateFormatter()
|
||||||
|
dateFormatter.dateFormat="yyyy-MM-dd HH.mm.ss"
|
||||||
|
let dest=makeFileDestinationURL(downloadsDirectory.appendingPathComponent("\(dateFormatter.string(from: Date())).txt"))
|
||||||
|
let info=InternalFileInfo(meta: FileMetadata(name: dest.lastPathComponent, size: meta.size, mimeType: "text/plain"),
|
||||||
|
payloadID: meta.payloadID,
|
||||||
|
destinationURL: dest)
|
||||||
|
transferredFiles[meta.payloadID]=info
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.delegate?.obtainUserConsent(for: TransferMetadata(files: [info.meta], id: self.id, pinCode: self.pinCode), from: self.remoteDeviceInfo!, connection: self)
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
rejectTransfer(with: .unsupportedAttachmentType)
|
rejectTransfer(with: .unsupportedAttachmentType)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user