diff --git a/lib/spellchecker.js b/lib/spellchecker.js index 9bce86c..b30455b 100644 --- a/lib/spellchecker.js +++ b/lib/spellchecker.js @@ -1,10 +1,25 @@ var path = require('path'); -var bindings = require('../build/Release/spellchecker.node'); +var loophole = require('loophole'); +var bindings = require('bindings')('spellchecker.node'); var Spellchecker = bindings.Spellchecker; var defaultSpellcheck = null; +var objc, pool; + +// Workaround NSSpellChecker bug +// http://stackoverflow.com/a/31383060 +loophole.allowUnsafeNewFunction(function () { + try { + objc = require('nodobjc') + objc.import('Cocoa'); + pool = objc.NSAutoreleasePool('alloc')('init'); + objc.NSApplication('sharedApplication'); + pool('release'); + } catch (ex) {} +}); + var setDictionary = function(lang, dictPath) { defaultSpellcheck = new Spellchecker(); // NB: Windows 8 uses *dashes* to set the language (i.e. en-US), so if we fail diff --git a/package.json b/package.json index da48e97..dbf5773 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,9 @@ "jasmine-focused": "1.x" }, "dependencies": { - "nan": "^2.0.0" + "bindings": "^1.2.1", + "loophole": "^1.1.0", + "nan": "^2.0.0", + "nodobjc": "^2.1.0" } }