-
Notifications
You must be signed in to change notification settings - Fork 0
/
DVTimer.ahk
142 lines (108 loc) · 3.32 KB
/
DVTimer.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#NoTrayIcon
#SingleInstance, Force
#Persistent
#KeyHistory, 0
SetBatchLines, -1
; =========
; Main Body - v1.0
; =========
FileInstall, DVTimer.wav, %A_ScriptDir%\DVTimer.wav
FileInstall, DVTimer0.ico, %A_ScriptDir%\DVTimer0.ico
FileInstall, DVTimer1.ico, %A_ScriptDir%\DVTimer1.ico
WinTitle = Activity Reminder
Menu, Tray, Icon, %A_ScriptDir%\DVTimer0.ico,, 1 ; not yet shown, but used by possible InputBox
IfEqual, 1, ; was the timer period not provided on command line?
{
InputBox, PeriodM, %WinTitle%, Enter the timer period (in minutes):,, 250, 130,,,,, 75
IfNotEqual, ErrorLevel, 0, ExitApp, 1
}
Else
PeriodM = %1%
ToGo := Period := PeriodM * 60000
Interval := 6000 ; TrayTip update interval (6 seconds / 0.1 minute)
SetFormat, Float, 0.1
SetTimer, TimeCheck, %Interval%
GoSub, mNewTime
Menu, Tray, Icon
Menu, Tray, Tip, %WinTitle%:`nNext Walk at %TimeM% ; `n is a line break.
Menu, Tray, NoStandard
Stopped = 0 ; to keep track of timer stopped/started state
StartText = Start timer
StopText = Stop timer
Menu, Tray, Add, Next Walk at %TimeM%, mDoNothing
Menu, Tray, Default, Next Walk at %TimeM%
Menu, Tray, Disable, Next Walk at %TimeM%
Menu, Tray, Add ; time for a nice separator
Menu, Tray, Add, %StopText%, mStopStart
Menu, Tray, Add, Restart timer, mRestart
Menu, Tray, Add, Change timer period, mChange
Menu, Tray, Add ; time for a nice separator
Menu, Tray, Add, Exit %WinTitle%, mExit
Return
; ======
mChange:
; ======
PeriodM =
; =======
mRestart:
; =======
Run, %A_ScriptFullPath% %PeriodM%, %A_WorkingDir%, UseErrorLevel
Return ; failsafe / probably never hits this line
; ====
mExit:
; ====
ExitApp, 0
; =======
mStopStart:
; =======
Stopped := 1 - Stopped
IfEqual, Stopped, 1
{
Menu, Tray, Rename, %StopText%, %StartText%
Menu, Tray, Icon, %A_ScriptDir%\DVTimer1.ico
SetTimer, TimeCheck, Off
Menu, Tray, Tip, %WinTitle%:`nCurrently stopped!
Menu, Tray, Disable, Restart timer
Menu, Tray, Rename, Next Walk at %TimeM%, Blood Clots FORMING!
}
Else
{
GoSub, mNewTime
Menu, Tray, Rename, %StartText%, %StopText%
Menu, Tray, Icon, %A_ScriptDir%\DVTimer0.ico
ToGo := Period
SetTimer, TimeCheck, On ; restart timer with original period
Menu, Tray, Tip, %WinTitle%:`nNext Walk at %TimeM%.
Menu, Tray, Enable, Restart timer
Menu, Tray, Rename, Blood Clots FORMING!, Next Walk at %TimeM%
}
Return
; =====
mDoNothing: ; for labels.
; =====
Return
; =====
mNewTime: ; Sets up time Variable.
; =====
TimeM =
TimeM += %PeriodM%, Minutes
FormatTime, TimeM, %TimeM%, Time
Return
; =====
; Timer
; =====
TimeCheck:
ToGo := ToGo - Interval
IfGreater, ToGo, 3000 ; not yet time if more than 3 seconds to go (instead of 0, to account for cumulative "drift")
{
TipTime := (ToGo // 6000) / 10
Menu, Tray, Tip, %WinTitle%:`nNext Walk %TimeM% (in ~%TipTime% minutes).
Return
}
GoSub, mStopStart ; stop timer
Menu, Tray, Disable, %StartText% ; don't allow timer restart until upcoming MsgBox is dismissed!
SoundPlay, %A_ScriptDir%\DVTimer.wav, Wait
MsgBox, 4160, %WinTitle%, Time to take a walk, buddy!`n`nClick OK to restart the timer.
Menu, Tray, Enable, %StartText% ; re-enable timer stop/start menu item
GoSub, mStopStart ; start fresh timer
Return