diff --git a/README.md b/README.md index f650fed..6ca5a62 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,18 @@ # Touchbar Nyancat Stupid Nyan Cat animation on your +$2k MacBook Pro's Touchbar. Enjoy. -[DEMO VIDEO 📼](https://www.youtube.com/watch?v=E7Or2M7XUb4) - +[Download ⬇️](https://www.dropbox.com/s/3j18z84jctsecjf/touchbar_nyancat.app.zip?dl=0) ![](http://i.imgur.com/mHYg4vE.jpeg) +## Other awesome TouchBar apps + +* [TouchFart][touchfart] - by @hungtruong +* [KnightTouchBar2000][KnightTouchBar2000] - by @AkdM + +[touchfart]: +[KnightTouchBar2000]: + diff --git a/nyan_music.mp3 b/nyan_music.mp3 deleted file mode 100644 index 5f6bee0..0000000 Binary files a/nyan_music.mp3 and /dev/null differ diff --git a/touchbar_nyancat.xcodeproj/project.pbxproj b/touchbar_nyancat.xcodeproj/project.pbxproj index 8577a7f..f48d293 100644 --- a/touchbar_nyancat.xcodeproj/project.pbxproj +++ b/touchbar_nyancat.xcodeproj/project.pbxproj @@ -15,9 +15,6 @@ A362A10D1DCE6D6B00737197 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A362A10B1DCE6D6B00737197 /* Main.storyboard */; }; A3826CDA1DCE79B900B7C41E /* NyanCatCanvas.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3826CD91DCE79B900B7C41E /* NyanCatCanvas.swift */; }; A3826CDC1DCE7B5000B7C41E /* NyanCatCanvas.xib in Resources */ = {isa = PBXBuildFile; fileRef = A3826CDB1DCE7B5000B7C41E /* NyanCatCanvas.xib */; }; - A3A050DC1DCE96BD009D9775 /* nyan_music.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = A3A050DB1DCE96BD009D9775 /* nyan_music.mp3 */; }; - A3A050E01DCE9E03009D9775 /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = A3A050DF1DCE9E03009D9775 /* icon.png */; }; - A3A050E41DCEAB08009D9775 /* nyan_long@2x.gif in Resources */ = {isa = PBXBuildFile; fileRef = A3A050E31DCEAB08009D9775 /* nyan_long@2x.gif */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -31,9 +28,6 @@ A362A10E1DCE6D6B00737197 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A3826CD91DCE79B900B7C41E /* NyanCatCanvas.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NyanCatCanvas.swift; sourceTree = ""; }; A3826CDB1DCE7B5000B7C41E /* NyanCatCanvas.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NyanCatCanvas.xib; sourceTree = ""; }; - A3A050DB1DCE96BD009D9775 /* nyan_music.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = nyan_music.mp3; sourceTree = ""; }; - A3A050DF1DCE9E03009D9775 /* icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon.png; sourceTree = ""; }; - A3A050E31DCEAB08009D9775 /* nyan_long@2x.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = "nyan_long@2x.gif"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -84,8 +78,6 @@ children = ( A34053A11DCF56600081ABF1 /* ic_volume_off_3x.png */, A34053A31DCF56640081ABF1 /* ic_volume_up_3x.png */, - A3A050E31DCEAB08009D9775 /* nyan_long@2x.gif */, - A3A050DF1DCE9E03009D9775 /* icon.png */, ); name = img; sourceTree = ""; @@ -93,7 +85,6 @@ A3A050DA1DCE96B2009D9775 /* sound */ = { isa = PBXGroup; children = ( - A3A050DB1DCE96BD009D9775 /* nyan_music.mp3 */, ); name = sound; sourceTree = ""; @@ -159,12 +150,9 @@ buildActionMask = 2147483647; files = ( A3826CDC1DCE7B5000B7C41E /* NyanCatCanvas.xib in Resources */, - A3A050E01DCE9E03009D9775 /* icon.png in Resources */, - A3A050DC1DCE96BD009D9775 /* nyan_music.mp3 in Resources */, A362A10A1DCE6D6B00737197 /* Assets.xcassets in Resources */, A362A10D1DCE6D6B00737197 /* Main.storyboard in Resources */, A34053A21DCF56600081ABF1 /* ic_volume_off_3x.png in Resources */, - A3A050E41DCEAB08009D9775 /* nyan_long@2x.gif in Resources */, A34053A41DCF56640081ABF1 /* ic_volume_up_3x.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/Contents.json b/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/Contents.json index f467f87..2db2b1c 100644 --- a/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -21,39 +21,33 @@ "scale" : "2x" }, { - "size" : "128x128", "idiom" : "mac", - "filename" : "touchbar_nyancat_icon_128@2x.png", + "size" : "128x128", "scale" : "1x" }, { - "size" : "128x128", "idiom" : "mac", - "filename" : "touchbar_nyancat_icon_256@2x-2.png", + "size" : "128x128", "scale" : "2x" }, { - "size" : "256x256", "idiom" : "mac", - "filename" : "touchbar_nyancat_icon_256@2x-1.png", + "size" : "256x256", "scale" : "1x" }, { - "size" : "256x256", "idiom" : "mac", - "filename" : "touchbar_nyancat_icon_512@2x-2.png", + "size" : "256x256", "scale" : "2x" }, { - "size" : "512x512", "idiom" : "mac", - "filename" : "touchbar_nyancat_icon_512@2x-1.png", + "size" : "512x512", "scale" : "1x" }, { - "size" : "512x512", "idiom" : "mac", - "filename" : "touchbar_nyancat_icon@2x 2.png", + "size" : "512x512", "scale" : "2x" } ], diff --git a/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon@2x 2.png b/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon@2x 2.png deleted file mode 100644 index c7c88ec..0000000 Binary files a/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon@2x 2.png and /dev/null differ diff --git a/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon_128@2x.png b/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon_128@2x.png deleted file mode 100644 index 164737a..0000000 Binary files a/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon_128@2x.png and /dev/null differ diff --git a/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon_256@2x-1.png b/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon_256@2x-1.png deleted file mode 100644 index b55ec08..0000000 Binary files a/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon_256@2x-1.png and /dev/null differ diff --git a/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon_256@2x-2.png b/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon_256@2x-2.png deleted file mode 100644 index b55ec08..0000000 Binary files a/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon_256@2x-2.png and /dev/null differ diff --git a/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon_512@2x-1.png b/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon_512@2x-1.png deleted file mode 100644 index ef7be0b..0000000 Binary files a/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon_512@2x-1.png and /dev/null differ diff --git a/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon_512@2x-2.png b/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon_512@2x-2.png deleted file mode 100644 index ef7be0b..0000000 Binary files a/touchbar_nyancat/Assets.xcassets/AppIcon.appiconset/touchbar_nyancat_icon_512@2x-2.png and /dev/null differ diff --git a/touchbar_nyancat/Base.lproj/Main.storyboard b/touchbar_nyancat/Base.lproj/Main.storyboard index 5ee59c5..de2fc2e 100644 --- a/touchbar_nyancat/Base.lproj/Main.storyboard +++ b/touchbar_nyancat/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -16,7 +16,7 @@ - + @@ -113,6 +113,7 @@ + diff --git a/touchbar_nyancat/NyanCatCanvas.swift b/touchbar_nyancat/NyanCatCanvas.swift index 785b615..d590ba7 100644 --- a/touchbar_nyancat/NyanCatCanvas.swift +++ b/touchbar_nyancat/NyanCatCanvas.swift @@ -9,17 +9,75 @@ import Cocoa class NyanCatCanvas: NSImageView { + + var imageLoaded:Bool = false; + + var xPosition: CGFloat = 0 { + didSet { + self.frame = CGRect(x: xPosition, y: 0, width: 685, height: 30) + } + } + override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. - - self.frame = CGRect(x: 0, y: 0, width: 685, height: 30) - + self.animates = true - self.image = NSImage(named: "nyan_long@2x.gif")! + + if(!self.imageLoaded){ + self.downloadImage() + } + + self.canDrawSubviewsIntoLayer = true + self.frame = CGRect(x: xPosition, y: 0, width: 685, height: 30) + } + + override func touchesBegan(with event: NSEvent) { + // Calling super causes the cat to jump back to its original position 🤔 + //super.touchesBegan(with: event) + } + + override func didAddSubview(_ subview: NSView) { + + } + + func downloadImage() { + + let url = URL(string: "https://i.imgur.com/7pgdK28.gif") + + getDataFromUrl(url: url!) { (data, response, error) in + guard let data = data, error == nil else { return } + + DispatchQueue.main.async() { () -> Void in + self.image = NSImage(data: data) + self.imageLoaded = true; + } + } + } + + func getDataFromUrl(url: URL, completion: @escaping (_ data: Data?, _ response: URLResponse?, _ error: Error?) -> Void) { + URLSession.shared.dataTask(with: url) { + (data, response, error) in + completion(data, response, error) + }.resume() + } + + + + override func touchesMoved(with event: NSEvent) { + if #available(OSX 10.12.1, *) { + let current = event.allTouches().first?.location(in: self).x ?? 0 + let previous = event.allTouches().first?.previousLocation(in: self).x ?? 0 + + let dX = (current - previous) + + xPosition += dX + } else { + // Fallback on earlier versions + } } } diff --git a/touchbar_nyancat/NyanCatViewController.swift b/touchbar_nyancat/NyanCatViewController.swift index 1700047..a2ec44c 100644 --- a/touchbar_nyancat/NyanCatViewController.swift +++ b/touchbar_nyancat/NyanCatViewController.swift @@ -15,6 +15,7 @@ class NyanCatViewController: NSViewController , NSTouchBarDelegate{ var audio_player: AVAudioPlayer? + @IBOutlet weak var muteBtn: NSButton! //NOTE: I fucking love Swift's computed properties! var sound: Bool = true { @@ -35,7 +36,6 @@ class NyanCatViewController: NSViewController , NSTouchBarDelegate{ var sound_btn_image_on: NSImage? var sound_btn_image_off: NSImage? - @IBOutlet weak var sound_btn: NSButtonCell! @IBOutlet weak var bkg: NSView! @@ -44,6 +44,7 @@ class NyanCatViewController: NSViewController , NSTouchBarDelegate{ super.viewDidLoad() self.view.wantsLayer = true + self.muteBtn.isHidden = true } @@ -62,17 +63,17 @@ class NyanCatViewController: NSViewController , NSTouchBarDelegate{ sound_btn_image_off = NSImage(named: "ic_volume_off_3x.png") - let nyan_music = URL(fileURLWithPath: Bundle.main.path(forResource: "nyan_music", ofType: "mp3")!) +// let nyan_music = URL(fileURLWithPath: Bundle.main.path(forResource: "nyan_music", ofType: "mp3")!) +// +// do { +// +// try audio_player = AVAudioPlayer(contentsOf: nyan_music) +// audio_player?.numberOfLoops = -1 +// audio_player?.prepareToPlay() +// +// }catch{} - do { - - try audio_player = AVAudioPlayer(contentsOf: nyan_music) - audio_player?.numberOfLoops = -1 - audio_player?.prepareToPlay() - - }catch{} - - sound = true + //sound = true } diff --git a/touchbar_nyancat/icon.png b/touchbar_nyancat/icon.png deleted file mode 100644 index f245683..0000000 Binary files a/touchbar_nyancat/icon.png and /dev/null differ diff --git a/touchbar_nyancat/nyan_long@2x.gif b/touchbar_nyancat/nyan_long@2x.gif deleted file mode 100644 index f66c69c..0000000 Binary files a/touchbar_nyancat/nyan_long@2x.gif and /dev/null differ diff --git a/touchbar_nyancat/nyan_music.mp3 b/touchbar_nyancat/nyan_music.mp3 deleted file mode 100644 index 5f6bee0..0000000 Binary files a/touchbar_nyancat/nyan_music.mp3 and /dev/null differ