Commits

Stefan Scherfke committed c7d96de

Made alarms asynchronous.

Comments (0)

Files changed (1)

Tea Timer.wdgt/Scripts/Timer.js

-var timer = null;
-
 /**
  * This class implements the countdown timer and the alarm function.
  */
  */
 Timer.prototype.run = function() {
     var h, m, s;
-    
-    if (!timer.isPaused) {
-		timer.hours = $('#hours').text()
-		timer.minutes = $('#minutes').text()
-		timer.seconds = $('#seconds').text()
-		h = parseInt(timer.hours, 10);
-		m = parseInt(timer.minutes, 10);
-		s = parseInt(timer.seconds, 10);  
+
+    if (!this.isPaused) {
+		this.hours = $('#hours').text()
+		this.minutes = $('#minutes').text()
+		this.seconds = $('#seconds').text()
+		h = parseInt(this.hours, 10);
+		m = parseInt(this.minutes, 10);
+		s = parseInt(this.seconds, 10);
     }
     else {
-        timer.isPaused = false;
-        h = timer.remainingHours;
-        m = timer.remainingMinutes;
-        s = timer.remainingSeconds;
+        this.isPaused = false;
+        h = this.remainingHours;
+        m = this.remainingMinutes;
+        s = this.remainingSeconds;
     }
 	m += h * 60;
 	s += m * 60;
-	timer._targetTime = Date.parse(new Date()) + s * 1000;
-	timer._isTargetReached = false; 
+	this._targetTime = Date.parse(new Date()) + s * 1000;
+	this._isTargetReached = false;
 
 	// Check if target time has already been passed.
-	if (timer._targetTime > Date.parse(new Date())) {
-		timer.timerInterval = setInterval('timer.runTimer()', 1000);
+	if (this._targetTime > Date.parse(new Date())) {
+		this.timerInterval = setInterval('timer.runTimer()', 1000);
 	}
 	else {
 		front.resetDisplay();
  * Pause the countdown.
  */
 Timer.prototype.pause = function() {
-	clearInterval(timer.timerInterval);
-	timer.timerInterval = null;
-	timer.isPaused = true
+	clearInterval(this.timerInterval);
+	this.timerInterval = null;
+	this.isPaused = true
 };
 
 /**
  * Rewind the countdown – set it back to it initial value.
  */
 Timer.prototype.rewind = function() {
-	clearInterval(timer.timerInterval);
-	timer.timerInterval = null;
-	timer._isTargetReached = false;
-	timer.isPaused = false;
-	front.resetDisplayTo(timer.hours, timer.minutes, timer.seconds);
+	clearInterval(this.timerInterval);
+	this.timerInterval = null;
+	this._isTargetReached = false;
+	this.isPaused = false;
+	front.resetDisplayTo(this.hours, this.minutes, this.seconds);
 };
 
 /**
  * Stop the alarm.
  */
 Timer.prototype.stopAlarm = function() {
-    timer.stopClicked = true;
+    this.stopClicked = true;
 };
 
 
  * the displayed time and finally checks wheter to alarm the user or not.
  */
 Timer.prototype.runTimer = function() {
-    timer.calculateRemainingTime();
+    this.calculateRemainingTime();
     front.updateTimerDisplay();
-    timer.checkForAlarm();
+    this.checkForAlarm();
 };
 
 /**
  */
 Timer.prototype.calculateRemainingTime = function() {
 	currentTime = Date.parse(new Date());
-	timer.remainingSeconds = (timer._targetTime - currentTime) / 1000;
-	timer.remainingMinutes = parseInt(timer.remainingSeconds / 60);
-	timer.remainingHours = parseInt(timer.remainingMinutes / 60);
-	timer.remainingSeconds %= 60;
-	timer.remainingMinutes %= 60;
+	this.remainingSeconds = (this._targetTime - currentTime) / 1000;
+	this.remainingMinutes = parseInt(this.remainingSeconds / 60);
+	this.remainingHours = parseInt(this.remainingMinutes / 60);
+	this.remainingSeconds %= 60;
+	this.remainingMinutes %= 60;
 };
 
 /**
  * Check if the target time is reached and alarm the user.
  */
 Timer.prototype.checkForAlarm = function() {
-	if (timer.remainingSeconds <= 0 && timer.remainingMinutes <= 0 
-			&& timer.remainingHours <= 0 && !timer._isTargetReached) {
-		clearInterval(timer.timerInterval);
-		timer.timerInterval = null;
-		timer._isTargetReached = true;
-		timer.isPaused = false;
-		front.resetDisplayTo(timer.hours, timer.minutes, timer.seconds);
+	if (this.remainingSeconds <= 0 && this.remainingMinutes <= 0
+			&& this.remainingHours <= 0 && !this._isTargetReached) {
+		clearInterval(this.timerInterval);
+		this.timerInterval = null;
+		this._isTargetReached = true;
+		this.isPaused = false;
+		front.resetDisplayTo(this.hours, this.minutes, this.seconds);
 		if (alarm.keepAlarming)
 			front.showStopAlarmButton();
-			timer.stopClicked = false;
-        timer.alarm();
+			this.stopClicked = false;
+        this.alarm();
 	}
 };
 
         $('#soundPlayer').get(0).Play();
 	}
 	if (window.widget && (!type || type == 'growl') && alarm.growl) {
-		widget.system('/usr/bin/env python growl.py "' + title + '" "' 
-				+ message + '"', null);
+		widget.system('/usr/bin/env python growl.py "' + title + '" "'
+				+ message + '"', function(){});
 	}
 	if (window.widget && (!type || type == 'voice') && alarm.voice != 'none') {
 		widget.system('/usr/bin/osascript -e \'say "' + message
-						+ '" using "' + alarm.voice + '"\'', null);
+						+ '" using "' + alarm.voice + '"\'', function(){});
 	}
-	
-	if (window.widget && alarm.keepAlarming && !type && !timer.stopClicked) {
-		timer.repeatAlarm();
+
+	if (window.widget && alarm.keepAlarming && !type && !this.stopClicked) {
+		this.repeatAlarm();
 	}
 };
 
  *
  */
 Timer.prototype.repeatAlarm = function() {
-	if (timer.stopClicked) {
-		timer._msCounter == 0;
+	if (this.stopClicked) {
+		this._msCounter == 0;
 		return;
 	}
-	timer._msCounter = (timer._msCounter + 10) % 5000;
-	if (timer._msCounter == 0)
-		timer.alarm();
+	this._msCounter = (this._msCounter + 10) % 5000;
+	if (this._msCounter == 0)
+		this.alarm();
 	else
-		setTimeout('timer.repeatAlarm()', 10);
+		setTimeout('this.repeatAlarm()', 10);
 };
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.