@@ -8,9 +8,18 @@ export class UsageCounter {
8
8
private totalUsage = 0
9
9
private usageSinceSubscriptionStarted = 0
10
10
private store : typeof Store
11
+ private totalCO2 = 0
11
12
12
13
constructor ( store : typeof Store ) {
13
14
this . store = store
15
+ setTimeout ( ( ) => {
16
+ chrome . notifications . create ( '' , {
17
+ title : 'Update on your usage' ,
18
+ message : `You have used ${ this . usageToday } bytes today` ,
19
+ type : 'basic' ,
20
+ iconUrl : './android-chrome-192x192.png'
21
+ } )
22
+ } , 5000 )
14
23
}
15
24
16
25
private getUsageLast7Days = async ( ) => {
@@ -26,6 +35,7 @@ export class UsageCounter {
26
35
if ( ! this . store . user ) return
27
36
const userDoc = await this . store . firestore . getUserDoc ( this . store . user . uid )
28
37
this . totalUsage = userDoc . totalSize
38
+ this . totalCO2 = userDoc . totalCO2
29
39
}
30
40
31
41
private listenToTodaysUsage = async ( ) => {
@@ -37,9 +47,19 @@ export class UsageCounter {
37
47
)
38
48
}
39
49
40
- private handleUsageUpdate = ( usage : number ) => {
41
- if ( ! this . usageToday ) this . usageToday = usage
42
- this . usageSinceSubscriptionStarted = usage - this . usageToday
50
+ private handleUsageUpdate = ( {
51
+ size,
52
+ CO2
53
+ } : {
54
+ size : number
55
+ CO2 : number
56
+ } ) => {
57
+ if ( ! this . usageToday ) this . usageToday = size
58
+ this . usageSinceSubscriptionStarted = size - this . usageToday
59
+ this . usageToday += this . usageSinceSubscriptionStarted
60
+ this . usageLast7Days += this . usageSinceSubscriptionStarted
61
+ this . totalUsage += this . usageSinceSubscriptionStarted
62
+ this . totalCO2 += CO2
43
63
this . sendUsageUpdate ( )
44
64
}
45
65
@@ -62,10 +82,10 @@ export class UsageCounter {
62
82
chrome . runtime . sendMessage ( {
63
83
type : MESSAGE_TYPES . SYNC_REQUESTS ,
64
84
payload : {
65
- usageToday : ( this . usageToday || 0 ) + this . usageSinceSubscriptionStarted ,
66
- usageLast7Days :
67
- this . usageLast7Days + this . usageSinceSubscriptionStarted ,
68
- totalUsage : this . totalUsage + this . usageSinceSubscriptionStarted
85
+ usageToday : this . usageToday ,
86
+ usageLast7Days : this . usageLast7Days ,
87
+ totalUsage : this . totalUsage ,
88
+ totalCO2 : this . totalCO2
69
89
}
70
90
} )
71
91
}
0 commit comments