ddb1bc5f3c8d5b109298e59ee18483a5c63ae6ca
[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         this.outdir = GLib.get_home_dir() + "/.gitlog";
35         this.screen = Wnck.Screen.get_default();
36         GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() { return WindowLog.getStatus() } );
37         
38     },
39         
40     getStatus : function() {
41         
42         var output =  xorg.screensaverinfo_get_idletime();
43         //print(output);
44          
45         if (output * 1 > 10000) {
46             if (this.win != false) { 
47                 print( (xDate.newDate()).format("Y-m-d H:i:s") + " IDLE");
48                 this.write("IDLE");
49             }
50             this.win = false;
51             return true;
52         }
53         this.screen.force_update();
54         var aw = this.screen.get_active_window();
55         if (aw) { 
56             var win = aw.get_name();
57             if (!this.win || (this.win && win != this.win)) { 
58         
59                 print((xDate.newDate()).format("Y-m-d H:i:s") + " " + win);
60                 this.write(win);
61                 this.win=win;
62             }
63         }
64         
65         
66         return true;
67     },
68     lastdir : false,
69     
70     write : function (str) {
71         
72         var dir =  this.outdir + (xDate.newDate()).format("/Y/m");
73         if (!this.lastdir || this.lastdir != dir) {
74             if (!File.isDirectory(dir)) {
75                File.mkdir(dir,true);
76             }
77             this.lastdir = dir;
78         }
79         
80         var path = dir + (xDate.newDate()).format("/d") + ".log";
81         var time = (xDate.newDate()).format("H:i:s ")
82         
83         File.append (path, time +  str + "\n");
84     }
85     
86 }
87
88
89