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 const Wnck = imports.gi.Wnck;
19 const Gtk = imports.gi.Gtk ;
20 const Spawn = imports.Spawn;
21 const File = imports.File.File;
22 const GLib = imports.gi.GLib;
23 const Gio = imports.gi.Gio;
25 //Gtk.init(Seed.argv);
26 const xDate = imports.Date;
27 const xorg = typeof(Seed) != 'undefined' ? imports.xorg : false;
37 this.outdir = GLib.get_home_dir() + "/.gitlog";
38 this.screen = Wnck.Screen.get_default();
40 GLib.timeout_add(GLib.PRIORITY_LOW, 5000, function() {
41 return WindowLog.getStatus()
43 //Roo.log("Windowlog start");
44 this.screen.signal.active_window_changed.connect(function() {
45 WindowLog.windowChanged();
52 getStatus : function()
56 var output = xorg.screensaverinfo_get_idletime();
58 // more that 10 seconds?? - report idle..
59 if (output * 1 > 10000) {
60 if (this.win != false) {
61 print( (xDate.newDate()).format("Y-m-d H:i:s") + " IDLE");
62 this.write(false, "IDLE");
69 windowChanged : function()
71 this.screen.force_update();
72 // print("window changeD");
73 var aw = this.screen.get_active_window();
75 var win = aw.get_name();
76 var app = aw.get_application();
77 var pid = app.get_pid();
78 //print("PID " + pid);
79 //var cmd = File.realpath('/proc/'+ pid + '/exe');
80 var cmd = pid ? File.read('/proc/'+ pid + '/cmdline') : 'UNKNOWN';
82 if (!this.win || (this.win && win != this.win)) {
84 print((xDate.newDate()).format("Y-m-d H:i:s") + " " + win + ' - '+ cmd );
98 write : function (cmd , str)
101 var dir = this.outdir + (xDate.newDate()).format("/Y/m");
102 if (!this.lastdir || this.lastdir != dir) {
103 if (!File.isDirectory(dir)) {
104 File.mkdir(dir,true);
108 var ctime = xDate.newDate();
109 var fname = ctime.format("/d") + ".log";
110 var path = dir + '/' + fname;
111 var time = ctime.format("H:i:s ")
113 File.append (path, "\n" +time + str + ' ' + cmd );
116 // copy to gitlive/gitlog (each user should check out their own gitlog!?
117 if (this.lastcopy && this.lastcopy > ctime.add(xDate.Date.HOUR, -1)) {
120 this.lastcopy = ctime;
121 var cpdir = imports.GitMonitor.GitMonitor.gitlive +
122 '/gitlog' + (xDate.newDate()).format("/Y/m");
124 if (!File.isDirectory(cpdir)) {
125 File.mkdir(cpdir,true);
127 File.copy(path, cpdir + fname, Gio.FileCopyFlags.OVERWRITE );