line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Flower::Chronos::Tracker; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
28497
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
501
|
use Flower::Chronos::X11; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
586
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
10
|
|
|
10
|
0
|
8578
|
my $class = shift; |
10
|
10
|
|
|
|
|
22
|
my (%params) = @_; |
11
|
|
|
|
|
|
|
|
12
|
10
|
|
|
|
|
16
|
my $self = {}; |
13
|
10
|
|
|
|
|
19
|
bless $self, $class; |
14
|
|
|
|
|
|
|
|
15
|
10
|
|
100
|
|
|
56
|
$self->{idle_timeout} = $params{idle_timeout} || 300; |
16
|
10
|
|
100
|
|
|
41
|
$self->{flush_timeout} = $params{flush_timeout} || 300; |
17
|
10
|
|
|
|
|
20
|
$self->{applications} = $params{applications}; |
18
|
10
|
|
|
|
|
20
|
$self->{on_end} = $params{on_end}; |
19
|
|
|
|
|
|
|
|
20
|
10
|
|
|
|
|
25
|
return $self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub track { |
24
|
18
|
|
|
18
|
0
|
14256
|
my $self = shift; |
25
|
|
|
|
|
|
|
|
26
|
18
|
100
|
|
|
|
68
|
if ($self->_is_time_to_flush) { |
27
|
2
|
50
|
|
|
|
3
|
if (%{$self->{prev} || {}}) { |
|
2
|
50
|
|
|
|
10
|
|
28
|
|
|
|
|
|
|
$self->{prev}->{_end} = |
29
|
2
|
|
|
|
|
6
|
$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
|
|
|
72
|
my $x11 = $self->{x11} ||= $self->_build_x11; |
37
|
|
|
|
|
|
|
|
38
|
18
|
|
|
|
|
425
|
my $info; |
39
|
18
|
50
|
|
|
|
140
|
if ($x11->idle_time > $self->{idle_timeout}) { |
40
|
0
|
|
|
|
|
0
|
$info = {idle => 1, category => ''}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
18
|
|
|
|
|
807
|
$info = $x11->get_active_window; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
18
|
|
100
|
|
|
691
|
my $prev = $self->{prev} ||= {}; |
47
|
18
|
|
|
|
|
41
|
my $time = $self->_time; |
48
|
|
|
|
|
|
|
|
49
|
18
|
50
|
|
|
|
201
|
$self->_run_applications($info) unless $info->{idle}; |
50
|
|
|
|
|
|
|
|
51
|
18
|
|
100
|
|
|
234
|
$info->{$_} //= '' for (qw/id name role class/); |
52
|
18
|
|
100
|
|
|
65
|
$info->{application} //= 'other'; |
53
|
18
|
|
50
|
|
|
65
|
$info->{category} //= 'other'; |
54
|
|
|
|
|
|
|
|
55
|
18
|
50
|
100
|
|
|
87
|
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
|
|
|
|
42
|
if (%$prev) { |
62
|
5
|
|
|
|
|
12
|
$prev->{_end} = $time; |
63
|
5
|
|
|
|
|
16
|
$self->{on_end}->($prev); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
17
|
|
66
|
|
|
96
|
$info->{_start} ||= $time; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
18
|
|
|
|
|
31
|
$self->{prev} = $info; |
70
|
18
|
|
100
|
|
|
49
|
$self->{prev}->{_start} ||= $time; |
71
|
|
|
|
|
|
|
|
72
|
18
|
|
|
|
|
42
|
return $self; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _run_applications { |
76
|
18
|
|
|
18
|
|
27
|
my $self = shift; |
77
|
18
|
|
|
|
|
26
|
my ($info) = @_; |
78
|
|
|
|
|
|
|
|
79
|
18
|
|
|
|
|
27
|
foreach my $application (@{$self->{applications}}) { |
|
18
|
|
|
|
|
47
|
|
80
|
9
|
|
|
|
|
10
|
local $@; |
81
|
9
|
|
|
|
|
17
|
my $rv = eval { $application->run($info) }; |
|
9
|
|
|
|
|
25
|
|
82
|
9
|
100
|
|
|
|
67
|
next if $@; |
83
|
|
|
|
|
|
|
|
84
|
8
|
100
|
|
|
|
25
|
last if $rv; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _is_time_to_flush { |
89
|
18
|
|
|
18
|
|
21
|
my $self = shift; |
90
|
|
|
|
|
|
|
|
91
|
18
|
|
100
|
|
|
116
|
$self->{flush_time} //= $self->_time; |
92
|
|
|
|
|
|
|
|
93
|
18
|
100
|
|
|
|
139
|
if ($self->_time - $self->{flush_time} > $self->{flush_timeout}) { |
94
|
2
|
|
|
|
|
15
|
$self->{flush_time} = $self->_time; |
95
|
2
|
|
|
|
|
12
|
return 1; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
16
|
|
|
|
|
168
|
return 0; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _build_x11 { |
102
|
0
|
|
|
0
|
|
0
|
return Flower::Chronos::X11->new; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
43
|
|
|
43
|
|
105
|
sub _time { time } |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |