SymphonyElectron/js/spellChecker/spellChecker.js
Kiran Niranjan ae0398d8d0 Electron-47
1. Added a default language ('en-US') for windows
2. Included app.asar.unpacked dir in the windows installer as `spawn-rx` module is required for spellchecker to work.
2017-08-01 13:28:32 +05:30

57 lines
1.6 KiB
JavaScript

const { remote } = require('electron');
const { MenuItem } = remote;
const { isMac } = require('./../utils/misc');
const { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } = require('electron-spellchecker');
class SpellCheckHelper {
constructor() {
this.spellCheckHandler = new SpellCheckHandler();
}
/**
* Method to initialize spell checker
*/
initializeSpellChecker() {
this.spellCheckHandler.attachToInput();
// This is only for window as in mac the
// language is switched w.r.t to the current system language.
//
// In windows we need to implement RxJS observable
// in order to switch language dynamically
if (!isMac) {
this.spellCheckHandler.switchLanguage('en-US');
}
const contextMenuBuilder = new ContextMenuBuilder(this.spellCheckHandler, null, false, SpellCheckHelper.processMenu);
this.contextMenuListener = new ContextMenuListener((info) => {
contextMenuBuilder.showPopupMenu(info);
});
}
/**
* Method to add default menu items to the
* menu that was generated by ContextMenuBuilder
*
* This method will be invoked by electron-spellchecker
* before showing the context menu
*
* @param menu
* @returns menu
*/
static processMenu(menu) {
menu.append(new MenuItem({ type: 'separator' }));
menu.append(new MenuItem({
role: 'reload',
accelerator: 'CmdOrCtrl+R',
label: 'Reload'
}));
return menu;
}
}
module.exports = {
SpellCheckHelper: SpellCheckHelper
};