<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -121,6 +121,7 @@ class TimeClock:
         self.wTree = gtk.glade.XML(self.gladefile)
 
         self.last_tick = time.time()
+        self.last_save = 0
         self._init_widgets()
 
         self.notify = True
@@ -213,13 +214,9 @@ class TimeClock:
         if widget.get_active():
             self.selectedBtn = widget
 
-        if self.selectedBtn.mode == SLEEP and self.save_timeout:
+        if self.selectedBtn.mode == SLEEP:
             gobject.source_remove(self.save_timeout)
-            self.save_timeout = None
             self.doSave()
-        elif self.selectedBtn.mode != SLEEP and not self.save_timeout:
-            # Save timer states every five minutes in case of crashes
-            self.save_timeout = gobject.timeout_add(1000 * 60 * 5, self.doSave)
 
     def reset_clicked(self, widget):
         &quot;&quot;&quot;Callback for the reset button&quot;&quot;&quot;
@@ -270,14 +267,19 @@ class TimeClock:
     def tick(self):
         &quot;&quot;&quot;Once-per-second timeout callback for updating progress bars.&quot;&quot;&quot;
         mode = self.selectedBtn.mode
+        now = time.time()
         if mode != SLEEP:
-            self.used[mode] += (time.time() - self.last_tick)
+            self.used[mode] += (now - self.last_tick)
             self.update_progressBars()
 
             if self.used[mode] &gt;= self.total[mode] and self.notify:
                 notify_exhaustion(mode)
 
-        self.last_tick = time.time()
+            if now &gt;= (self.last_save + (5 * 60)):
+                self.doSave()
+
+        self.last_tick = now
+
         return True
 
     def doSave(self):
@@ -287,6 +289,7 @@ class TimeClock:
         Saves the current timer values to disk.&quot;&quot;&quot;
         pickle.dump( (CURRENT_SAVE_VERSION, self.total, self.used, self.notify),
                      open(SAVE_FILE, &quot;w&quot;) )
+        self.last_save = time.time()
         return True
 
 if __name__ == '__main__':</diff>
      <filename>timeclock.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>92aa24035e55111cfbf1547f3f50ddd1c8448cb8</id>
    </parent>
  </parents>
  <author>
    <name>FunnyMan3595 (Charlie Nolan)</name>
    <email>funnyman3595@gmail.com</email>
  </author>
  <url>http://github.com/ssokolow/timeclock/commit/0c8b984cd2e9a3ea79bea9d3e7415c54bfb3f95d</url>
  <id>0c8b984cd2e9a3ea79bea9d3e7415c54bfb3f95d</id>
  <committed-date>2009-10-03T13:32:28-07:00</committed-date>
  <authored-date>2009-10-03T13:32:28-07:00</authored-date>
  <message>Moved 5-minute autosaves into main heartbeat.

This works around an issue where the save timer would stop firing for unexplained reasons when the user went AFK and/or closed the lid of their laptop.</message>
  <tree>ac5f428b77d450a2312d965a3b570fb213e5b05f</tree>
  <committer>
    <name>FunnyMan3595 (Charlie Nolan)</name>
    <email>funnyman3595@gmail.com</email>
  </committer>
</commit>
