1 //<script type="text/javascript">
3 * log desktop actions..
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..
10 * apt-get install gir1.2-wnck-3.0
11 * -- needs latest seed (HEAD as of 30nov2011) with the xorg module built in..
18 Wnck = imports.gi.Wnck;
19 Gtk = imports.gi.Gtk ;
20 Spawn = imports.Spawn;
21 File = imports.File.File;
22 GLib = imports.gi.GLib;
25 //Gtk.init(Seed.argv);
37 this.outdir = GLib.get_home_dir() + "/.gitlog";
38 this.screen = Wnck.Screen.get_default();
39 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() { return WindowLog.getStatus() } );
43 getStatus : function()
47 var output = xorg.screensaverinfo_get_idletime();
50 if (output * 1 > 10000) {
51 if (this.win != false) {
52 print( (xDate.newDate()).format("Y-m-d H:i:s") + " IDLE");
53 this.write(false, "IDLE");
59 this.screen.force_update();
61 var aw = this.screen.get_active_window();
63 var win = aw.get_name();
64 var app = aw.get_application();
65 var pid = app.get_pid();
66 //print("PID " + pid);
67 //var cmd = File.realpath('/proc/'+ pid + '/exe');
68 var cmd = pid ? File.read('/proc/'+ pid + '/cmdline') : 'UNKNOWN';
70 if (!this.win || (this.win && win != this.win)) {
72 print((xDate.newDate()).format("Y-m-d H:i:s") + " " + win + ' - '+ cmd );
86 write : function (cmd , str)
89 var dir = this.outdir + (xDate.newDate()).format("/Y/m");
90 if (!this.lastdir || this.lastdir != dir) {
91 if (!File.isDirectory(dir)) {
96 var ctime = xDate.newDate();
97 var fname = ctime.format("/d") + ".log";
98 var path = dir + '/' + fname;
99 var time = ctime.format("H:i:s ")
101 File.append (path, "\n" +time + str + ' ' + cmd );
104 // copy to gitlive/gitlog (each user should check out their own gitlog!?
105 if (this.lastcopy && this.lastcopy > ctime.add(xDate.Date.HOUR, -1)) {
108 this.lastcopy = ctime;
109 var cpdir = imports.GitMonitor.GitMonitor.gitlive +
110 '/gitlog' + (xDate.newDate()).format("/Y/m");
112 if (!File.isDirectory(cpdir)) {
113 File.mkdir(cpdir,true);
115 File.copy(path, cpdir + fname, Gio.FileCopyFlags.OVERWRITE );