mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-10-24 08:33:36 +00:00
This is an experimental fix for spellchecker. Previously, we were only using this on macOS since on other platforms, the spellcheck-module claimed to auto-detect + switch language on the fly but looks like it's not working as expected.
56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } = require('electron-spellchecker');
|
|
|
|
const ConfigUtil = require(__dirname + '/utils/config-util.js');
|
|
const Logger = require(__dirname + '/utils/logger-util.js');
|
|
|
|
const logger = new Logger({
|
|
file: 'errors.log',
|
|
timestamp: true
|
|
});
|
|
|
|
class SetupSpellChecker {
|
|
init() {
|
|
if (ConfigUtil.getConfigItem('enableSpellchecker')) {
|
|
this.enableSpellChecker();
|
|
}
|
|
this.enableContextMenu();
|
|
}
|
|
|
|
enableSpellChecker() {
|
|
try {
|
|
this.SpellCheckHandler = new SpellCheckHandler();
|
|
} catch (err) {
|
|
logger.error(err);
|
|
}
|
|
}
|
|
|
|
enableContextMenu() {
|
|
if (this.SpellCheckHandler) {
|
|
this.SpellCheckHandler.attachToInput();
|
|
|
|
const userLanguage = ConfigUtil.getConfigItem('spellcheckerLanguage');
|
|
|
|
this.SpellCheckHandler.switchLanguage(userLanguage);
|
|
}
|
|
|
|
const contextMenuBuilder = new ContextMenuBuilder(this.SpellCheckHandler);
|
|
this.contextMenuListener = new ContextMenuListener(info => {
|
|
contextMenuBuilder.showPopupMenu(info);
|
|
});
|
|
}
|
|
|
|
unsubscribeSpellChecker() {
|
|
// eslint-disable-next-line no-undef
|
|
if (this.SpellCheckHandler) {
|
|
this.SpellCheckHandler.unsubscribe();
|
|
}
|
|
if (this.contextMenuListener) {
|
|
this.contextMenuListener.unsubscribe();
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = new SetupSpellChecker();
|