2018-12-20 23:48:52 -08:00
|
|
|
import {app, ipcMain} from 'electron';
|
2018-12-20 23:03:20 -08:00
|
|
|
|
2018-12-04 18:30:16 -08:00
|
|
|
import TelemetryClient from './telemetry/TelemetryClient';
|
|
|
|
|
2018-12-20 23:48:52 -08:00
|
|
|
const APP_ID = 'scratch-desktop';
|
|
|
|
const APP_VERSION = app.getVersion();
|
|
|
|
const APP_INFO = Object.freeze({
|
|
|
|
projectName: `${APP_ID} ${APP_VERSION}`
|
|
|
|
});
|
2018-12-04 18:30:16 -08:00
|
|
|
|
|
|
|
class ScratchDesktopTelemetry {
|
|
|
|
constructor () {
|
|
|
|
this._telemetryClient = new TelemetryClient();
|
|
|
|
}
|
|
|
|
|
2018-12-20 23:03:20 -08:00
|
|
|
get didOptIn () {
|
|
|
|
return this._telemetryClient.didOptIn;
|
|
|
|
}
|
|
|
|
set didOptIn (value) {
|
|
|
|
this._telemetryClient.didOptIn = value;
|
|
|
|
}
|
|
|
|
|
2018-12-04 18:30:16 -08:00
|
|
|
appWasOpened () {
|
2018-12-20 23:48:52 -08:00
|
|
|
this._telemetryClient.addEvent('app::open', APP_INFO);
|
2018-12-04 18:30:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
appWillClose () {
|
2018-12-20 23:48:52 -08:00
|
|
|
this._telemetryClient.addEvent('app::close', APP_INFO);
|
2018-12-04 18:30:16 -08:00
|
|
|
}
|
|
|
|
|
2018-12-20 23:48:52 -08:00
|
|
|
projectDidLoad (metadata = {}) {
|
|
|
|
this._telemetryClient.addEvent('project::load', metadata);
|
2018-12-04 18:30:16 -08:00
|
|
|
}
|
|
|
|
|
2018-12-20 23:48:52 -08:00
|
|
|
projectDidSave (metadata = {}) {
|
|
|
|
this._telemetryClient.addEvent('project::save', metadata);
|
2018-12-04 18:30:16 -08:00
|
|
|
}
|
|
|
|
|
2018-12-20 23:48:52 -08:00
|
|
|
projectWasCreated (metadata = {}) {
|
|
|
|
this._telemetryClient.addEvent('project::create', metadata);
|
2018-12-04 18:30:16 -08:00
|
|
|
}
|
|
|
|
|
2018-12-20 23:48:52 -08:00
|
|
|
projectWasUploaded (metadata = {}) {
|
|
|
|
this._telemetryClient.addEvent('project::upload', metadata);
|
2018-12-04 18:30:16 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 23:03:20 -08:00
|
|
|
// make a singleton so it's easy to share across both Electron processes
|
|
|
|
const scratchDesktopTelemetrySingleton = new ScratchDesktopTelemetry();
|
|
|
|
|
|
|
|
ipcMain.on('getTelemetryDidOptIn', event => {
|
|
|
|
event.returnValue = scratchDesktopTelemetrySingleton.didOptIn;
|
|
|
|
});
|
|
|
|
ipcMain.on('setTelemetryDidOptIn', (event, arg) => {
|
|
|
|
scratchDesktopTelemetrySingleton.didOptIn = arg;
|
|
|
|
});
|
2018-12-20 23:48:52 -08:00
|
|
|
ipcMain.on('projectDidLoad', (event, arg) => {
|
|
|
|
scratchDesktopTelemetrySingleton.projectDidLoad(arg);
|
|
|
|
});
|
|
|
|
ipcMain.on('projectDidSave', (event, arg) => {
|
|
|
|
scratchDesktopTelemetrySingleton.projectDidSave(arg);
|
|
|
|
});
|
|
|
|
ipcMain.on('projectWasCreated', (event, arg) => {
|
|
|
|
scratchDesktopTelemetrySingleton.projectWasCreated(arg);
|
|
|
|
});
|
|
|
|
ipcMain.on('projectWasUploaded', (event, arg) => {
|
|
|
|
scratchDesktopTelemetrySingleton.projectWasUploaded(arg);
|
|
|
|
});
|
2018-12-20 23:03:20 -08:00
|
|
|
|
|
|
|
export default scratchDesktopTelemetrySingleton;
|