Hook up telemetry opt-in/out modal

This commit is contained in:
Christopher Willis-Ford 2018-12-20 23:03:20 -08:00
parent 30cafbf508
commit 64da5dff27
4 changed files with 32 additions and 5 deletions

View file

@ -1,3 +1,5 @@
import {ipcMain} from 'electron';
import TelemetryClient from './telemetry/TelemetryClient';
const info = {
@ -17,6 +19,13 @@ class ScratchDesktopTelemetry {
this._telemetryClient = new TelemetryClient();
}
get didOptIn () {
return this._telemetryClient.didOptIn;
}
set didOptIn (value) {
this._telemetryClient.didOptIn = value;
}
appWasOpened () {
this._telemetryClient.addEvent('app::open', info);
}
@ -42,4 +51,14 @@ class ScratchDesktopTelemetry {
}
}
export default ScratchDesktopTelemetry;
// 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;
});
export default scratchDesktopTelemetrySingleton;

View file

@ -1,9 +1,8 @@
import {BrowserWindow, app, dialog} from 'electron';
import * as path from 'path';
import {format as formatUrl} from 'url';
import ScratchDesktopTelemetry from './ScratchDesktopTelemetry';
import telemetry from './ScratchDesktopTelemetry';
const telemetry = new ScratchDesktopTelemetry();
telemetry.appWasOpened();

View file

@ -132,7 +132,8 @@ class TelemetryClient {
* @type {boolean}
*/
get didOptIn () {
return this._store.get('optIn', false);
// don't supply a default here: we want to track "opt out" separately from "undecided"
return this._store.get('optIn');
}
set didOptIn (value) {
this._store.set('optIn', !!value);

View file

@ -1,3 +1,4 @@
import {ipcRenderer} from 'electron';
import React from 'react';
import ReactDOM from 'react-dom';
import GUI, {AppStateHOC} from 'scratch-gui';
@ -42,7 +43,14 @@ const onStorageInit = storageInstance => {
const guiProps = {
onStorageInit,
isScratchDesktop: true,
projectId: defaultProjectId
projectId: defaultProjectId,
showTelemetryModal: (typeof ipcRenderer.sendSync('getTelemetryDidOptIn')) !== 'boolean',
onTelemetryModalOptIn: () => {
ipcRenderer.send('setTelemetryDidOptIn', true);
},
onTelemetryModalOptOut: () => {
ipcRenderer.send('setTelemetryDidOptIn', false);
}
};
const wrappedGui = React.createElement(WrappedGui, guiProps);
ReactDOM.render(wrappedGui, appTarget);