<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -7,7 +7,8 @@ import gtk
 import hulahop
 from BaseHTTPServer import HTTPServer
 import thread
-import from XOHTTPServer import XOHTTPRequestHandler
+from XOHTTPServer import XOHTTPRequestHandler
+import XOHTTPStatus
 
 hulahop.startup(os.path.join(env.get_profile_path(), 'gecko'))
 from hulahop.webview import WebView
@@ -21,6 +22,7 @@ class HTTPActivity(activity.Activity):
         toolbox.show()
 
         # Set up the HTTP server thread
+        XOHTTPStatus.initialize()
         self.port = 4080
         try:
             t = thread.start_new_thread(self._socialcalc_server_thread, ())
@@ -30,7 +32,7 @@ class HTTPActivity(activity.Activity):
         
         wv = WebView()
         bundle_path = get_bundle_path()
-        wv.load_uri('file://' + bundle_path + '/web/index.html')
+        wv.load_uri('http://localhost:%s/index.html'%self.port)
         wv.show()
         self.set_canvas(wv)
 
@@ -41,10 +43,13 @@ class HTTPActivity(activity.Activity):
 
     def write_file(self, filename):
         print &quot;write_file: &quot; + filename
-        f = open('web/status.json', 'w')
-        f.write('{ &quot;command&quot; : &quot;write&quot; }')
-        print &quot;wrote status.json&quot;
+        XOHTTPStatus.write_status({ 'command': 'write', 'filename': filename})
 
     def read_file(self, filename):
         print &quot;read_file: &quot; + filename
+        fh = open(filename, 'r')
+        content = fh.read()
+        XOHTTPStatus.write_status({ 'command': 'read', 'content': content})
+        
+
 </diff>
      <filename>HTTPActivity.py</filename>
    </modified>
    <modified>
      <diff>@@ -25,13 +25,14 @@ class XOHTTPRequestHandler(SimpleHTTPRequestHandler):
 
     def write_file(self, content):
         # read the json file to determine where to save the content
-        status = XOHTTPStatus.read()
+        status = XOHTTPStatus.read_status()
         if status['command'] != 'write': 
             return
         fh = open(status['filename'], 'w')
         fh.write(content)
         fh.close()
         print &quot;Saved content to %s&quot;%status['filename']
+        XOHTTPStatus.initialize()
 
 
 def main():</diff>
      <filename>XOHTTPServer.py</filename>
    </modified>
    <modified>
      <diff>@@ -2,11 +2,18 @@ import json
 
 filename = 'web/status.json'
 
-def read():
+def initialize():
+    write_status({'command': 'idle'})
+
+def read_status():
     fh = open(filename, 'r')
     content = fh.read()
     return json.read(content)
 
+def write_status(opts):
+    fh = open(filename, 'w')
+    fh.write(json.write(opts))
+    fh.close()
 
 # For testing
 if __name__ == '__main__':</diff>
      <filename>XOHTTPStatus.py</filename>
    </modified>
    <modified>
      <diff>@@ -16,6 +16,10 @@
                 // Calculate some values
                 return jQuery('textarea').html()
             }
+
+            // Set up hooks to poll for UI actions
+            jQuery('textarea').blur( function () { XO.poll_for_command() } )
+            jQuery(window).unload( function () { XO.poll_for_command() } )
         &lt;/script&gt;
         &lt;style type=&quot;text/css&quot;&gt;
 .savedata {</diff>
      <filename>web/index.html</filename>
    </modified>
    <modified>
      <diff>@@ -10,7 +10,6 @@ var XO = window.XO = {
     poll_for_command: function () {
         XO.set_status('Polling for a command')
         $.getJSON(&quot;/status.json&quot;, function(json){
-            XO.set_status('Received command: ' + json.command)
             if (json.command == &quot;read&quot;) {
                 // Content to read, so send it to the application
                 XO.read_hook(json.content)
@@ -24,12 +23,19 @@ var XO = window.XO = {
                     url:  '/write',
                     data: { 'save_content': XO.write_hook() },
                     success: function() {
-                        XO.set_status('Send save data to server')
+                        XO.set_status('Sent save data to server')
                     }
                 })
             }
+            else if (json.command == 'idle') {
+                XO.set_status('Idle - no command')
+            }
+            else {
+                XO.set_status('Unknown command: ' + json.command)
+            }
         })
     }
 }
 
 jQuery(function() {XO.poll_for_command()})
+setInterval(function() {XO.poll_for_command()}, 10000)</diff>
      <filename>web/xo-code.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>5f7ccc5e5080e8fd1f65e94ffb38ce33c77dd2dd</id>
    </parent>
  </parents>
  <author>
    <name>Luke Closs</name>
    <email>olpc@5thplane.com</email>
  </author>
  <url>http://github.com/lukec/httpactivity/commit/850ccaf022626595e1a25678556b53201161fd64</url>
  <id>850ccaf022626595e1a25678556b53201161fd64</id>
  <committed-date>2008-04-01T00:50:01-07:00</committed-date>
  <authored-date>2008-04-01T00:50:01-07:00</authored-date>
  <message>it works, sorta</message>
  <tree>47482ddef908e26d212f8ebbf6c6318589a2c71a</tree>
  <committer>
    <name>Luke Closs</name>
    <email>olpc@5thplane.com</email>
  </committer>
</commit>
