Skip to content

Commit

Permalink
Action controls & beginning of preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Eklund committed Jul 3, 2017
1 parent 42ab8c8 commit 4c32730
Show file tree
Hide file tree
Showing 16 changed files with 207 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Release"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
6 changes: 6 additions & 0 deletions SleepWell/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
23 changes: 23 additions & 0 deletions SleepWell/Assets.xcassets/PlayButton.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "icons8-Play Filled-16.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "icons8-Play Filled-32.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "icons8-Play Filled-64.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions SleepWell/Assets.xcassets/RestartButton.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "restart16.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "restart32.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "restart64.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions SleepWell/Assets.xcassets/StopButton.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "icons8-Stop Filled-16.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "icons8-Stop Filled-32.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "icons8-Stop Filled-64.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 94 additions & 14 deletions SleepWell/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,41 @@
<outlet property="intervalStepper" destination="mSB-18-3wR" id="lRm-rs-dmX"/>
<outlet property="menubar" destination="asO-AN-rWL" id="5DE-bY-1y2"/>
<outlet property="progressbar" destination="oWT-Rs-Itp" id="uV3-Ww-TdQ"/>
<outlet property="restartButton" destination="cHv-YY-fF8" id="qEn-Eu-dT0"/>
<outlet property="startButton" destination="2Bf-ib-nyo" id="nXz-Eg-1Up"/>
<outlet property="stopButton" destination="ux3-Yg-BF3" id="xsw-3h-RHR"/>
<outlet property="timerLabel" destination="3TT-Uo-wkQ" id="c1Q-zo-2ig"/>
<outlet property="toggleButton" destination="KXm-JQ-Adn" id="1jO-aT-2Nk"/>
</connections>
</customObject>
<menu id="asO-AN-rWL" userLabel="Menubar">
<items>
<menuItem title="Timer View" id="a4c-CE-52D" userLabel="Timer View">
<menuItem title="Timer" id="a4c-CE-52D" userLabel="Timer View">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<outlet property="view" destination="WxJ-5I-PgS" id="D5I-ug-NpP"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="Lvu-RV-Xt9"/>
<menuItem title="Interval" id="eHk-Ko-JLE">
<menuItem title="Actions" id="eHk-Ko-JLE">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<outlet property="view" destination="Q3w-LZ-ipl" id="fek-ba-OLY"/>
<outlet property="view" destination="74f-2z-yDv" id="aaK-9k-YOw"/>
</connections>
</menuItem>
<menuItem title="Start" id="KXm-JQ-Adn" userLabel="Toggle Countdown">
<menuItem isSeparatorItem="YES" id="ePQ-k2-CvO"/>
<menuItem title="Interval" id="dkx-vy-gcs">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleTimer:" target="gEe-Vl-JZj" id="oOV-Wc-lB1"/>
<outlet property="view" destination="Q3w-LZ-ipl" id="z9R-rr-a1k"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="fFf-9U-cx3"/>
<menuItem isSeparatorItem="YES" id="6vs-2P-6Lh"/>
<menuItem title="Preferences" id="4YN-Km-ohc">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<outlet property="view" destination="C4I-d5-Tb4" id="IiX-os-gW7"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="dTa-WJ-cFP"/>
<menuItem title="Quit" id="clu-G1-dhh">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
Expand All @@ -80,11 +89,11 @@
</connections>
</menu>
<customView identifier="TimerView" id="WxJ-5I-PgS" userLabel="Timer">
<rect key="frame" x="0.0" y="0.0" width="163" height="58"/>
<rect key="frame" x="0.0" y="0.0" width="163" height="65"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3TT-Uo-wkQ" userLabel="Timer">
<rect key="frame" x="18" y="25" width="127" height="24"/>
<rect key="frame" x="18" y="32" width="127" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingHead" sendsActionOnEndEditing="YES" alignment="center" placeholderString="Stopped" id="1pi-kS-v5V">
<font key="font" metaFont="system" size="20"/>
Expand All @@ -93,13 +102,58 @@
</textFieldCell>
</textField>
<progressIndicator identifier="timerprogress" wantsLayer="YES" fixedFrame="YES" maxValue="100" style="bar" translatesAutoresizingMaskIntoConstraints="NO" id="oWT-Rs-Itp">
<rect key="frame" x="20" y="1" width="123" height="20"/>
<rect key="frame" x="20" y="8" width="123" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</progressIndicator>
</subviews>
</customView>
<customView id="74f-2z-yDv" userLabel="Actions">
<rect key="frame" x="0.0" y="0.0" width="163" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2Bf-ib-nyo">
<rect key="frame" x="20" y="10" width="16" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="PlayButton" imagePosition="only" alignment="center" imageScaling="proportionallyUpOrDown" inset="2" id="yTx-58-PSo">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<connections>
<binding destination="gEe-Vl-JZj" name="enabled" keyPath="disabled" id="tDg-UC-2f4"/>
</connections>
</buttonCell>
<connections>
<action selector="toggleTimer:" target="gEe-Vl-JZj" id="j39-GT-nxX"/>
<binding destination="gEe-Vl-JZj" name="enabled" keyPath="disabled" id="OEH-V7-NrJ"/>
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ux3-Yg-BF3">
<rect key="frame" x="73" y="10" width="16" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="StopButton" imagePosition="only" alignment="center" imageScaling="proportionallyUpOrDown" inset="2" id="RIk-xU-15c">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="toggleTimer:" target="gEe-Vl-JZj" id="k79-l8-zpy"/>
<binding destination="gEe-Vl-JZj" name="enabled" keyPath="enabled" id="vId-wU-ElG"/>
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="cHv-YY-fF8">
<rect key="frame" x="127" y="10" width="16" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="RestartButton" imagePosition="only" alignment="center" imageScaling="proportionallyUpOrDown" inset="2" id="tOC-cZ-jP8">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="resetTimer:" target="gEe-Vl-JZj" id="l01-5C-pO2"/>
<binding destination="gEe-Vl-JZj" name="enabled" keyPath="enabled" id="2i9-R3-SA0"/>
</connections>
</button>
</subviews>
</customView>
<customView id="Q3w-LZ-ipl" userLabel="Interval">
<rect key="frame" x="0.0" y="0.0" width="163" height="24"/>
<rect key="frame" x="0.0" y="0.0" width="163" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bHh-df-Se7" userLabel="Interval Label">
Expand All @@ -112,7 +166,7 @@
</textFieldCell>
</textField>
<stepper horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="mSB-18-3wR" userLabel="Interval Stepper">
<rect key="frame" x="126" y="-2" width="19" height="27"/>
<rect key="frame" x="127" y="-1" width="19" height="27"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<stepperCell key="cell" lineBreakMode="truncatingHead" continuous="YES" alignment="left" increment="5" minValue="5" maxValue="600" doubleValue="5" id="ghn-kl-ysh"/>
<connections>
Expand All @@ -121,9 +175,35 @@
</stepper>
</subviews>
</customView>
<userDefaultsController representsSharedInstance="YES" id="oey-xm-2ni"/>
<customView id="C4I-d5-Tb4" userLabel="Preferences">
<rect key="frame" x="0.0" y="0.0" width="163" height="45"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="E7w-0g-DDt">
<rect key="frame" x="18" y="22" width="127" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Save Interval" bezelStyle="regularSquare" imagePosition="right" inset="2" id="YJu-D2-JQz">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5JE-tB-e0M">
<rect key="frame" x="18" y="2" width="127" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Sleep" bezelStyle="regularSquare" imagePosition="right" inset="2" id="dN8-8i-cOD">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
</subviews>
</customView>
</objects>
<point key="canvasLocation" x="75" y="0.0"/>
</scene>
</scenes>
<resources>
<image name="PlayButton" width="32" height="32"/>
<image name="RestartButton" width="32" height="32"/>
<image name="StopButton" width="32" height="32"/>
</resources>
</document>
43 changes: 35 additions & 8 deletions SleepWell/MenubarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,35 @@ class MenubarController: NSObject {
@IBOutlet weak var menubar: NSMenu!
@IBOutlet weak var timerLabel: NSTextField!
@IBOutlet weak var progressbar: NSProgressIndicator!
@IBOutlet weak var toggleButton: NSMenuItem!
@IBOutlet weak var intervalLabel: NSTextField!
@IBOutlet weak var intervalStepper: NSStepper!
@IBOutlet weak var startButton: NSButton!
@IBOutlet weak var stopButton: NSButton!
@IBOutlet weak var restartButton: NSButton!

var interval = 0
var enabled = false
dynamic var enabled: NSNumber? = false
dynamic var disabled: NSNumber? = true
var timeRemaining = 0
var timer = Timer()
let menubarIcon = NSStatusBar.system().statusItem(withLength: NSVariableStatusItemLength)

@IBAction func toggleTimer(_ sender: NSMenuItem) {
@IBAction func toggleTimer(_ sender: NSButton) {
progressbar.doubleValue = Double(0)
timeRemaining = interval

if enabled == false {
if isEnabled() == false {
startTimer()
} else {
stopTimer()
}
}

@IBAction func resetTimer(_ sender: NSButton) {
progressbar.doubleValue = Double(0)
timeRemaining = interval
}

@IBAction func setTimeInterval(_ sender: NSStepper) {
setTime(minutes: sender.integerValue)
}
Expand All @@ -47,12 +55,32 @@ class MenubarController: NSObject {
menubarIcon.menu = menubar

setTime(minutes: 60)
setControlButtonStates()
}

func isEnabled() -> Bool {
return (enabled?.boolValue)!
}

func enable() {
enabled = NSNumber?.init(true)
disabled = NSNumber?.init(false)
}

func disable() {
enabled = NSNumber?.init(false)
disabled = NSNumber?.init(true)
}

func getTime() -> Int {
return interval / 60
}

func setControlButtonStates() {
startButton.image?.isTemplate = true
stopButton.image?.isTemplate = true
restartButton.image?.isTemplate = true
}

func setTime(minutes : Int) {
interval = minutes * 60
Expand All @@ -63,8 +91,7 @@ class MenubarController: NSObject {
}

func startTimer() {
enabled = true
toggleButton.title = "Stop"
enable()

DispatchQueue.main.async {
self.timer = Timer(timeInterval: 1.0, target: self, selector: #selector(self.timerRunning), userInfo: nil, repeats: true)
Expand All @@ -73,9 +100,9 @@ class MenubarController: NSObject {
}

func stopTimer() {
disable()

timer.invalidate()
enabled = false
toggleButton.title = "Start"
timerLabel.stringValue = ""
progressbar.doubleValue = Double(0)
}
Expand Down

0 comments on commit 4c32730

Please sign in to comment.