Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
LyricZhao committed Feb 18, 2020
1 parent 2c36091 commit c819e84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
17 changes: 9 additions & 8 deletions THU Bell/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import AVFoundation
class AppDelegate: NSObject, NSApplicationDelegate, AVAudioPlayerDelegate {

@IBOutlet weak var menu: NSMenu!
@IBOutlet weak var stopRingButton: NSMenuItem!

let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
var audioPlayer: AVAudioPlayer!
@IBOutlet weak var stopRingBt: NSMenuItem!

let thuTimeZone = TimeZone(identifier: "Asia/Hong_Kong")

Expand All @@ -26,7 +26,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, AVAudioPlayerDelegate {
var timer: Timer!
var trigger = false

// MARK: Time Table
// MARK: Time table
let times = ["08:00:00", "08:45:00", "08:50:00", "09:35:00", "09:50:00", "10:35:00", "10:40:00", "11:25:00", "11:30:00", "12:15:00", "13:30:00", "14:15:00", "14:20:00", "15:05:00", "15:20:00", "16:05:00", "16:10:00", "16:55:00", "17:05:00", "17:50:00", "17:55:00", "18:40:00", "19:20:00", "20:05:00", "20:10:00", "20:55:00", "21:00:00", "21:45:00"]

@IBOutlet var timeDisplay: NSMenuItem!
Expand Down Expand Up @@ -84,8 +84,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, AVAudioPlayerDelegate {
// Time up
@objc func setNextTime() {
if trigger {
print("Bell starts ringing.")
self.audioPlayer.play()
stopRingBt.isEnabled = true
stopRingButton.isEnabled = true
}

let formatter = DateFormatter() // Local time formatter
Expand All @@ -112,7 +113,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, AVAudioPlayerDelegate {
// Initialize time setting
func reset() {
trigger = false
stopRingBt.isEnabled = false
stopRingButton.isEnabled = false

nextDate = Date()
let formatter = DateFormatter()
Expand Down Expand Up @@ -162,18 +163,18 @@ class AppDelegate: NSObject, NSApplicationDelegate, AVAudioPlayerDelegate {
// Skip current ring
@IBAction func stopRing(_ sender: Any) {
guard audioPlayer.isPlaying else {
print("bell not ringing")
print("Bell is not ringing.")
return
}
audioPlayer.stop()
audioPlayer.currentTime = 0
stopRingBt.isEnabled = false
stopRingButton.isEnabled = false
}

// When the bell finishes playing, this function will be evoked
func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
print("bell finished")
stopRingBt.isEnabled = false
print("Bell finished.")
stopRingButton.isEnabled = false
}
}

10 changes: 5 additions & 5 deletions THU Bell/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -676,15 +676,18 @@
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="THU_Bell" customModuleProvider="target">
<connections>
<outlet property="menu" destination="Var-a1-35V" id="2YS-SV-M0t"/>
<outlet property="stopRingBt" destination="7tC-6k-vIF" id="QNe-aI-MnU"/>
<outlet property="stopRingButton" destination="7tC-6k-vIF" id="QNe-aI-MnU"/>
<outlet property="timeDisplay" destination="IcN-cY-UXW" id="NQY-9F-5HS"/>
</connections>
</customObject>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<menu id="Var-a1-35V">
<items>
<menuItem title="THU Bell v1.0.4" id="ddY-c1-DYO">
<menuItem title="THU Bell v1.0.4" enabled="NO" id="ddY-c1-DYO">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="Next Time" enabled="NO" id="IcN-cY-UXW">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="跳过本次响铃" id="7tC-6k-vIF">
Expand All @@ -693,9 +696,6 @@
<action selector="stopRing:" target="Voe-Tx-rLC" id="Yxw-eG-3zI"/>
</connections>
</menuItem>
<menuItem title="Next Time" id="IcN-cY-UXW">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="退出" id="PCG-Sk-IQa">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
Expand Down

0 comments on commit c819e84

Please sign in to comment.