Skip to content

Commit

Permalink
feat(App): Add option to enable/disable spell checker
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Nov 14, 2017
1 parent 430e9a3 commit dcab45a
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/components/settings/navigation/SettingsNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
33 changes: 24 additions & 9 deletions src/components/settings/settings/EditSettingsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -58,6 +58,10 @@ const messages = defineMessages({
id: 'settings.app.currentVersion',
defaultMessage: '!!!Current version:',
},
restartRequired: {
id: 'settings.app.restartRequired',
defaultMessage: '!!!Changes require restart',
},
});

@observer
Expand Down Expand Up @@ -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)}
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const DEFAULT_APP_SETTINGS = {
minimizeToSystemTray: false,
showDisabledServices: true,
enableSpellchecking: true,
// spellcheckingLanguage: 'auto',
locale: 'en-US',
beta: false,
isAppMuted: false,
Expand Down
38 changes: 32 additions & 6 deletions src/containers/settings/EditSettingsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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,
},
Expand All @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
45 changes: 44 additions & 1 deletion src/i18n/languages.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export const APP_LOCALES = {
'en-US': 'English',
'pt-BR': 'Portuguese (Brazil)',
'el-GR': 'Ελληνικά (Greece)',
Expand All @@ -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',
// };
3 changes: 3 additions & 0 deletions src/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/i18n/translations.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/stores/ServicesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 14 additions & 2 deletions src/webview/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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', () => {
Expand Down
40 changes: 28 additions & 12 deletions src/webview/spellchecker.js
Original file line number Diff line number Diff line change
@@ -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.