aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2017-11-15 11:10:40 +0100
committerLibravatar GitHub <noreply@github.com>2017-11-15 11:10:40 +0100
commitabfad99bd4bb9db8697322d141c2cf57e9213172 (patch)
treecd4be4f7552341687cfa1e30bbed57abcbda6bc8 /src
parentMerge pull request #277 from meetfranz/feature/pricing-info (diff)
parentfix weird settings navigation styles (diff)
downloadferdium-app-abfad99bd4bb9db8697322d141c2cf57e9213172.tar.gz
ferdium-app-abfad99bd4bb9db8697322d141c2cf57e9213172.tar.zst
ferdium-app-abfad99bd4bb9db8697322d141c2cf57e9213172.zip
Merge pull request #276 from meetfranz/feature/spellcheck-settings
Spellcheck settings
Diffstat (limited to 'src')
-rw-r--r--src/actions/service.js4
-rw-r--r--src/components/settings/navigation/SettingsNavigation.js1
-rw-r--r--src/components/settings/settings/EditSettingsForm.js29
-rw-r--r--src/config.js2
-rw-r--r--src/containers/settings/EditSettingsScreen.js48
-rw-r--r--src/i18n/languages.js45
-rw-r--r--src/i18n/locales/en-US.json3
-rw-r--r--src/i18n/translations.js4
-rw-r--r--src/stores/ServicesStore.js22
-rw-r--r--src/styles/settings.scss5
-rw-r--r--src/webview/plugin.js28
-rw-r--r--src/webview/spellchecker.js40
12 files changed, 196 insertions, 35 deletions
diff --git a/src/actions/service.js b/src/actions/service.js
index 1b918251b..e3100e986 100644
--- a/src/actions/service.js
+++ b/src/actions/service.js
@@ -50,6 +50,10 @@ export default {
50 channel: PropTypes.string.isRequired, 50 channel: PropTypes.string.isRequired,
51 args: PropTypes.object.isRequired, 51 args: PropTypes.object.isRequired,
52 }, 52 },
53 sendIPCMessageToAllServices: {
54 channel: PropTypes.string.isRequired,
55 args: PropTypes.object.isRequired,
56 },
53 openWindow: { 57 openWindow: {
54 event: PropTypes.object.isRequired, 58 event: PropTypes.object.isRequired,
55 }, 59 },
diff --git a/src/components/settings/navigation/SettingsNavigation.js b/src/components/settings/navigation/SettingsNavigation.js
index 3b21a7765..fea8d682d 100644
--- a/src/components/settings/navigation/SettingsNavigation.js
+++ b/src/components/settings/navigation/SettingsNavigation.js
@@ -74,7 +74,6 @@ export default class SettingsNavigation extends Component {
74 <Link 74 <Link
75 to="/auth/logout" 75 to="/auth/logout"
76 className="settings-navigation__link" 76 className="settings-navigation__link"
77 activeClassName="is-active"
78 > 77 >
79 {intl.formatMessage(messages.logout)} 78 {intl.formatMessage(messages.logout)}
80 </Link> 79 </Link>
diff --git a/src/components/settings/settings/EditSettingsForm.js b/src/components/settings/settings/EditSettingsForm.js
index ba07b1a5b..601d57c81 100644
--- a/src/components/settings/settings/EditSettingsForm.js
+++ b/src/components/settings/settings/EditSettingsForm.js
@@ -30,6 +30,10 @@ const messages = defineMessages({
30 id: 'settings.app.headlineAppearance', 30 id: 'settings.app.headlineAppearance',
31 defaultMessage: '!!!Appearance', 31 defaultMessage: '!!!Appearance',
32 }, 32 },
33 headlineAdvanced: {
34 id: 'settings.app.headlineAdvanced',
35 defaultMessage: '!!!Advanced',
36 },
33 buttonSearchForUpdate: { 37 buttonSearchForUpdate: {
34 id: 'settings.app.buttonSearchForUpdate', 38 id: 'settings.app.buttonSearchForUpdate',
35 defaultMessage: '!!!Check for updates', 39 defaultMessage: '!!!Check for updates',
@@ -54,6 +58,10 @@ const messages = defineMessages({
54 id: 'settings.app.currentVersion', 58 id: 'settings.app.currentVersion',
55 defaultMessage: '!!!Current version:', 59 defaultMessage: '!!!Current version:',
56 }, 60 },
61 restartRequired: {
62 id: 'settings.app.restartRequired',
63 defaultMessage: '!!!Changes require restart',
64 },
57}); 65});
58 66
59@observer 67@observer
@@ -116,18 +124,31 @@ export default class EditSettingsForm extends Component {
116 onChange={e => this.submit(e)} 124 onChange={e => this.submit(e)}
117 id="form" 125 id="form"
118 > 126 >
119 <h2>{intl.formatMessage(messages.headlineGeneral)}</h2> 127 {/* General */}
128 <h2 id="general">{intl.formatMessage(messages.headlineGeneral)}</h2>
120 <Toggle field={form.$('autoLaunchOnStart')} /> 129 <Toggle field={form.$('autoLaunchOnStart')} />
121 <Toggle field={form.$('runInBackground')} /> 130 <Toggle field={form.$('runInBackground')} />
122 <Toggle field={form.$('enableSystemTray')} /> 131 <Toggle field={form.$('enableSystemTray')} />
123 {process.platform === 'win32' && ( 132 {process.platform === 'win32' && (
124 <Toggle field={form.$('minimizeToSystemTray')} /> 133 <Toggle field={form.$('minimizeToSystemTray')} />
125 )} 134 )}
126 <h2>{intl.formatMessage(messages.headlineAppearance)}</h2> 135
136 {/* Appearance */}
137 <h2 id="apperance">{intl.formatMessage(messages.headlineAppearance)}</h2>
127 <Toggle field={form.$('showDisabledServices')} /> 138 <Toggle field={form.$('showDisabledServices')} />
128 <h2>{intl.formatMessage(messages.headlineLanguage)}</h2> 139
140 {/* Language */}
141 <h2 id="language">{intl.formatMessage(messages.headlineLanguage)}</h2>
129 <Select field={form.$('locale')} showLabel={false} /> 142 <Select field={form.$('locale')} showLabel={false} />
130 <h2>{intl.formatMessage(messages.headlineUpdates)}</h2> 143
144 {/* Advanced */}
145 <h2 id="advanced">{intl.formatMessage(messages.headlineAdvanced)}</h2>
146 <Toggle field={form.$('enableSpellchecking')} />
147 <p className="settings__help">{intl.formatMessage(messages.restartRequired)}</p>
148 {/* <Select field={form.$('spellcheckingLanguage')} /> */}
149
150 {/* Updates */}
151 <h2 id="updates">{intl.formatMessage(messages.headlineUpdates)}</h2>
131 {updateIsReadyToInstall ? ( 152 {updateIsReadyToInstall ? (
132 <Button 153 <Button
133 label={intl.formatMessage(messages.buttonInstallUpdate)} 154 label={intl.formatMessage(messages.buttonInstallUpdate)}
diff --git a/src/config.js b/src/config.js
index 10359f426..5ee5ee18e 100644
--- a/src/config.js
+++ b/src/config.js
@@ -11,6 +11,8 @@ export const DEFAULT_APP_SETTINGS = {
11 enableSystemTray: true, 11 enableSystemTray: true,
12 minimizeToSystemTray: false, 12 minimizeToSystemTray: false,
13 showDisabledServices: true, 13 showDisabledServices: true,
14 enableSpellchecking: true,
15 // spellcheckingLanguage: 'auto',
14 locale: 'en-US', 16 locale: 'en-US',
15 beta: false, 17 beta: false,
16 isAppMuted: false, 18 isAppMuted: false,
diff --git a/src/containers/settings/EditSettingsScreen.js b/src/containers/settings/EditSettingsScreen.js
index b10acf3c6..62e255dab 100644
--- a/src/containers/settings/EditSettingsScreen.js
+++ b/src/containers/settings/EditSettingsScreen.js
@@ -7,7 +7,7 @@ import AppStore from '../../stores/AppStore';
7import SettingsStore from '../../stores/SettingsStore'; 7import SettingsStore from '../../stores/SettingsStore';
8import UserStore from '../../stores/UserStore'; 8import UserStore from '../../stores/UserStore';
9import Form from '../../lib/Form'; 9import Form from '../../lib/Form';
10import languages from '../../i18n/languages'; 10import { APP_LOCALES } from '../../i18n/languages';
11import { gaPage } from '../../lib/analytics'; 11import { gaPage } from '../../lib/analytics';
12import { DEFAULT_APP_SETTINGS } from '../../config'; 12import { DEFAULT_APP_SETTINGS } from '../../config';
13 13
@@ -43,6 +43,18 @@ const messages = defineMessages({
43 id: 'settings.app.form.showDisabledServices', 43 id: 'settings.app.form.showDisabledServices',
44 defaultMessage: '!!!Display disabled services tabs', 44 defaultMessage: '!!!Display disabled services tabs',
45 }, 45 },
46 enableSpellchecking: {
47 id: 'settings.app.form.enableSpellchecking',
48 defaultMessage: '!!!Enable spell checking',
49 },
50 spellcheckingLanguage: {
51 id: 'settings.app.form.spellcheckingLanguage',
52 defaultMessage: '!!!Language for spell checking',
53 },
54 // spellcheckingAutomaticDetection: {
55 // id: 'settings.app.form.spellcheckingAutomaticDetection',
56 // defaultMessage: '!!!Detect language automatically',
57 // },
46 beta: { 58 beta: {
47 id: 'settings.app.form.beta', 59 id: 'settings.app.form.beta',
48 defaultMessage: '!!!Include beta versions', 60 defaultMessage: '!!!Include beta versions',
@@ -73,6 +85,8 @@ export default class EditSettingsScreen extends Component {
73 enableSystemTray: settingsData.enableSystemTray, 85 enableSystemTray: settingsData.enableSystemTray,
74 minimizeToSystemTray: settingsData.minimizeToSystemTray, 86 minimizeToSystemTray: settingsData.minimizeToSystemTray,
75 showDisabledServices: settingsData.showDisabledServices, 87 showDisabledServices: settingsData.showDisabledServices,
88 enableSpellchecking: settingsData.enableSpellchecking,
89 // spellcheckingLanguage: settingsData.spellcheckingLanguage,
76 locale: settingsData.locale, 90 locale: settingsData.locale,
77 beta: settingsData.beta, 91 beta: settingsData.beta,
78 }, 92 },
@@ -89,14 +103,25 @@ export default class EditSettingsScreen extends Component {
89 const { app, settings, user } = this.props.stores; 103 const { app, settings, user } = this.props.stores;
90 const { intl } = this.context; 104 const { intl } = this.context;
91 105
92 const options = []; 106 const locales = [];
93 Object.keys(languages).forEach((key) => { 107 Object.keys(APP_LOCALES).forEach((key) => {
94 options.push({ 108 locales.push({
95 value: key, 109 value: key,
96 label: languages[key], 110 label: APP_LOCALES[key],
97 }); 111 });
98 }); 112 });
99 113
114 // const spellcheckerLocales = [{
115 // value: 'auto',
116 // label: intl.formatMessage(messages.spellcheckingAutomaticDetection),
117 // }];
118 // Object.keys(SPELLCHECKER_LOCALES).forEach((key) => {
119 // spellcheckerLocales.push({
120 // value: key,
121 // label: SPELLCHECKER_LOCALES[key],
122 // });
123 // });
124
100 const config = { 125 const config = {
101 fields: { 126 fields: {
102 autoLaunchOnStart: { 127 autoLaunchOnStart: {
@@ -129,10 +154,21 @@ export default class EditSettingsScreen extends Component {
129 value: settings.all.showDisabledServices, 154 value: settings.all.showDisabledServices,
130 default: DEFAULT_APP_SETTINGS.showDisabledServices, 155 default: DEFAULT_APP_SETTINGS.showDisabledServices,
131 }, 156 },
157 enableSpellchecking: {
158 label: intl.formatMessage(messages.enableSpellchecking),
159 value: settings.all.enableSpellchecking,
160 default: DEFAULT_APP_SETTINGS.enableSpellchecking,
161 },
162 // spellcheckingLanguage: {
163 // label: intl.formatMessage(messages.spellcheckingLanguage),
164 // value: settings.all.spellcheckingLanguage,
165 // options: spellcheckerLocales,
166 // default: DEFAULT_APP_SETTINGS.spellcheckingLanguage,
167 // },
132 locale: { 168 locale: {
133 label: intl.formatMessage(messages.language), 169 label: intl.formatMessage(messages.language),
134 value: app.locale, 170 value: app.locale,
135 options, 171 options: locales,
136 default: DEFAULT_APP_SETTINGS.locale, 172 default: DEFAULT_APP_SETTINGS.locale,
137 }, 173 },
138 beta: { 174 beta: {
diff --git a/src/i18n/languages.js b/src/i18n/languages.js
index 72d7b26c1..77bb5deae 100644
--- a/src/i18n/languages.js
+++ b/src/i18n/languages.js
@@ -1,4 +1,4 @@
1module.exports = { 1export const APP_LOCALES = {
2 'en-US': 'English', 2 'en-US': 'English',
3 'pt-BR': 'Portuguese (Brazil)', 3 'pt-BR': 'Portuguese (Brazil)',
4 'el-GR': 'Ελληνικά (Greece)', 4 'el-GR': 'Ελληνικά (Greece)',
@@ -15,3 +15,46 @@ module.exports = {
15 'zh-Hant': 'Chinese (Traditional)', 15 'zh-Hant': 'Chinese (Traditional)',
16 'nb-NO': 'Norsk', 16 'nb-NO': 'Norsk',
17}; 17};
18
19export default APP_LOCALES;
20
21// export const SPELLCHECKER_LOCALES = {
22// af: 'Afrikaans',
23// sq: 'Albanian',
24// ar: 'Arabic',
25// bg: 'Bulgarian',
26// zh: 'Chinese',
27// hr: 'Croatian',
28// cs: 'Czech',
29// da: 'Danish',
30// nl: 'Dutch',
31// en: 'English',
32// 'en-AU': 'English (AU)',
33// 'en-CA': 'English (CA)',
34// 'en-GB': 'English (GB)',
35// fi: 'Finnish',
36// fr: 'French',
37// ka: 'Georgian',
38// de: 'German',
39// el: 'Greek, Modern',
40// hi: 'Hindi',
41// hu: 'Hungarian',
42// id: 'Indonesian',
43// it: 'Italian',
44// ja: 'Japanese',
45// jv: 'Javanese',
46// ko: 'Korean',
47// lt: 'Lithuanian',
48// lv: 'Latvian',
49// ms: 'Malay',
50// no: 'Norwegian',
51// pl: 'Polish',
52// pt: 'Portuguese',
53// ro: 'Romanian, Moldavian, Moldovan',
54// ru: 'Russian',
55// sk: 'Slovak',
56// es: 'Spanish',
57// sv: 'Swedish',
58// uk: 'Ukrainian',
59// vi: 'Vietnamese',
60// };
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json
index 56daa9163..ed1f4a722 100644
--- a/src/i18n/locales/en-US.json
+++ b/src/i18n/locales/en-US.json
@@ -132,6 +132,7 @@
132 "settings.app.headlineLanguage": "Language", 132 "settings.app.headlineLanguage": "Language",
133 "settings.app.headlineUpdates": "Updates", 133 "settings.app.headlineUpdates": "Updates",
134 "settings.app.headlineAppearance": "Appearance", 134 "settings.app.headlineAppearance": "Appearance",
135 "settings.app.headlineAdvanced": "Advanced",
135 "settings.app.buttonSearchForUpdate": "Check for updates", 136 "settings.app.buttonSearchForUpdate": "Check for updates",
136 "settings.app.buttonInstallUpdate": "Restart & install update", 137 "settings.app.buttonInstallUpdate": "Restart & install update",
137 "settings.app.updateStatusSearching": "Is searching for update", 138 "settings.app.updateStatusSearching": "Is searching for update",
@@ -143,9 +144,11 @@
143 "settings.app.form.minimizeToSystemTray": "Minimize Franz to system tray", 144 "settings.app.form.minimizeToSystemTray": "Minimize Franz to system tray",
144 "settings.app.form.runInBackground": "Keep Franz in background when closing the window", 145 "settings.app.form.runInBackground": "Keep Franz in background when closing the window",
145 "settings.app.form.language": "Language", 146 "settings.app.form.language": "Language",
147 "settings.app.form.enableSpellchecking": "Enable spell checking",
146 "settings.app.form.showDisabledServices": "Display disabled services tabs", 148 "settings.app.form.showDisabledServices": "Display disabled services tabs",
147 "settings.app.form.beta": "Include beta versions", 149 "settings.app.form.beta": "Include beta versions",
148 "settings.app.currentVersion": "Current version:", 150 "settings.app.currentVersion": "Current version:",
151 "settings.app.restartRequired": "Changes require restart",
149 "settings.user.form.firstname": "Firstname", 152 "settings.user.form.firstname": "Firstname",
150 "settings.user.form.lastname": "Lastname", 153 "settings.user.form.lastname": "Lastname",
151 "settings.user.form.email": "Email", 154 "settings.user.form.email": "Email",
diff --git a/src/i18n/translations.js b/src/i18n/translations.js
index 492a6cc4e..161a172ba 100644
--- a/src/i18n/translations.js
+++ b/src/i18n/translations.js
@@ -1,7 +1,7 @@
1import languages from './languages'; 1import { APP_LOCALES } from './languages';
2 2
3const translations = []; 3const translations = [];
4Object.keys(languages).forEach((key) => { 4Object.keys(APP_LOCALES).forEach((key) => {
5 try { 5 try {
6 const translation = require(`./locales/${key}.json`); // eslint-disable-line 6 const translation = require(`./locales/${key}.json`); // eslint-disable-line
7 translations[key] = translation; 7 translations[key] = translation;
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index 269cd1526..87d31c0c5 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -37,6 +37,7 @@ export default class ServicesStore extends Store {
37 this.actions.service.toggleService.listen(this._toggleService.bind(this)); 37 this.actions.service.toggleService.listen(this._toggleService.bind(this));
38 this.actions.service.handleIPCMessage.listen(this._handleIPCMessage.bind(this)); 38 this.actions.service.handleIPCMessage.listen(this._handleIPCMessage.bind(this));
39 this.actions.service.sendIPCMessage.listen(this._sendIPCMessage.bind(this)); 39 this.actions.service.sendIPCMessage.listen(this._sendIPCMessage.bind(this));
40 this.actions.service.sendIPCMessageToAllServices.listen(this._sendIPCMessageToAllServices.bind(this));
40 this.actions.service.setUnreadMessageCount.listen(this._setUnreadMessageCount.bind(this)); 41 this.actions.service.setUnreadMessageCount.listen(this._setUnreadMessageCount.bind(this));
41 this.actions.service.openWindow.listen(this._openWindow.bind(this)); 42 this.actions.service.openWindow.listen(this._openWindow.bind(this));
42 this.actions.service.filter.listen(this._filter.bind(this)); 43 this.actions.service.filter.listen(this._filter.bind(this));
@@ -58,6 +59,7 @@ export default class ServicesStore extends Store {
58 this._mapActiveServiceToServiceModelReaction.bind(this), 59 this._mapActiveServiceToServiceModelReaction.bind(this),
59 this._saveActiveService.bind(this), 60 this._saveActiveService.bind(this),
60 this._logoutReaction.bind(this), 61 this._logoutReaction.bind(this),
62 this._shareSettingsWithServiceProcess.bind(this),
61 ]); 63 ]);
62 64
63 // Just bind this 65 // Just bind this
@@ -284,6 +286,7 @@ export default class ServicesStore extends Store {
284 if (channel === 'hello') { 286 if (channel === 'hello') {
285 this._initRecipePolling(service.id); 287 this._initRecipePolling(service.id);
286 this._initializeServiceRecipeInWebview(serviceId); 288 this._initializeServiceRecipeInWebview(serviceId);
289 this._shareSettingsWithServiceProcess();
287 } else if (channel === 'messages') { 290 } else if (channel === 'messages') {
288 this.actions.service.setUnreadMessageCount({ 291 this.actions.service.setUnreadMessageCount({
289 serviceId, 292 serviceId,
@@ -330,7 +333,17 @@ export default class ServicesStore extends Store {
330 @action _sendIPCMessage({ serviceId, channel, args }) { 333 @action _sendIPCMessage({ serviceId, channel, args }) {
331 const service = this.one(serviceId); 334 const service = this.one(serviceId);
332 335
333 service.webview.send(channel, args); 336 if (service.webview) {
337 service.webview.send(channel, args);
338 }
339 }
340
341 @action _sendIPCMessageToAllServices({ channel, args }) {
342 this.all.forEach(s => this.actions.service.sendIPCMessage({
343 serviceId: s.id,
344 channel,
345 args,
346 }));
334 } 347 }
335 348
336 @action _openWindow({ event }) { 349 @action _openWindow({ event }) {
@@ -495,6 +508,13 @@ export default class ServicesStore extends Store {
495 } 508 }
496 } 509 }
497 510
511 _shareSettingsWithServiceProcess() {
512 this.actions.service.sendIPCMessageToAllServices({
513 channel: 'settings-update',
514 args: this.stores.settings.all,
515 });
516 }
517
498 _cleanUpTeamIdAndCustomUrl(recipeId, data) { 518 _cleanUpTeamIdAndCustomUrl(recipeId, data) {
499 const serviceData = data; 519 const serviceData = data;
500 const recipe = this.stores.recipes.one(recipeId); 520 const recipe = this.stores.recipes.one(recipeId);
diff --git a/src/styles/settings.scss b/src/styles/settings.scss
index f804e6273..6e93094b4 100644
--- a/src/styles/settings.scss
+++ b/src/styles/settings.scss
@@ -350,9 +350,10 @@
350 flex-direction: column; 350 flex-direction: column;
351 351
352 .settings-navigation__link { 352 .settings-navigation__link {
353 display: block; 353 display: flex;
354 align-items: center;
354 height: 50px; 355 height: 50px;
355 line-height: 50px; 356 flex-shrink: 0;
356 text-decoration: none; 357 text-decoration: none;
357 color: $theme-text-color; 358 color: $theme-text-color;
358 padding: 0 20px; 359 padding: 0 20px;
diff --git a/src/webview/plugin.js b/src/webview/plugin.js
index ffc9084e4..c877132b1 100644
--- a/src/webview/plugin.js
+++ b/src/webview/plugin.js
@@ -1,11 +1,13 @@
1const { ipcRenderer } = require('electron'); 1import { ipcRenderer } from 'electron';
2const path = require('path'); 2import path from 'path';
3 3
4const RecipeWebview = require('./lib/RecipeWebview'); 4import RecipeWebview from './lib/RecipeWebview';
5 5
6require('./notifications.js'); 6import Spellchecker from './spellchecker.js';
7require('./spellchecker.js'); 7import './notifications.js';
8require('./ime.js'); 8import './ime.js';
9
10const spellchecker = new Spellchecker();
9 11
10ipcRenderer.on('initializeRecipe', (e, data) => { 12ipcRenderer.on('initializeRecipe', (e, data) => {
11 const modulePath = path.join(data.recipe.path, 'webview.js'); 13 const modulePath = path.join(data.recipe.path, 'webview.js');
@@ -19,6 +21,20 @@ ipcRenderer.on('initializeRecipe', (e, data) => {
19 } 21 }
20}); 22});
21 23
24ipcRenderer.on('settings-update', (e, data) => {
25 if (data.enableSpellchecking) {
26 if (!spellchecker.isEnabled) {
27 spellchecker.enable();
28
29 // TODO: this does not work yet, needs more testing
30 // if (data.spellcheckingLanguage !== 'auto') {
31 // console.log('set spellchecking language to', data.spellcheckingLanguage);
32 // spellchecker.switchLanguage(data.spellcheckingLanguage);
33 // }
34 }
35 }
36});
37
22document.addEventListener('DOMContentLoaded', () => { 38document.addEventListener('DOMContentLoaded', () => {
23 ipcRenderer.sendToHost('hello'); 39 ipcRenderer.sendToHost('hello');
24}, false); 40}, false);
diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js
index ec8807874..5beb77e03 100644
--- a/src/webview/spellchecker.js
+++ b/src/webview/spellchecker.js
@@ -1,14 +1,30 @@
1import { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } from 'electron-spellchecker'; 1import { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } from 'electron-spellchecker';
2 2
3window.spellCheckHandler = new SpellCheckHandler(); 3import { isMac } from '../environment';
4setTimeout(() => { 4
5 window.spellCheckHandler.attachToInput(); 5export default class Spellchecker {
6}, 1000); 6 isEnabled = false;
7 7 spellchecker = null;
8// TODO: should we set the language to user settings? 8
9// window.spellCheckHandler.switchLanguage('en-US'); 9 enable() {
10 10 this.spellchecker = new SpellCheckHandler();
11const contextMenuBuilder = new ContextMenuBuilder(window.spellCheckHandler); 11 if (!isMac) {
12const contextMenuListener = new ContextMenuListener((info) => { // eslint-disable-line 12 this.spellchecker.attachToInput();
13 contextMenuBuilder.showPopupMenu(info); 13 this.spellchecker.switchLanguage(navigator.language);
14}); 14 }
15
16 const contextMenuBuilder = new ContextMenuBuilder(this.spellchecker);
17
18 new ContextMenuListener((info) => { // eslint-disable-line
19 contextMenuBuilder.showPopupMenu(info);
20 });
21 }
22
23 // TODO: this does not work yet, needs more testing
24 // switchLanguage(language) {
25 // if (language !== 'auto') {
26 // this.spellchecker.switchLanguage(language);
27 // }
28 // }
29}
30