Skip to content

Commit

Permalink
Animate menu bar icon while recording
Browse files Browse the repository at this point in the history
  • Loading branch information
vishaltelangre committed Nov 9, 2016
1 parent d2c23b1 commit 387b028
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
{
"idiom" : "mac",
"filename" : "stop.png",
"filename" : "stop-1.png",
"scale" : "2x"
}
],
Expand Down
20 changes: 20 additions & 0 deletions Kyapchar/Assets.xcassets/stop-2.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Kyapchar/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.0.3</string>
<string>0.0.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
33 changes: 30 additions & 3 deletions Kyapchar/MenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -49,21 +52,42 @@ 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"
}

func recordingDidStop(recordingInfo: RecordingInfo?) {
recordStopItem.enabled = true
recordStopItem.title = "Record"

stopMenubarIconAnimation()

statusItem.button?.image = NSImage(named: "record")

pauseResumeItem.enabled = false
Expand All @@ -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")
}

Expand Down

0 comments on commit 387b028

Please sign in to comment.