scratch-desktop/src/main/ScratchDesktopTelemetry.js

84 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-12-20 23:48:52 -08:00
import {app, ipcMain} from 'electron';
2018-12-20 23:03:20 -08:00
import TelemetryClient from './telemetry/TelemetryClient';
const EVENT_TEMPLATE = {
2018-12-21 10:34:06 -08:00
version: '3.0.0',
projectName: '',
language: '',
scriptCount: -1,
spriteCount: -1,
variablesCount: -1,
blocksCount: -1,
costumesCount: -1,
listsCount: -1,
soundsCount: -1
};
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}`
});
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;
}
appWasOpened () {
this._telemetryClient.addEvent('app::open', {...EVENT_TEMPLATE, ...APP_INFO});
}
appWillClose () {
this._telemetryClient.addEvent('app::close', {...EVENT_TEMPLATE, ...APP_INFO});
}
2018-12-20 23:48:52 -08:00
projectDidLoad (metadata = {}) {
this._telemetryClient.addEvent('project::load', {...EVENT_TEMPLATE, ...metadata});
}
2018-12-20 23:48:52 -08:00
projectDidSave (metadata = {}) {
this._telemetryClient.addEvent('project::save', {...EVENT_TEMPLATE, ...metadata});
}
2018-12-20 23:48:52 -08:00
projectWasCreated (metadata = {}) {
this._telemetryClient.addEvent('project::create', {...EVENT_TEMPLATE, ...metadata});
}
2018-12-20 23:48:52 -08:00
projectWasUploaded (metadata = {}) {
this._telemetryClient.addEvent('project::upload', {...EVENT_TEMPLATE, ...metadata});
}
}
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;