mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-01 12:33:31 +00:00
And enable the import/unambiguous ESLint rule as a check on our
partition between scripts and modules. After this commit, if you add
a new file and get this error:
✖ 1:1 This module could be parsed as a valid script. import/unambiguous
* For a module, add an `import` or `export` declaration to make the
file unambiguously a module (the empty `export {};` declaration
suffices).
* For a script, add the file to the xo overrides section of
package.json that marks it "sourceType": "script", and add a 'use
strict' declaration.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import type { Subject } from 'rxjs';
|
|
import { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } from 'electron-spellchecker';
|
|
|
|
import * as ConfigUtil from './utils/config-util';
|
|
import Logger from './utils/logger-util';
|
|
|
|
declare module 'electron-spellchecker' {
|
|
interface SpellCheckHandler {
|
|
currentSpellcheckerChanged: Subject<true>;
|
|
currentSpellcheckerLanguage: string;
|
|
}
|
|
}
|
|
|
|
const logger = new Logger({
|
|
file: 'errors.log',
|
|
timestamp: true
|
|
});
|
|
|
|
let spellCheckHandler: SpellCheckHandler;
|
|
let contextMenuListener: ContextMenuListener;
|
|
|
|
export function init(serverLanguage: string): void {
|
|
if (ConfigUtil.getConfigItem('enableSpellchecker')) {
|
|
enableSpellChecker();
|
|
}
|
|
enableContextMenu(serverLanguage);
|
|
}
|
|
|
|
function enableSpellChecker(): void {
|
|
try {
|
|
spellCheckHandler = new SpellCheckHandler();
|
|
} catch (err) {
|
|
logger.error(err);
|
|
}
|
|
}
|
|
|
|
function enableContextMenu(serverLanguage: string): void {
|
|
if (spellCheckHandler) {
|
|
spellCheckHandler.attachToInput();
|
|
spellCheckHandler.switchLanguage(serverLanguage);
|
|
spellCheckHandler.currentSpellcheckerChanged.subscribe(() => {
|
|
spellCheckHandler.switchLanguage(spellCheckHandler.currentSpellcheckerLanguage);
|
|
});
|
|
}
|
|
|
|
const contextMenuBuilder = new ContextMenuBuilder(spellCheckHandler);
|
|
contextMenuListener = new ContextMenuListener(info => {
|
|
contextMenuBuilder.showPopupMenu(info);
|
|
});
|
|
}
|
|
|
|
export function unsubscribeSpellChecker(): void {
|
|
if (spellCheckHandler) {
|
|
spellCheckHandler.unsubscribe();
|
|
}
|
|
if (contextMenuListener) {
|
|
contextMenuListener.unsubscribe();
|
|
}
|
|
}
|