Permalink
Browse files

feat(App): Add option to enable/disable spell checker

  • Loading branch information...
adlk committed Nov 14, 2017
1 parent 430e9a3 commit dcab45a323f53a10ff5f419daa5ba6442817eebc
@@ -74,7 +74,6 @@ export default class SettingsNavigation extends Component {
<Link
to="/auth/logout"
className="settings-navigation__link"
activeClassName="is-active"
>
{intl.formatMessage(messages.logout)}
</Link>
@@ -30,9 +30,9 @@ const messages = defineMessages({
id: 'settings.app.headlineAppearance',
defaultMessage: '!!!Appearance',
},
headlineMessaging: {
id: 'settings.app.headlineMessaging',
defaultMessage: '!!!Messaging',
headlineAdvanced: {
id: 'settings.app.headlineAdvanced',
defaultMessage: '!!!Advanced',
},
buttonSearchForUpdate: {
id: 'settings.app.buttonSearchForUpdate',
@@ -58,6 +58,10 @@ const messages = defineMessages({
id: 'settings.app.currentVersion',
defaultMessage: '!!!Current version:',
},
restartRequired: {
id: 'settings.app.restartRequired',
defaultMessage: '!!!Changes require restart',
},
});
@observer
@@ -120,20 +124,31 @@ export default class EditSettingsForm extends Component {
onChange={e => this.submit(e)}
id="form"
>
<h2>{intl.formatMessage(messages.headlineGeneral)}</h2>
{/* General */}
<h2 id="general">{intl.formatMessage(messages.headlineGeneral)}</h2>
<Toggle field={form.$('autoLaunchOnStart')} />
<Toggle field={form.$('runInBackground')} />
<Toggle field={form.$('enableSystemTray')} />
{process.platform === 'win32' && (
<Toggle field={form.$('minimizeToSystemTray')} />
)}
<h2>{intl.formatMessage(messages.headlineAppearance)}</h2>
{/* Appearance */}
<h2 id="apperance">{intl.formatMessage(messages.headlineAppearance)}</h2>
<Toggle field={form.$('showDisabledServices')} />
<h2>{intl.formatMessage(messages.headlineMessaging)}</h2>
<Toggle field={form.$('enableSpellchecking')} />
<h2>{intl.formatMessage(messages.headlineLanguage)}</h2>
{/* Language */}
<h2 id="language">{intl.formatMessage(messages.headlineLanguage)}</h2>
<Select field={form.$('locale')} showLabel={false} />
<h2>{intl.formatMessage(messages.headlineUpdates)}</h2>
{/* Advanced */}
<h2 id="advanced">{intl.formatMessage(messages.headlineAdvanced)}</h2>
<Toggle field={form.$('enableSpellchecking')} />
<p className="settings__help">{intl.formatMessage(messages.restartRequired)}</p>
{/* <Select field={form.$('spellcheckingLanguage')} /> */}
{/* Updates */}
<h2 id="updates">{intl.formatMessage(messages.headlineUpdates)}</h2>
{updateIsReadyToInstall ? (
<Button
label={intl.formatMessage(messages.buttonInstallUpdate)}
@@ -12,6 +12,7 @@ export const DEFAULT_APP_SETTINGS = {
minimizeToSystemTray: false,
showDisabledServices: true,
enableSpellchecking: true,
// spellcheckingLanguage: 'auto',
locale: 'en-US',
beta: false,
isAppMuted: false,
@@ -7,7 +7,7 @@ import AppStore from '../../stores/AppStore';
import SettingsStore from '../../stores/SettingsStore';
import UserStore from '../../stores/UserStore';
import Form from '../../lib/Form';
import languages from '../../i18n/languages';
import { APP_LOCALES } from '../../i18n/languages';
import { gaPage } from '../../lib/analytics';
import { DEFAULT_APP_SETTINGS } from '../../config';
@@ -47,6 +47,14 @@ const messages = defineMessages({
id: 'settings.app.form.enableSpellchecking',
defaultMessage: '!!!Enable spell checking',
},
spellcheckingLanguage: {
id: 'settings.app.form.spellcheckingLanguage',
defaultMessage: '!!!Language for spell checking',
},
// spellcheckingAutomaticDetection: {
// id: 'settings.app.form.spellcheckingAutomaticDetection',
// defaultMessage: '!!!Detect language automatically',
// },
beta: {
id: 'settings.app.form.beta',
defaultMessage: '!!!Include beta versions',
@@ -78,6 +86,7 @@ export default class EditSettingsScreen extends Component {
minimizeToSystemTray: settingsData.minimizeToSystemTray,
showDisabledServices: settingsData.showDisabledServices,
enableSpellchecking: settingsData.enableSpellchecking,
// spellcheckingLanguage: settingsData.spellcheckingLanguage,
locale: settingsData.locale,
beta: settingsData.beta,
},
@@ -94,14 +103,25 @@ export default class EditSettingsScreen extends Component {
const { app, settings, user } = this.props.stores;
const { intl } = this.context;
const options = [];
Object.keys(languages).forEach((key) => {
options.push({
const locales = [];
Object.keys(APP_LOCALES).forEach((key) => {
locales.push({
value: key,
label: languages[key],
label: APP_LOCALES[key],
});
});
// const spellcheckerLocales = [{
// value: 'auto',
// label: intl.formatMessage(messages.spellcheckingAutomaticDetection),
// }];
// Object.keys(SPELLCHECKER_LOCALES).forEach((key) => {
// spellcheckerLocales.push({
// value: key,
// label: SPELLCHECKER_LOCALES[key],
// });
// });
const config = {
fields: {
autoLaunchOnStart: {
@@ -139,10 +159,16 @@ export default class EditSettingsScreen extends Component {
value: settings.all.enableSpellchecking,
default: DEFAULT_APP_SETTINGS.enableSpellchecking,
},
// spellcheckingLanguage: {
// label: intl.formatMessage(messages.spellcheckingLanguage),
// value: settings.all.spellcheckingLanguage,
// options: spellcheckerLocales,
// default: DEFAULT_APP_SETTINGS.spellcheckingLanguage,
// },
locale: {
label: intl.formatMessage(messages.language),
value: app.locale,
options,
options: locales,
default: DEFAULT_APP_SETTINGS.locale,
},
beta: {
@@ -1,4 +1,4 @@
module.exports = {
export const APP_LOCALES = {
'en-US': 'English',
'pt-BR': 'Portuguese (Brazil)',
'el-GR': 'Ελληνικά (Greece)',
@@ -15,3 +15,46 @@ module.exports = {
'zh-Hant': 'Chinese (Traditional)',
'nb-NO': 'Norsk',
};
export default APP_LOCALES;
// export const SPELLCHECKER_LOCALES = {
// af: 'Afrikaans',
// sq: 'Albanian',
// ar: 'Arabic',
// bg: 'Bulgarian',
// zh: 'Chinese',
// hr: 'Croatian',
// cs: 'Czech',
// da: 'Danish',
// nl: 'Dutch',
// en: 'English',
// 'en-AU': 'English (AU)',
// 'en-CA': 'English (CA)',
// 'en-GB': 'English (GB)',
// fi: 'Finnish',
// fr: 'French',
// ka: 'Georgian',
// de: 'German',
// el: 'Greek, Modern',
// hi: 'Hindi',
// hu: 'Hungarian',
// id: 'Indonesian',
// it: 'Italian',
// ja: 'Japanese',
// jv: 'Javanese',
// ko: 'Korean',
// lt: 'Lithuanian',
// lv: 'Latvian',
// ms: 'Malay',
// no: 'Norwegian',
// pl: 'Polish',
// pt: 'Portuguese',
// ro: 'Romanian, Moldavian, Moldovan',
// ru: 'Russian',
// sk: 'Slovak',
// es: 'Spanish',
// sv: 'Swedish',
// uk: 'Ukrainian',
// vi: 'Vietnamese',
// };
@@ -132,6 +132,7 @@
"settings.app.headlineLanguage": "Language",
"settings.app.headlineUpdates": "Updates",
"settings.app.headlineAppearance": "Appearance",
"settings.app.headlineAdvanced": "Advanced",
"settings.app.buttonSearchForUpdate": "Check for updates",
"settings.app.buttonInstallUpdate": "Restart & install update",
"settings.app.updateStatusSearching": "Is searching for update",
@@ -143,9 +144,11 @@
"settings.app.form.minimizeToSystemTray": "Minimize Franz to system tray",
"settings.app.form.runInBackground": "Keep Franz in background when closing the window",
"settings.app.form.language": "Language",
"settings.app.form.enableSpellchecking": "Enable spell checking",
"settings.app.form.showDisabledServices": "Display disabled services tabs",
"settings.app.form.beta": "Include beta versions",
"settings.app.currentVersion": "Current version:",
"settings.app.restartRequired": "Changes require restart",
"settings.user.form.firstname": "Firstname",
"settings.user.form.lastname": "Lastname",
"settings.user.form.email": "Email",
@@ -1,7 +1,7 @@
import languages from './languages';
import { APP_LOCALES } from './languages';
const translations = [];
Object.keys(languages).forEach((key) => {
Object.keys(APP_LOCALES).forEach((key) => {
try {
const translation = require(`./locales/${key}.json`); // eslint-disable-line
translations[key] = translation;
@@ -286,6 +286,7 @@ export default class ServicesStore extends Store {
if (channel === 'hello') {
this._initRecipePolling(service.id);
this._initializeServiceRecipeInWebview(serviceId);
this._shareSettingsWithServiceProcess();
} else if (channel === 'messages') {
this.actions.service.setUnreadMessageCount({
serviceId,
@@ -3,10 +3,12 @@ import path from 'path';
import RecipeWebview from './lib/RecipeWebview';
import './spellchecker.js';
import Spellchecker from './spellchecker.js';
import './notifications.js';
import './ime.js';
const spellchecker = new Spellchecker();
ipcRenderer.on('initializeRecipe', (e, data) => {
const modulePath = path.join(data.recipe.path, 'webview.js');
// Delete module from cache
@@ -20,7 +22,17 @@ ipcRenderer.on('initializeRecipe', (e, data) => {
});
ipcRenderer.on('settings-update', (e, data) => {
console.log(data);
if (data.enableSpellchecking) {
if (!spellchecker.isEnabled) {
spellchecker.enable();
// TODO: this does not work yet, needs more testing
// if (data.spellcheckingLanguage !== 'auto') {
// console.log('set spellchecking language to', data.spellcheckingLanguage);
// spellchecker.switchLanguage(data.spellcheckingLanguage);
// }
}
}
});
document.addEventListener('DOMContentLoaded', () => {
@@ -1,14 +1,30 @@
import { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } from 'electron-spellchecker';
window.spellCheckHandler = new SpellCheckHandler();
setTimeout(() => {
window.spellCheckHandler.attachToInput();
}, 1000);
// TODO: should we set the language to user settings?
// window.spellCheckHandler.switchLanguage('en-US');
const contextMenuBuilder = new ContextMenuBuilder(window.spellCheckHandler);
const contextMenuListener = new ContextMenuListener((info) => { // eslint-disable-line
contextMenuBuilder.showPopupMenu(info);
});
import { isMac } from '../environment';
export default class Spellchecker {
isEnabled = false;
spellchecker = null;
enable() {
this.spellchecker = new SpellCheckHandler();
if (!isMac) {
this.spellchecker.attachToInput();
this.spellchecker.switchLanguage(navigator.language);
}
const contextMenuBuilder = new ContextMenuBuilder(this.spellchecker);
new ContextMenuListener((info) => { // eslint-disable-line
contextMenuBuilder.showPopupMenu(info);
});
}
// TODO: this does not work yet, needs more testing
// switchLanguage(language) {
// if (language !== 'auto') {
// this.spellchecker.switchLanguage(language);
// }
// }
}

0 comments on commit dcab45a

Please sign in to comment.