Browse code

"Cleaning code and adding global variables"

Blackbeard authored on 2018-09-12 03:53:05
Showing 1 changed files
... ...
@@ -1,19 +1,14 @@
1 1
 #!/bin/sh
2 2
 WORK_TIME=1500
3 3
 REST_TIME=300
4
-SOUND="/usr/share/sounds/Oxygen-Sys-Log-In.ogg"
5
-SAY_MESSAGE_STOP="Please stop aworking"
6
-SAY_MESSAGE_CONTINUE="Please stop aworking"
4
+SOUND="$HOME/bin/time.ogg"
5
+SAY_MESSAGE_STOP="Please stop working."
6
+SAY_MESSAGE_CONTINUE="You can continue working now" 
7
+POPUP_MESSAGE_REST="Time to rest."
7 8
 
8
-
9
-function _pomodoro_clockWork {
10
-    local time_work="$1"
11
-    sleep "$work_time"
12
-}
13
-
14
-function _pomodoro_clockRest {
15
-    local time_rest="$1"
16
-    sleep "$time_rest"
9
+function _pomodoro_clock {
10
+    local _time="$1"
11
+    sleep "$_time"
17 12
 }
18 13
 
19 14
 function _pomodoro_sound {
... ...
@@ -26,10 +21,6 @@ function _pomodoro_say {
26 21
     espeak "$message" 2>/dev/null
27 22
 }
28 23
 
29
-function _pomodoro_sayWork {
30
-    espeak "You can continue working now" 2>/dev/null
31
-}
32
-
33 24
 function _pomodoro_popup {
34 25
     local message="$1"
35 26
     local time_out="$2"
... ...
@@ -40,42 +31,40 @@ function _pomodoro_popup {
40 31
 	-timeout "$time_out" 
41 32
 }
42 33
 
43
-function _pomodoro_popupRest {
44
-    local message="time to rest"
45
-    local time_out=300
46
-    _pomodoro_popup "$message" "$time_out"
34
+function _pomodoro_work {
35
+    # work for during WORK_TIME
36
+    _pomodoro_clock "$WORK_TIME"
37
+    # when clock ends it is time to stop
38
+    _pomodoro_sound "$SOUND"
39
+    _pomodoro_say "$SAY_MESSAGE_STOP"
40
+    _pomodoro_popup "$POPUP_MESSAGE_REST" "$REST_TIME"
41
+    # after popup ends you can go back to work
42
+    _pomodoro_say "$SAY_MESSAGE_CONTINUE"
47 43
 }
48 44
 
49
-
50
-function _pomodoro_timerWork {
51
-    _pomodoro_wait25
52
-    _pomodoro_sound
53
-    _pomodoro_sayStop
54
-    _pomodoro_popupRest
55
-    _pomodoro_sayWork
45
+function _pomodoro_rest {
46
+    _pomodoro_sound "$SOUND"
47
+    _pomodoro_popup "$POPUP_MESSAGE_REST" "$REST_TIME"
48
+    #time to go back to work after popup ends
49
+    _pomodoro_say "$SAY_MESSAGE_CONTINUE"
56 50
 }
57 51
 
58
-function _pomodoro_timerRest {
59
-    _pomodoro_popupRest
60
-    _pomodoro_sound
61
-    _pomodoro_sayWork
62
-}
63
-
64
-function handle_arguments {
52
+function main {
65 53
     if [ -z "$1" ]; then
66
-	_pomodoro_timerWork
54
+	_pomodoro_work
67 55
     else
68
-	not_empty_arguments "$@"
56
+	_handle_arguments "$@"
69 57
     fi
70 58
     return
71 59
 }
72 60
 
73
-function not_empty_arguments {
61
+
62
+#	    -p | --playlist-id )    argument_playlist_id "$2" ; shift ; shift  ;;
63
+function _handle_arguments {
74 64
     while [ "$1" != "" ]; do
75 65
 	case "$1" in
76
-	    -r | --rest )        _pomodoro_timerRest ; shift ;;
77
-	    -w | --work )        _pomodoro_timerWork ; shift ;;
78
-#	    -p | --playlist-id )    argument_playlist_id "$2" ; shift ; shift  ;;
66
+	    -r | --rest )        _pomodoro_rest ; shift ;;
67
+	    -w | --work )        _pomodoro_work ; shift ;;
79 68
 	    --)  shift; break ;;
80 69
 	    * ) print_invalid_option $1 ; exit 1 ;;
81 70
 	esac
... ...
@@ -83,4 +72,4 @@ function not_empty_arguments {
83 72
     return
84 73
 }
85 74
 
86
-handle_arguments "$@"
75
+main "$@"