Skip to content
Snippets Groups Projects
Commit 480872ed authored by Spotlight's avatar Spotlight
Browse files

Fix duplication error

parent 18b979e3
No related branches found
No related tags found
No related merge requests found
......@@ -27,31 +27,41 @@ class UploadManager : NSObject {
#endif
} else {
defaults.set(true, forKey: uploadingKey)
// This could probably be done better
// oh well lol
sleep(2)
let fileManager = FileManager.default
do {
// Grab contents by predicate, convert to array, loop through array with paths
let allFiles = try fileManager.contentsOfDirectory(atPath: path)
let screenshotPredicate = NSPredicate(format: "self BEGINSWITH 'Screen Shot'")
let screenshotFiles = (allFiles as NSArray).filtered(using: screenshotPredicate)
let toUpload: [String] = screenshotFiles.flatMap({ $0 as? String })
for fileName in toUpload {
let toSeach: [String] = (allFiles as NSArray).flatMap({ $0 as? String })
var toUpload: [URL] = []
for fileName in toSeach {
let filePath = NSURL(fileURLWithPath:path).appendingPathComponent(fileName)!
let metadata : NSMetadataItem? = NSMetadataItem.init(url: filePath)
if (metadata == nil) {
// This file is no friend of mine.
return
}
// Check if tagged as screenshot
let isScreenshot : Int = metadata?.value(forAttribute: "kMDItemIsScreenCapture") as! Int? ?? 0
if (isScreenshot == 1) {
switchForProvider(path: filePath.path, type: type, shouldDelete: true)
// This file is no friend of mine
print("That probably shouldn't have happened. File: \(filePath)")
} else {
// Check if tagged as screenshot
let test : Bool = metadata?.value(forAttribute: "kMDItemIsScreenCapture") as! Bool? ?? false
if (test) {
toUpload.append(filePath)
print(toUpload)
}
}
}
print("\(toUpload) topkek")
for screenshot in toUpload {
switchForProvider(path: screenshot.path, type: type, shouldDelete: true)
}
defaults.set(false, forKey: uploadingKey)
} catch let error as NSError {
print("Ooops! Something went wrong: \(error.localizedDescription)")
showFailureNotification(errorText: error.localizedDescription)
defaults.set(false, forKey: uploadingKey)
}
defaults.set(false, forKey: uploadingKey)
}
} else {
switchForProvider(path: path, type: type, shouldDelete: false)
......@@ -62,19 +72,21 @@ class UploadManager : NSObject {
switch (type) {
case .GoogleCloudPlatform:
GCPAuthHandler().uploadFile(path: path) { (error, url) in
self.finishUp(path: path, possibleError: error, shouldDelete: shouldDelete, url: url)
self.finishUp(path: path, possibleError: error, shouldDelete: shouldDelete, url: url) {}
}
break
case .Pomf:
PomfManager().uploadFile(path: path) { (error, url) in
self.finishUp(path: path, possibleError: error, shouldDelete: shouldDelete, url: url)
self.finishUp(path: path, possibleError: error, shouldDelete: shouldDelete, url: url) {}
}
break
}
}
func finishUp(path: String, possibleError: NSError?, shouldDelete: Bool, url: String) {
func finishUp(path: String, possibleError: NSError?, shouldDelete: Bool, url: String, handler: () -> Void) {
if (possibleError != nil) {
showFailureNotification(errorText: (possibleError?.localizedDescription)!)
handler()
} else {
NSPasteboard.general().clearContents()
NSPasteboard.general().setString(url, forType: NSPasteboardTypeString)
......@@ -96,6 +108,7 @@ class UploadManager : NSObject {
notification.soundName = NSUserNotificationDefaultSoundName
NSUserNotificationCenter.default.deliver(notification)
handler()
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment