README.txt
[gitlive] / WindowLog.js
1 //<script type="text/javascript">
2 /**
3  * log desktop actions..
4  *
5  * a potential add-on to gitlive....
6  * - basically tracks what applications are being worked on when, allowing you to
7  * use it to generate time tracking (eg. invoices...) later..
8  * 
9  *
10  * apt-get install gir1.2-wnck-3.0
11  * -- needs latest seed (HEAD as of 30nov2011) with the xorg module built in..
12  * 
13  */
14
15
16
17
18 Wnck = imports.gi.Wnck;
19 Gtk = imports.gi.Gtk ;
20 Spawn = imports.Spawn;
21 File  = imports.File.File;
22 GLib        = imports.gi.GLib;
23 //Gtk.init(Seed.argv);
24 xDate = imports.Date;
25 xorg = imports.xorg;
26
27 WindowLog = {
28     
29     win : false,
30     screen : false,
31  
32     start  : function()
33     {
34         
35         this.outdir = GLib.get_home_dir() + "/.gitlog";
36         this.screen = Wnck.Screen.get_default();
37         GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() { return WindowLog.getStatus() } );
38         
39     },
40         
41     getStatus : function()
42     {
43         
44          
45         var output =  xorg.screensaverinfo_get_idletime();
46         //print(output);
47          
48         if (output * 1 > 10000) {
49             if (this.win != false) { 
50                 print( (xDate.newDate()).format("Y-m-d H:i:s") + " IDLE");
51                 this.write(false, "IDLE");
52             }
53             this.win = false;
54             return true;
55         }
56         
57         this.screen.force_update();
58        
59         var aw = this.screen.get_active_window();
60         if (aw) { 
61             var win = aw.get_name();
62             var app = aw.get_application();
63             var pid = app.get_pid();
64             //print("PID " + pid);
65             //var cmd = File.realpath('/proc/'+ pid + '/exe');
66             var cmd = pid ? File.read('/proc/'+ pid + '/cmdline') : 'UNKNOWN';
67             
68             if (!this.win || (this.win && win != this.win)) { 
69         
70                 print((xDate.newDate()).format("Y-m-d H:i:s") + " " + win + ' - '+ cmd );
71                 this.write(cmd, win);
72                 this.win=win;
73             }
74         }
75         
76         
77         return true;
78     },
79     lastdir : false,
80     
81     write : function (cmd , str) {
82         
83         var dir =  this.outdir + (xDate.newDate()).format("/Y/m");
84         if (!this.lastdir || this.lastdir != dir) {
85             if (!File.isDirectory(dir)) {
86                File.mkdir(dir,true);
87             }
88             this.lastdir = dir;
89         }
90         
91         var path = dir + (xDate.newDate()).format("/d") + ".log";
92         var time = (xDate.newDate()).format("H:i:s ")
93         
94         File.append (path, "\n" +time + str + ' ' + cmd );
95         
96
97         return;
98         var auth = imports.Netrc.Netrc.forHost('git.roojs.com');
99
100         // upload it..
101         new XMLHttpRequest({
102             url : 'http://www.roojs.com/admin.php/Roo/Mtrack_desktop_activity', // configurable?
103             method : 'POST',
104             params : {
105                 cmd : cmd,
106                 title : str,
107                 start_dt : (xDate.newDate()).format("Y-m-d H:i:s")
108             },
109             user : auth.login,
110             password : auth.password,
111             async : true,
112             send : true   // run on ctor..
113         });
114         
115         
116     }
117     
118 }
119
120
121