[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:
Mark Hahnenberg 2017-03-27 14:05:36 -07:00
parent 0508180712
commit da018c3639

View file

@ -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());
}