electron-userland / electron-spellchecker

Implement spellchecking, correctly
MIT License
238 stars 83 forks source link

Can't create SpellCheckHandler with Electron >= 10.0.0 #176

Closed smee30 closed 3 years ago

smee30 commented 3 years ago

Because of non-semver compatible version checking on line 466 of spell-check-handler.js, this module is unusable with Electron versions > 10.0.0.

When you call new SpellCheckHandler(), the call fails with the following error:

Uncaught TypeError: Error processing argument at index 2, conversion failure from 
    at WebFrame.e.startsWith.WebFrame.<computed> [as setSpellCheckProvider] (electron/js2c/renderer_init.js:87)
    at SpellCheckHandler.setSpellCheckProvider (<my app>/node_modules/electron-spellchecker/src/spell-check-handler.js:471)
    at new SpellCheckHandler (<my app>/node_modules/electron-spellchecker/src/spell-check-handler.js:144)
    at create (<my app>/src/context-menu.js:88)
    at createContextMenu (<my app>/src/context-menu.js:105)
    at <my app>/src/preload.js:35

This is because this code in spell-check-handler.js:

  setSpellCheckProvider(webFrame) {
    if (process.versions.electron >= '5.0.0') {
      webFrame.setSpellCheckProvider(
        this.currentSpellcheckerLanguage,
        { spellCheck: this.handleElectronSpellCheck.bind(this) });
    } else {
      webFrame.setSpellCheckProvider(
        this.currentSpellcheckerLanguage,
        this.shouldAutoCorrect,
        { spellCheck: this.handleElectron4SpellCheck.bind(this) });
    }
  }

compares 5.0.0 with 11.2.1 (in my case) and in string comparison terms, 5.0.0 is greater. The library should compare the versions using SemVer as intended.

smee30 commented 3 years ago

Looks like this is irrelevant as spellchecking is now built-in to Electron. As you were ;-)