windowlog added
[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
48 WindowLog = {
49     
50     win : false,
51     screen : false,
52  
53     start  : function()
54     {
55         this.outdir = GLib.get_home_dir() + "/.gitlog";
56         this.screen = Wnck.Screen.get_default();
57         GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() { return WindowLog.getStatus() } );
58         
59     },
60         
61     getStatus : function() {
62         
63         var output = Spawn.run({
64            cwd : __script_path__ + '/tests',
65            args : [ __script_path__ + '/tests/xidletime'  ] 
66         });
67         //print(output);
68          
69         if (output * 1 > 10000) {
70             if (this.win != false) { 
71                 print( (xDate.newDate()).format("Y-m-d H:i:s") + " IDLE");
72                 this.write("IDLE");
73             }
74             this.win = false;
75             return true;
76         }
77         this.screen.force_update();
78         var aw = this.screen.get_active_window();
79         if (aw) { 
80             var win = aw.get_name();
81             if (!this.win || (this.win && win != this.win)) { 
82         
83                 print((xDate.newDate()).format("Y-m-d H:i:s") + " " + win);
84                 this.write(win);
85                 this.win=win;
86             }
87         }
88         
89         
90         return true;
91     },
92     lastdir : false,
93     
94     write : function (str) {
95         
96         var dir =  this.outdir + (xDate.newDate()).format("/Y/m");
97         if (!this.lastdir || this.lastdir != dir) {
98             if (!File.isDirectory(dir)) {
99                File.mkdir(dir,true);
100             }
101             this.lastdir = dir;
102         }
103         
104         var path = dir + (xDate.newDate()).format("/d") + ".log";
105         var time = (xDate.newDate()).format("H:i:s ")
106         
107         File.append (path, time +  str + "\n");
108     }
109     
110 }
111
112
113