Skip to content

Instantly share code, notes, and snippets.

@ghostoy
Created November 17, 2015 11:57
Show Gist options
  • Save ghostoy/447d08051177fa3dc29c to your computer and use it in GitHub Desktop.
Save ghostoy/447d08051177fa3dc29c to your computer and use it in GitHub Desktop.
NW.js shim for providing backward compatible for NW13
(function() {
// detect `nw` object of NW13
if (!(self.nw && self.nw.require)) return;
var realrequire = nw.require;
self.require = function() {
if (arguments[0] === 'nw.gui') {
return nw;
} else {
return realrequire.apply(self, [].slice.call(arguments, 0));
}
};
// Following items exist when running with `--mixed-context`.
// Copy them from `nw` to browser context
if (!self.process) self.process = self.nw.process;
if (!self.Buffer) self.Buffer = self.nw.Buffer;
if (!self.global) self.global = self.nw.global;
if (!self.root) self.root = self.nw.root;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment