From 387b0284b21b8b6556854c3a6471ea7ac5e0a9fb Mon Sep 17 00:00:00 2001 From: Vishal Telangre Date: Thu, 10 Nov 2016 00:23:13 +0530 Subject: [PATCH] Animate menu bar icon while recording --- .../Contents.json | 2 +- .../stop.png => stop-1.imageset/stop-1.png} | Bin .../stop-2.imageset/Contents.json | 20 +++++++++++ .../stop-2.imageset/stop-2.png | Bin 0 -> 1267 bytes Kyapchar/Info.plist | 2 +- Kyapchar/MenuController.swift | 33 ++++++++++++++++-- 6 files changed, 52 insertions(+), 5 deletions(-) rename Kyapchar/Assets.xcassets/{stop.imageset => stop-1.imageset}/Contents.json (88%) rename Kyapchar/Assets.xcassets/{stop.imageset/stop.png => stop-1.imageset/stop-1.png} (100%) create mode 100644 Kyapchar/Assets.xcassets/stop-2.imageset/Contents.json create mode 100644 Kyapchar/Assets.xcassets/stop-2.imageset/stop-2.png diff --git a/Kyapchar/Assets.xcassets/stop.imageset/Contents.json b/Kyapchar/Assets.xcassets/stop-1.imageset/Contents.json similarity index 88% rename from Kyapchar/Assets.xcassets/stop.imageset/Contents.json rename to Kyapchar/Assets.xcassets/stop-1.imageset/Contents.json index 76814df..14bd0bc 100644 --- a/Kyapchar/Assets.xcassets/stop.imageset/Contents.json +++ b/Kyapchar/Assets.xcassets/stop-1.imageset/Contents.json @@ -6,7 +6,7 @@ }, { "idiom" : "mac", - "filename" : "stop.png", + "filename" : "stop-1.png", "scale" : "2x" } ], diff --git a/Kyapchar/Assets.xcassets/stop.imageset/stop.png b/Kyapchar/Assets.xcassets/stop-1.imageset/stop-1.png similarity index 100% rename from Kyapchar/Assets.xcassets/stop.imageset/stop.png rename to Kyapchar/Assets.xcassets/stop-1.imageset/stop-1.png diff --git a/Kyapchar/Assets.xcassets/stop-2.imageset/Contents.json b/Kyapchar/Assets.xcassets/stop-2.imageset/Contents.json new file mode 100644 index 0000000..2cd8811 --- /dev/null +++ b/Kyapchar/Assets.xcassets/stop-2.imageset/Contents.json @@ -0,0 +1,20 @@ +{ + "images" : [ + { + "idiom" : "mac", + "scale" : "1x" + }, + { + "idiom" : "mac", + "filename" : "stop-2.png", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + }, + "properties" : { + "template-rendering-intent" : "template" + } +} \ No newline at end of file diff --git a/Kyapchar/Assets.xcassets/stop-2.imageset/stop-2.png b/Kyapchar/Assets.xcassets/stop-2.imageset/stop-2.png new file mode 100644 index 0000000000000000000000000000000000000000..43ace7ec22a5b68414e313fe4646594607d50c6a GIT binary patch literal 1267 zcmVYx8t;0+o8UN(j~=$8=8C?z=LhT9L0~Cf1q>}(!I6QLN50M_yRzC-h2wcsB-fn z085RR19({-%?a&jT)G6{EP%{*N8(yn3SdO-U{n1r12_kuvIq}Ws32T1xz zdW#5PeN9)M5xtM{!fAJ5AP~^O4Llwh+PC>eG;YNl$p(_|B@&6nfq?C~jImgZ$z+nIY5u4O8_CaS zW@dQt;zcU@co%7`|F2M4q05aFFUnj|44ZN(#YML)s zYU!BM{%eWy;H`c_2FDDWx~`Mn4Or~y+Q z#jmQ6xhY>~Se8|;fIXIF0l=(Y>2xVc0Fbq{ zHHk)}Im@ze;lhQLva+%U5&4;(B0mv!2#tQ&$40LsM0RWT9B&w^c&x^=? zl23_l0OW?002fJ5ga>q44s{wNTpIAkbGqy!QFs-MvI4(QB_s7?7Ha4 zks~xs(=$0anTtlF&s&!DHOYe_LXrpe0IJI`X=8Vd^73-aaU1~P!-o&$(4j+96B858 z<;$0I@p$~jbUOWwI))9B2lwCs_uT8Xu{*GB`(|rvt6qqjNxpyU)~&7Tn9JpcwIcNF z9(Mn)LgWPipU(#X%;j>JpPvr}gTW6;)+G{&#>U1*yRx$KHIf4&(jp?iko1Yj<__S@ z>$I`}nze4}I{-=8wmp3O_;CW*=`9Vm78Vvh z>+kPpb91u;fc5qD5d{j(DMkQC@%83+V60WcH_MIJNtif_qC zdS+*5{i^%%S5#Dt0H6vo*3{JWMIw>sTy3+nv;J^6ynjvUlWxoZR}YgX@-%zmkJFuA dtpEA*{4a&4twKd3VZQ(X002ovPDHLkV1nXCNsRyi literal 0 HcmV?d00001 diff --git a/Kyapchar/Info.plist b/Kyapchar/Info.plist index b47c35a..60c8f8c 100644 --- a/Kyapchar/Info.plist +++ b/Kyapchar/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.0.3 + 0.0.4 CFBundleSignature ???? CFBundleVersion diff --git a/Kyapchar/MenuController.swift b/Kyapchar/MenuController.swift index f5afa6e..b823eb4 100644 --- a/Kyapchar/MenuController.swift +++ b/Kyapchar/MenuController.swift @@ -18,6 +18,9 @@ class MenuController: NSObject { var recorder: Recorder! + var menubarIconAnimationTimer: NSTimer? + var menubarIconCurrentIndex = 0 + @IBAction func onRecordStopItemClick(sender: NSMenuItem) { if recorder.recording { recorder.stop() @@ -49,14 +52,32 @@ class MenuController: NSObject { recorder = Recorder(delegate: self) } + func animateMenubarIcon() { + menubarIconAnimationTimer = NSTimer.scheduledTimerWithTimeInterval(1/2, target: self, selector: #selector(MenuController.changeMenubarIcon), userInfo: nil, repeats: true) + } + + func stopMenubarIconAnimation() { + menubarIconAnimationTimer?.invalidate() + } + + func changeMenubarIcon() { + statusItem.button?.image = NSImage(named: NSString(format: "stop-%d", (menubarIconCurrentIndex + 1)) as String) + + menubarIconCurrentIndex += 1 + + if menubarIconCurrentIndex > 1 { + menubarIconCurrentIndex = 0 + } + } + } extension MenuController: RecorderDelegate { func recordingDidStart(recordingInfo: RecordingInfo?) { recordStopItem.title = "Stop" - statusItem.button?.image = NSImage(named: "stop") - + animateMenubarIcon() + pauseResumeItem.enabled = true pauseResumeItem.title = "Pause" } @@ -64,6 +85,9 @@ extension MenuController: RecorderDelegate { func recordingDidStop(recordingInfo: RecordingInfo?) { recordStopItem.enabled = true recordStopItem.title = "Record" + + stopMenubarIconAnimation() + statusItem.button?.image = NSImage(named: "record") pauseResumeItem.enabled = false @@ -79,11 +103,14 @@ extension MenuController: RecorderDelegate { func recordingDidResume(recordingInfo: RecordingInfo?) { pauseResumeItem.title = "Pause" - statusItem.button?.image = NSImage(named: "stop") + animateMenubarIcon() } func recordingDidPause(recordingInfo: RecordingInfo?) { pauseResumeItem.title = "Resume" + + stopMenubarIconAnimation() + statusItem.button?.image = NSImage(named: "pause") }