WindowLog.js
[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  * mouse:
10  * xdotool getmouselocation
11  *
12  * xwit -property WM_NAME -print 
13  * 0x3a13d6c: x=1 y=25 w=1109 h=747 d=32 'root@wideboy: /home/alan'
14  * root@wideboy:/home/alan# xwit -property WM_CLASS -print 
15  * 0x3a13d6c: x=1 y=25 w=1109 h=747 d=32 'gnome-terminal'
16  * root@wideboy:/home/alan# 
17  * 
18  * 
19  * Not sure how we handle last key press...
20  * 
21  * -- log to a remote url.
22  * 
23  * LOG:
24  * DATE / TIME / Application / Title
25  * if cursor same as before.. - SEND 'IDLE'... (twice, then stop sending..)
26  * 
27  * For commits... (we send out every 1 minute as well, it's upto the other end to determine if that means updating
28  * or creating a new record..
29  * yyyy-mm-dd /12:00 / GIT / XXXXX
30  *
31  *
32  * apt-get install gir1.2-wnck-3.0
33  *
34  * 
35  */
36
37
38
39
40 Wnck = imports.gi.Wnck;
41 Gtk = imports.gi.Gtk ;
42 Spawn = imports.Spawn;
43 File  = imports.File.File;
44 GLib        = imports.gi.GLib;
45 //Gtk.init(Seed.argv);
46 xDate = imports.Date;
47 xorg = imports.xorg;
48
49 WindowLog = {
50     
51     win : false,
52     screen : false,
53  
54     start  : function()
55     {
56         this.outdir = GLib.get_home_dir() + "/.gitlog";
57         this.screen = Wnck.Screen.get_default();
58         GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() { return WindowLog.getStatus() } );
59         
60     },
61         
62     getStatus : function() {
63         
64         var output = imports.xorg.screensaverinfo_get_idletime();
65         //print(output);
66          
67         if (output * 1 > 10000) {
68             if (this.win != false) { 
69                 print( (xDate.newDate()).format("Y-m-d H:i:s") + " IDLE");
70                 this.write("IDLE");
71             }
72             this.win = false;
73             return true;
74         }
75         this.screen.force_update();
76         var aw = this.screen.get_active_window();
77         if (aw) { 
78             var win = aw.get_name();
79             if (!this.win || (this.win && win != this.win)) { 
80         
81                 print((xDate.newDate()).format("Y-m-d H:i:s") + " " + win);
82                 this.write(win);
83                 this.win=win;
84             }
85         }
86         
87         
88         return true;
89     },
90     lastdir : false,
91     
92     write : function (str) {
93         
94         var dir =  this.outdir + (xDate.newDate()).format("/Y/m");
95         if (!this.lastdir || this.lastdir != dir) {
96             if (!File.isDirectory(dir)) {
97                File.mkdir(dir,true);
98             }
99             this.lastdir = dir;
100         }
101         
102         var path = dir + (xDate.newDate()).format("/d") + ".log";
103         var time = (xDate.newDate()).format("H:i:s ")
104         
105         File.append (path, time +  str + "\n");
106     }
107     
108 }
109
110
111