diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ee32510 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +ScreenshotUpload.xcodeproj/xcuserdata/ diff --git a/ScreenshotUpload.xcodeproj/project.pbxproj b/ScreenshotUpload.xcodeproj/project.pbxproj index f163414..407070a 100644 --- a/ScreenshotUpload.xcodeproj/project.pbxproj +++ b/ScreenshotUpload.xcodeproj/project.pbxproj @@ -399,6 +399,7 @@ 1F80F6441956FFD600925040 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 1F80F6451956FFD600925040 /* Build configuration list for PBXNativeTarget "ScreenshotUploadTests" */ = { isa = XCConfigurationList; @@ -407,6 +408,7 @@ 1F80F6471956FFD600925040 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/ScreenshotUpload.xcodeproj/xcuserdata/jeena.xcuserdatad/xcschemes/ScreenshotUpload.xcscheme b/ScreenshotUpload.xcodeproj/xcuserdata/jeena.xcuserdatad/xcschemes/ScreenshotUpload.xcscheme deleted file mode 100644 index d2d91ae..0000000 --- a/ScreenshotUpload.xcodeproj/xcuserdata/jeena.xcuserdatad/xcschemes/ScreenshotUpload.xcscheme +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/ScreenshotUpload.xcodeproj/xcuserdata/jeena.xcuserdatad/xcschemes/xcschememanagement.plist b/ScreenshotUpload.xcodeproj/xcuserdata/jeena.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index b995a5e..0000000 --- a/ScreenshotUpload.xcodeproj/xcuserdata/jeena.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,27 +0,0 @@ - - - - - SchemeUserState - - ScreenshotUpload.xcscheme - - orderHint - 0 - - - SuppressBuildableAutocreation - - 1F80F6251956FFD500925040 - - primary - - - 1F80F6371956FFD600925040 - - primary - - - - - diff --git a/ScreenshotUpload/AppDelegate.swift b/ScreenshotUpload/AppDelegate.swift index 3fe28d3..f48e328 100644 --- a/ScreenshotUpload/AppDelegate.swift +++ b/ScreenshotUpload/AppDelegate.swift @@ -7,20 +7,119 @@ // import Cocoa +import Foundation class AppDelegate: NSObject, NSApplicationDelegate { @IBOutlet var window: NSWindow + @IBOutlet var takeScreenshotButton : NSButton func applicationDidFinishLaunching(aNotification: NSNotification?) { - // Insert code here to initialize your application + + if !self.handledURL(aNotification) { + + // Insert code here to initialize your application + let defaults = NSUserDefaults.standardUserDefaults() + let fileName = defaults.stringForKey("fileName") + let scpPath = defaults.stringForKey("scpPath") + let httpPath = defaults.stringForKey("httpPath") + + if fileName? && scpPath? && httpPath? { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { + NSOperationQueue.mainQueue().addOperationWithBlock { + self.takeScreenshot(self) + } + } + } + } } func applicationWillTerminate(aNotification: NSNotification?) { // Insert code here to tear down your application } + + func handledURL(aNotification: NSNotification?) -> Bool { + + if let urlString = aNotification?.userInfo["openUrl"] as? String { + + let url = NSURL.URLWithString(urlString) + NSWorkspace.sharedWorkspace().openURL(url) + println(url) + + NSApp.terminate(self) + + return true + } + + return false + } + @IBAction func takeScreenshot(sender : NSObject) { + + window.miniaturize(self) + NSRunningApplication.currentApplication().hide() + + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { + // do some async stuff + + let httpUrl = self.runSystemCallsAssync() + + NSOperationQueue.mainQueue().addOperationWithBlock { + // do some main thread stuff stuff + + if httpUrl? { + let notification = NSUserNotification() + notification.title = "Screenshot uploaded to" + notification.informativeText = httpUrl + notification.userInfo = ["openUrl": httpUrl] + //notification.identifier = httpUrl + notification.soundName = "NSUserNotificationDefaultSoundName" + notification.actionButtonTitle = "Open" + notification.otherButtonTitle = "" + + NSUserNotificationCenter.defaultUserNotificationCenter().deliverNotification( + notification + ) + + NSApp.terminate(self) + + } else { + self.window.orderFront(self) + } + } + } + } + + func runSystemCallsAssync() -> String! { + + let tmpName = NSTemporaryDirectory() + "nu.jabs.apps.ScreenshotUpload.png" + + systemCall("screencapture -i \(tmpName)") + + if NSFileManager.defaultManager().isReadableFileAtPath(tmpName) { + + let defaults = NSUserDefaults.standardUserDefaults() + let fileName = defaults.stringForKey("fileName") + let scpPath = defaults.stringForKey("scpPath") + let httpPath = defaults.stringForKey("httpPath") + + systemCall("scp \(tmpName) \(scpPath)\(fileName)") + systemCall("rm \(tmpName)") + + let httpUrl = "\(httpPath)\(fileName)" + systemCall("echo \(httpUrl) | pbcopy") + + return httpUrl + } + + return nil + } + + func systemCall(cmd : String) { + println(cmd) + system(cmd.bridgeToObjectiveC().UTF8String) + } } diff --git a/ScreenshotUpload/Base.lproj/MainMenu.xib b/ScreenshotUpload/Base.lproj/MainMenu.xib index 4afc4d2..d0a2a4c 100644 --- a/ScreenshotUpload/Base.lproj/MainMenu.xib +++ b/ScreenshotUpload/Base.lproj/MainMenu.xib @@ -1,7 +1,7 @@ - + - + @@ -11,8 +11,9 @@ - + + @@ -666,15 +667,104 @@ - - + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ScreenshotUpload/Images.xcassets/AppIcon.appiconset/Contents.json b/ScreenshotUpload/Images.xcassets/AppIcon.appiconset/Contents.json index 2db2b1c..348342a 100644 --- a/ScreenshotUpload/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/ScreenshotUpload/Images.xcassets/AppIcon.appiconset/Contents.json @@ -21,8 +21,9 @@ "scale" : "2x" }, { - "idiom" : "mac", "size" : "128x128", + "idiom" : "mac", + "filename" : "Screenshot-App-icon.png", "scale" : "1x" }, { diff --git a/ScreenshotUpload/Images.xcassets/AppIcon.appiconset/Screenshot-App-icon.png b/ScreenshotUpload/Images.xcassets/AppIcon.appiconset/Screenshot-App-icon.png new file mode 100644 index 0000000..6cba06e Binary files /dev/null and b/ScreenshotUpload/Images.xcassets/AppIcon.appiconset/Screenshot-App-icon.png differ diff --git a/ScreenshotUpload/Info.plist b/ScreenshotUpload/Info.plist index 286082e..d528836 100644 --- a/ScreenshotUpload/Info.plist +++ b/ScreenshotUpload/Info.plist @@ -9,7 +9,7 @@ CFBundleIconFile CFBundleIdentifier - nu.jabs.apps.ScreenshotUpload.${PRODUCT_NAME:rfc1034identifier} + nu.jabs.apps.${PRODUCT_NAME:rfc1034identifier} CFBundleInfoDictionaryVersion 6.0 CFBundleName