mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 18:32:20 +08:00
[client-app] Report battery state changes to Mixpanel
Summary: This diff will give us insight into how people use Nylas Mail on their computers with respect to how mobile they are (i.e. whether they use NM on battery or plugged in). Test Plan: Run locally Reviewers: evan, spang, juan Reviewed By: juan Subscribers: gleb Differential Revision: https://phab.nylas.com/D4267
This commit is contained in:
parent
0508180712
commit
da018c3639
1 changed files with 9 additions and 0 deletions
|
@ -1,8 +1,11 @@
|
|||
import moment from 'moment-timezone'
|
||||
import Actions from '../flux/actions'
|
||||
|
||||
class BatteryStatusManager {
|
||||
constructor() {
|
||||
this._callbacks = [];
|
||||
this._battery = null;
|
||||
this._lastChangeTime = Date.now();
|
||||
}
|
||||
|
||||
async activate() {
|
||||
|
@ -22,6 +25,12 @@ class BatteryStatusManager {
|
|||
}
|
||||
|
||||
_onChargingChange = () => {
|
||||
const changeTime = Date.now();
|
||||
Actions.recordUserEvent("Battery State Changed", {
|
||||
oldState: this.isBatteryCharging() ? 'battery' : 'ac',
|
||||
oldStateDuration: Math.min(changeTime - this._lastChangeTime, moment.duration(12, 'hours').asMilliseconds()),
|
||||
});
|
||||
this._lastChangeTime = changeTime;
|
||||
this._callbacks.forEach(cb => cb());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue