null/demo.local.php
[gitlive] / WindowLog.js
index a0f15a7..acd0d49 100644 (file)
 
 
 
-Wnck = imports.gi.Wnck;
-Gtk = imports.gi.Gtk ;
-Spawn = imports.Spawn;
-File  = imports.File.File;
-GLib        = imports.gi.GLib;
+const Wnck = imports.gi.Wnck;
+const  Gtk = imports.gi.Gtk ;
+const Spawn = imports.Spawn;
+const File  = imports.File.File;
+const GLib        = imports.gi.GLib;
+const Gio = imports.gi.Gio;
+
 //Gtk.init(Seed.argv);
-xDate = imports.Date;
-xorg = imports.xorg;
+const xDate = imports.Date;
+const xorg = typeof(Seed) != 'undefined' ? imports.xorg : false;
 
 WindowLog = {
     
@@ -34,17 +36,26 @@ WindowLog = {
         
         this.outdir = GLib.get_home_dir() + "/.gitlog";
         this.screen = Wnck.Screen.get_default();
-        GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() { return WindowLog.getStatus() } );
-        
+        // 
+        GLib.timeout_add(GLib.PRIORITY_LOW, 5000, function() {
+            return WindowLog.getStatus()
+        } );
+        //Roo.log("Windowlog start");
+        this.screen.signal.active_window_changed.connect(function() {
+            WindowLog.windowChanged();
+        });
     },
-        
+    
+    
+    
+    
     getStatus : function()
     {
         
          
         var output =  xorg.screensaverinfo_get_idletime();
         //print(output);
-         
+        // more that 10 seconds?? - report idle..
         if (output * 1 > 10000) {
             if (this.win != false) { 
                 print( (xDate.newDate()).format("Y-m-d H:i:s") + " IDLE");
@@ -53,16 +64,20 @@ WindowLog = {
             this.win = false;
             return true;
         }
-        
+        return true;
+    },
+     windowChanged : function()
+    {
         this.screen.force_update();
-       
+       // print("window changeD");
         var aw = this.screen.get_active_window();
         if (aw) { 
             var win = aw.get_name();
             var app = aw.get_application();
             var pid = app.get_pid();
             //print("PID " + pid);
-            var cmd = File.realpath('/proc/'+ pid + '/exe');
+            //var cmd = File.realpath('/proc/'+ pid + '/exe');
+            var cmd = pid ? File.read('/proc/'+ pid + '/cmdline') : 'UNKNOWN';
             
             if (!this.win || (this.win && win != this.win)) { 
         
@@ -77,7 +92,11 @@ WindowLog = {
     },
     lastdir : false,
     
-    write : function (cmd , str) {
+    
+    
+    
+    write : function (cmd , str)
+    {
         
         var dir =  this.outdir + (xDate.newDate()).format("/Y/m");
         if (!this.lastdir || this.lastdir != dir) {
@@ -86,14 +105,31 @@ WindowLog = {
             }
             this.lastdir = dir;
         }
+        var ctime = xDate.newDate();
+        var fname = ctime.format("/d") + ".log";
+        var path  = dir + '/' + fname;
+        var time  = ctime.format("H:i:s ")
+        
+        File.append (path, "\n" +time + str + ' ' + cmd );
+
+        // copy to gitlive/gitlog (each user should check out their own gitlog!?
+        if (this.lastcopy && this.lastcopy > ctime.add(xDate.Date.HOUR, -1)) {
+            return;
+        }
+        this.lastcopy = ctime;
+        var cpdir = imports.GitMonitor.GitMonitor.gitlive +
+                    '/gitlog' +  (xDate.newDate()).format("/Y/m");
+                    
+        if (!File.isDirectory(cpdir)) {
+           File.mkdir(cpdir,true);
+        }
+        File.copy(path, cpdir + fname, Gio.FileCopyFlags.OVERWRITE );
         
-        var path = dir + (xDate.newDate()).format("/d") + ".log";
-        var time = (xDate.newDate()).format("H:i:s ")
         
-        File.append (path, time + str + ' ' + cmd + "\n");
     }
     
 }
 
 
-  
\ No newline at end of file
+