Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
Add data collection privacy consent dialog (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
quanglam2807 authored Jan 25, 2021
1 parent 762c7bc commit 2493a1a
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 59 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"electron-settings": "4.0.2",
"electron-updater": "4.3.7",
"electron-window-state": "5.0.3",
"fs-extra": "9.0.1",
"menubar": "9.0.1",
"fs-extra": "9.1.0",
"menubar": "9.0.2",
"node-fetch": "2.6.1",
"node-mac-permissions": "2.2.0",
"node-machine-id": "1.1.12"
Expand All @@ -51,7 +51,7 @@
"cross-env": "7.0.3",
"del": "6.0.0",
"dotenv": "8.2.0",
"electron": "11.2.0",
"electron": "11.2.1",
"electron-builder": "22.10.4",
"eslint": "6.8.0",
"eslint-config-airbnb": "18.2.1",
Expand Down
4 changes: 2 additions & 2 deletions patches/menubar+9.0.1.patch → patches/menubar+9.0.2.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/node_modules/menubar/lib/Menubar.js b/node_modules/menubar/lib/Menubar.js
index 5f921d3..09125b4 100644
index c2621f4..7174857 100644
--- a/node_modules/menubar/lib/Menubar.js
+++ b/node_modules/menubar/lib/Menubar.js
@@ -359,7 +359,10 @@ var Menubar = /** @class */ (function (_super) {
@@ -353,7 +353,10 @@ var Menubar = /** @class */ (function (_super) {
}, 100));
});
if (this._options.showOnAllWorkspaces !== false) {
Expand Down
50 changes: 20 additions & 30 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const {
ipcMain,
nativeImage,
nativeTheme,
shell,
} = require('electron');
const isDev = require('electron-is-dev');
const settings = require('electron-settings');
Expand All @@ -29,15 +28,16 @@ const url = require('url');
const { menubar } = require('menubar');
const windowStateKeeper = require('electron-window-state');

const { getPreference, setPreference } = require('./libs/preferences');

// Activate the Sentry Electron SDK as early as possible in every process.
if (!isDev) {
if (!isDev && getPreference('sentry')) {
// eslint-disable-next-line global-require
require('./libs/sentry');
}

const { createMenu, showMenu } = require('./libs/menu');
const loadListeners = require('./listeners');
const { getPreference } = require('./libs/preferences');
const { initLocales, getLocale } = require('./libs/locales');
const sendToAllWindows = require('./libs/send-to-all-windows');
const setContextMenu = require('./libs/set-context-menu');
Expand Down Expand Up @@ -360,35 +360,25 @@ if (!gotTheLock) {

createWindowAsync()
.then(() => {
if (isDev) return; // dev environment
// Mac
if (process.platform === 'darwin' && !process.mas) {
dialog.showMessageBox({
type: 'question',
buttons: ['Learn More...', 'OK'],
message: 'The direct download version of Translatium will no longer be updated. Please get the app from the Mac App Store instead.',
cancelId: 1,
})
.then(({ response }) => {
if (response === 0) {
shell.openExternal('https://translatium.app/download/mac?utm_source=mac-dmg');
}
})
.catch(console.log); // eslint-disable-line no-console
// Windows
} else if (process.platform === 'win32' && !process.windowsStore) {
dialog.showMessageBox({
const privacyConsentAsked = getPreference('privacyConsentAsked');
if (!privacyConsentAsked) {
dialog.showMessageBox(mainWindow, {
type: 'question',
buttons: ['Learn More...', 'OK'],
message: 'The direct download version of Translatium will no longer be updated. Please get the app from the Microsoft Store instead.',
buttons: [getLocale('allow'), getLocale('dontAllow')],
message: getLocale('privacyConsentMessage'),
detail: getLocale('privacyConsentDetail'),
cancelId: 1,
})
.then(({ response }) => {
if (response === 0) {
shell.openExternal('https://translatium.app/download/windows?utm_source=windows-nsis');
}
})
.catch(console.log); // eslint-disable-line no-console
defaultId: 0,
}).then(({ response }) => {
// setPreference('privacyConsentAsked', true);
if (response === 0) {
setPreference('sentry', true);
setPreference('telemetry', true);
} else {
setPreference('sentry', false);
setPreference('telemetry', false);
}
}).catch(console.log); // eslint-disable-line
}
});
createMenu();
Expand Down
8 changes: 7 additions & 1 deletion public/libs/locales/de/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,11 @@
"historyDesc": "Hier zuvor übersetzte Wörter und Redewendungen anzeigen.",
"clearHistory": "Verlauf löschen",
"reset": "Zurücksetzen",
"restorePreferencesToDefault": "Einstellungen auf ihre ursprünglichen Standardwerte zurücksetzen"
"restorePreferencesToDefault": "Einstellungen auf ihre ursprünglichen Standardwerte zurücksetzen",
"privacyConsentMessage": "Können wir anonyme Nutzungsstatistiken und Absturzberichte erfassen?",
"privacyConsentDetail": "Die Daten helfen uns, das Produkt zu verbessern und zu optimieren. Sie können Ihre Entscheidung jederzeit in den Einstellungen der App ändern.",
"allow": "Erlauben",
"dontAllow": "Nicht Erlauben",
"allowCrashReports": "Erlaube der App anonyme Absturzberichte zu senden",
"allowTelemetry": "Erlaube der App anonyme Nutzungsdaten zu senden"
}
8 changes: 7 additions & 1 deletion public/libs/locales/en/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,11 @@
"historyDesc": "View previously translated words and phrases here.",
"clearHistory": "Clear history",
"reset": "Reset",
"restorePreferencesToDefault": "Restore preferences to their original defaults"
"restorePreferencesToDefault": "Restore preferences to their original defaults",
"privacyConsentMessage": "Can we collect anonymous usage statistics and crash reports?",
"privacyConsentDetail": "The data helps us improve and optimize the product. You can change your decision at any time in the app’s preferences.",
"allow": "Allow",
"dontAllow": "Don't Allow",
"allowCrashReports": "Allow the app to send anonymous crash reports",
"allowTelemetry": "Allow the app to send anonymous usage data"
}
8 changes: 7 additions & 1 deletion public/libs/locales/es/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,11 @@
"historyDesc": "Vea aquí las palabras y frases traducidas anteriormente.",
"clearHistory": "Borrar historial",
"reset": "Restablecer",
"restorePreferencesToDefault": "Restaurar las preferencias a sus valores predeterminados originales"
"restorePreferencesToDefault": "Restaurar las preferencias a sus valores predeterminados originales",
"privacyConsentMessage": "¿Podemos recopilar estadísticas de uso e informes de fallos anónimos?",
"privacyConsentDetail": "Los datos nos ayudan a mejorar y optimizar el producto. Puede cambiar su decisión en cualquier momento en las preferencias de la aplicación.",
"allow": "Permitir",
"dontAllow": "No Permitir",
"allowCrashReports": "Permitir que la aplicación envíe informes de fallos anónimos",
"allowTelemetry": "Permitir que la aplicación envíe datos de uso anónimos"
}
8 changes: 7 additions & 1 deletion public/libs/locales/fr/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,11 @@
"historyDesc": "Consultez les mots et phrases précédemment traduits ici.",
"clearHistory": "Effacer l'historique",
"reset": "Réinitialiser",
"restorePreferencesToDefault": "Restaurer les préférences à leurs valeurs par défaut"
"restorePreferencesToDefault": "Restaurer les préférences à leurs valeurs par défaut",
"privacyConsentMessage": "Pouvons-nous collecter des statistiques d'utilisation anonymes et des rapports de plantage ?",
"privacyConsentDetail": "Les données nous aident à améliorer et à optimiser le produit. Vous pouvez modifier votre décision à tout moment dans les préférences de l'application.",
"allow": "Permettre",
"dontAllow": "Ne Pas Autoriser",
"allowCrashReports": "Autoriser l'application à envoyer des rapports de plantage anonymes",
"allowTelemetry": "Autoriser l'application à envoyer des données d'utilisation anonymes"
}
8 changes: 7 additions & 1 deletion public/libs/locales/it/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,11 @@
"historyDesc": "Visualizzare qui parole e frasi tradotte in precedenza.",
"clearHistory": "Cancellare cronologia",
"reset": "Reimpostare",
"restorePreferencesToDefault": "Ripristinare le preferenze ai valori predefiniti originali"
"restorePreferencesToDefault": "Ripristinare le preferenze ai valori predefiniti originali",
"privacyConsentMessage": "Possiamo raccogliere statistiche anonime sull'utilizzo e rapporti sui crash?",
"privacyConsentDetail": "I dati ci aiutano a migliorare e ottimizzare il prodotto. Puoi modificare la tua decisione in qualsiasi momento nelle preferenze dell'app.",
"allow": "Consentire",
"dontAllow": "Non Consentire",
"allowCrashReports": "Consenti all'app di inviare rapporti anonimi sui crash",
"allowTelemetry": "Consenti all'app di inviare dati anonimi sull'utilizzo"
}
8 changes: 7 additions & 1 deletion public/libs/locales/ko/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,11 @@
"historyDesc": "이전에 번역된 단어와 구를 여기서 보세요..",
"clearHistory": "기록 지우기",
"reset": "재설정",
"restorePreferencesToDefault": "기본 설정을 원래 기본값으로 복원"
"restorePreferencesToDefault": "기본 설정을 원래 기본값으로 복원",
"privacyConsentMessage": "당사에서 익명의 사용 통계 및 충돌 보고서를 수집할 수 있습니까?",
"privacyConsentDetail": "데이터는 제품을 개선하고 최적화하는 데 도움이 됩니다. 앱의 기본 설정에서 언제든지 변경할 수 있습니다.",
"allow": "허용",
"dontAllow": "허용안함",
"allowCrashReports": "앱이 익명의 충돌 보고서를 보내도록 허용",
"allowTelemetry": "앱이 익명의 사용 데이터를 보내도록 허용"
}
8 changes: 7 additions & 1 deletion public/libs/locales/ru/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,11 @@
"historyDesc": "Здесь можно посмотреть ранее переведенные слова и фразы.",
"clearHistory": "Очистить журнал",
"reset": "Сброс настроек",
"restorePreferencesToDefault": "Восстановить настройки по умолчанию"
"restorePreferencesToDefault": "Восстановить настройки по умолчанию",
"privacyConsentMessage": "Разрешаете ли вы нам собирать анонимную статистику использования и отчеты о сбоях?",
"privacyConsentDetail": "Эти данные помогают улучшать и оптимизировать продукт. Отозвать разрешение можно в любой момент в настройках приложения.",
"allow": "Разрешить",
"dontAllow": "Не разрешать",
"allowCrashReports": "Разрешить приложению отправлять анонимные отчеты о сбоях",
"allowTelemetry": "Разрешить приложению отправлять анонимные данные об использовании"
}
8 changes: 7 additions & 1 deletion public/libs/locales/vi/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,11 @@
"historyDesc": "Xem các từ và cụm từ đã dịch trong quá khứ tại đây.",
"clearHistory": "Xóa lịch sử",
"reset": "Thiết đặt lại",
"restorePreferencesToDefault": "Khôi phục tùy chọn về trạng thái ban đầu"
"restorePreferencesToDefault": "Khôi phục tùy chọn về trạng thái ban đầu",
"privacyConsentMessage": "Chúng tôi có thể thu thập dữ liệu sử dụng và báo cáo sự cố nặc danh không?",
"privacyConsentDetail": "Dữ liệu này giúp chúng tôi cải thiện và tối ưu hóa sản phẩm. Bạn có thể thay đổi quyết định của mình bất kỳ lúc nào trong tùy chọn của ứng dụng.",
"allow": "Cho phép",
"dontAllow": "Không cho phép",
"allowCrashReports": "Cho phép ứng dụng gửi báo cáo sự cố nặc danh",
"allowTelemetry": "Cho phép ứng dụng gửi dữ liệu sử dụng nặc danh"
}
8 changes: 7 additions & 1 deletion public/libs/locales/zh-CN/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,11 @@
"historyDesc": "在此处查看先前翻译的单词和短语。",
"clearHistory": "清除历史记录",
"reset": "重置",
"restorePreferencesToDefault": "将首选项恢复为原始默认值"
"restorePreferencesToDefault": "将首选项恢复为原始默认值",
"privacyConsentMessage": "我们可以收集匿名使用情况统计数据和崩溃报告吗?",
"privacyConsentDetail": "这些数据帮助我们改进和优化产品。您可以随时在应用程序的首选项中更改您的决定。",
"allow": "允许",
"dontAllow": "不允许",
"allowCrashReports": "允许该应用程序发送匿名崩溃报告",
"allowTelemetry": "允许该应用程序发送匿名使用情况数据"
}
5 changes: 4 additions & 1 deletion public/libs/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ const defaultPreferences = {
inputLang: 'en',
openOnMenubarShortcut: 'alt+shift+t',
outputLang: 'zh-CN',
ratingCardLastClicked: 0,
privacyConsentAsked: false,
ratingCardDidRate: false,
ratingCardLastClicked: 0,
recentLanguages: ['en', 'zh-CN'],
sentry: false,
showTransliteration: true,
telemetry: false,
themeSource: 'system',
translateClipboardOnShortcut: false,
translateWhenPressingEnter: true,
Expand Down
3 changes: 2 additions & 1 deletion public/preload/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const isDev = require('electron-is-dev');
const machineId = require('node-machine-id');

// Activate the Sentry Electron SDK as early as possible in every process.
if (!isDev) {
if (!isDev && ipcRenderer.sendSync('get-preference', 'sentry')) {
// eslint-disable-next-line global-require
require('../libs/sentry');
}
Expand All @@ -23,4 +23,5 @@ window.ipcRenderer = ipcRenderer;
window.desktopCapturer = desktopCapturer;

window.machineId = machineId.machineIdSync();
window.optOutTelemetry = !ipcRenderer.sendSync('get-preference', 'telemetry');
window.macPermissions = process.platform === 'darwin' ? require('node-mac-permissions') : null;
1 change: 1 addition & 0 deletions src/amplitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { v5 as uuidv5 } from 'uuid';

amplitude.getInstance().init(process.env.REACT_APP_AMPLITUDE_API_KEY);
amplitude.getInstance().setVersionName(window.remote.app.getVersion());
amplitude.getInstance().setOptOut(window.optOutTelemetry);

// custom device id based on WebCatalog code
// to have some control over device id
Expand Down
40 changes: 40 additions & 0 deletions src/components/pages/preferences/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ const Preferences = (props) => {
onToggleSetting,
openAtLogin,
openOnMenubarShortcut,
sentry,
showTransliteration,
telemetry,
themeSource,
translateClipboardOnShortcut,
translateWhenPressingEnter,
Expand Down Expand Up @@ -355,6 +357,40 @@ const Preferences = (props) => {
/>
</ListItemSecondaryAction>
</ListItem>
<Divider />
<ListItem>
<ListItemText
primary={getLocale('allowCrashReports')}
/>
<ListItemSecondaryAction>
<Switch
edge="end"
color="primary"
checked={sentry}
onChange={(e) => {
requestSetPreference('sentry', e.target.checked);
requestShowRequireRestartDialog();
}}
/>
</ListItemSecondaryAction>
</ListItem>
<Divider />
<ListItem>
<ListItemText
primary={getLocale('allowTelemetry')}
/>
<ListItemSecondaryAction>
<Switch
edge="end"
color="primary"
checked={telemetry}
onChange={(e) => {
requestSetPreference('telemetry', e.target.checked);
requestShowRequireRestartDialog();
}}
/>
</ListItemSecondaryAction>
</ListItem>
</List>
</Paper>

Expand Down Expand Up @@ -472,7 +508,9 @@ Preferences.propTypes = {
onToggleSetting: PropTypes.func.isRequired,
openAtLogin: PropTypes.oneOf(['yes', 'yes-hidden', 'no']).isRequired,
openOnMenubarShortcut: PropTypes.string,
sentry: PropTypes.bool.isRequired,
showTransliteration: PropTypes.bool.isRequired,
telemetry: PropTypes.bool.isRequired,
themeSource: PropTypes.string.isRequired,
translateClipboardOnShortcut: PropTypes.bool.isRequired,
translateWhenPressingEnter: PropTypes.bool.isRequired,
Expand All @@ -485,7 +523,9 @@ const mapStateToProps = (state) => ({
displayLanguage: state.preferences.displayLanguage,
openAtLogin: state.systemPreferences.openAtLogin,
openOnMenubarShortcut: state.preferences.openOnMenubarShortcut,
sentry: state.preferences.sentry,
showTransliteration: state.preferences.showTransliteration,
telemetry: state.preferences.telemetry,
themeSource: state.preferences.themeSource,
translateClipboardOnShortcut: state.preferences.translateClipboardOnShortcut,
translateWhenPressingEnter: state.preferences.translateWhenPressingEnter,
Expand Down
Loading

0 comments on commit 2493a1a

Please sign in to comment.