line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Flower::Chronos::Tracker; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
28273
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
472
|
use Flower::Chronos::X11; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
612
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
10
|
|
|
10
|
0
|
8143
|
my $class = shift; |
10
|
10
|
|
|
|
|
23
|
my (%params) = @_; |
11
|
|
|
|
|
|
|
|
12
|
10
|
|
|
|
|
14
|
my $self = {}; |
13
|
10
|
|
|
|
|
19
|
bless $self, $class; |
14
|
|
|
|
|
|
|
|
15
|
10
|
|
100
|
|
|
55
|
$self->{idle_timeout} = $params{idle_timeout} || 300; |
16
|
10
|
|
100
|
|
|
42
|
$self->{flush_timeout} = $params{flush_timeout} || 300; |
17
|
10
|
|
|
|
|
17
|
$self->{applications} = $params{applications}; |
18
|
10
|
|
|
|
|
17
|
$self->{on_end} = $params{on_end}; |
19
|
|
|
|
|
|
|
|
20
|
10
|
|
|
|
|
28
|
return $self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub track { |
24
|
18
|
|
|
18
|
0
|
14101
|
my $self = shift; |
25
|
|
|
|
|
|
|
|
26
|
18
|
100
|
|
|
|
68
|
if ($self->_is_time_to_flush) { |
27
|
2
|
50
|
|
|
|
3
|
if (%{$self->{prev} || {}}) { |
|
2
|
50
|
|
|
|
11
|
|
28
|
|
|
|
|
|
|
$self->{prev}->{_end} = |
29
|
2
|
|
|
|
|
7
|
$self->{prev}->{_start} + $self->{flush_timeout}; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
7
|
$self->{on_end}->($self->{prev}); |
32
|
2
|
|
|
|
|
7
|
$self->{prev} = {}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
18
|
|
66
|
|
|
67
|
my $x11 = $self->{x11} ||= $self->_build_x11; |
37
|
|
|
|
|
|
|
|
38
|
18
|
|
|
|
|
413
|
my $info; |
39
|
18
|
50
|
|
|
|
147
|
if ($x11->idle_time > $self->{idle_timeout}) { |
40
|
0
|
|
|
|
|
0
|
$info = {idle => 1, category => ''}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
18
|
|
|
|
|
751
|
$info = $x11->get_active_window; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
18
|
|
100
|
|
|
721
|
my $prev = $self->{prev} ||= {}; |
47
|
18
|
|
|
|
|
44
|
my $time = $self->_time; |
48
|
|
|
|
|
|
|
|
49
|
18
|
50
|
|
|
|
195
|
$self->_run_applications($info) unless $info->{idle}; |
50
|
|
|
|
|
|
|
|
51
|
18
|
|
100
|
|
|
221
|
$info->{$_} //= '' for (qw/id name role class/); |
52
|
18
|
|
100
|
|
|
64
|
$info->{application} //= 'other'; |
53
|
18
|
|
50
|
|
|
65
|
$info->{category} //= 'other'; |
54
|
|
|
|
|
|
|
|
55
|
18
|
50
|
100
|
|
|
80
|
if ( !$prev->{id} |
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
56
|
|
|
|
|
|
|
|| $info->{id} ne $prev->{id} |
57
|
|
|
|
|
|
|
|| $info->{name} ne $prev->{name} |
58
|
|
|
|
|
|
|
|| $info->{role} ne $prev->{role} |
59
|
|
|
|
|
|
|
|| $info->{class} ne $prev->{class}) |
60
|
|
|
|
|
|
|
{ |
61
|
17
|
100
|
|
|
|
41
|
if (%$prev) { |
62
|
5
|
|
|
|
|
12
|
$prev->{_end} = $time; |
63
|
5
|
|
|
|
|
14
|
$self->{on_end}->($prev); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
17
|
|
66
|
|
|
92
|
$info->{_start} ||= $time; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
18
|
|
|
|
|
29
|
$self->{prev} = $info; |
70
|
18
|
|
100
|
|
|
49
|
$self->{prev}->{_start} ||= $time; |
71
|
|
|
|
|
|
|
|
72
|
18
|
|
|
|
|
45
|
return $self; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _run_applications { |
76
|
18
|
|
|
18
|
|
27
|
my $self = shift; |
77
|
18
|
|
|
|
|
27
|
my ($info) = @_; |
78
|
|
|
|
|
|
|
|
79
|
18
|
|
|
|
|
21
|
foreach my $application (@{$self->{applications}}) { |
|
18
|
|
|
|
|
46
|
|
80
|
9
|
|
|
|
|
14
|
local $@; |
81
|
9
|
|
|
|
|
14
|
my $rv = eval { $application->run($info) }; |
|
9
|
|
|
|
|
23
|
|
82
|
9
|
100
|
|
|
|
61
|
next if $@; |
83
|
|
|
|
|
|
|
|
84
|
8
|
100
|
|
|
|
24
|
last if $rv; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _is_time_to_flush { |
89
|
18
|
|
|
18
|
|
24
|
my $self = shift; |
90
|
|
|
|
|
|
|
|
91
|
18
|
|
100
|
|
|
115
|
$self->{flush_time} //= $self->_time; |
92
|
|
|
|
|
|
|
|
93
|
18
|
100
|
|
|
|
121
|
if ($self->_time - $self->{flush_time} > $self->{flush_timeout}) { |
94
|
2
|
|
|
|
|
16
|
$self->{flush_time} = $self->_time; |
95
|
2
|
|
|
|
|
12
|
return 1; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
16
|
|
|
|
|
163
|
return 0; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _build_x11 { |
102
|
0
|
|
|
0
|
|
0
|
return Flower::Chronos::X11->new; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
43
|
|
|
43
|
|
107
|
sub _time { time } |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |