From 855a4bbf30c003f2b5299946925c7acea5c55ba8 Mon Sep 17 00:00:00 2001 From: Miau Lightouch Date: Sat, 12 May 2018 04:45:51 +0800 Subject: [PATCH] Fix nwjs support --- src/browser.js | 5 +++-- src/index.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/browser.js b/src/browser.js index f18d63e7..49a07dd5 100644 --- a/src/browser.js +++ b/src/browser.js @@ -7,7 +7,8 @@ exports.formatArgs = formatArgs; exports.save = save; exports.load = load; exports.useColors = useColors; -exports.storage = 'undefined' != typeof chrome +exports.storage = 'undefined' == typeof process + && 'undefined' != typeof chrome && 'undefined' != typeof chrome.storage ? chrome.storage.local : localstorage(); @@ -42,7 +43,7 @@ function useColors() { // NB: In an Electron preload script, document will be defined but not fully // initialized. Since we know we're in Chrome, we'll just detect this case // explicitly - if (typeof window !== 'undefined' && window.process && window.process.type === 'renderer') { + if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) { return true; } diff --git a/src/index.js b/src/index.js index cabcbcda..57e93761 100644 --- a/src/index.js +++ b/src/index.js @@ -1,9 +1,9 @@ /** - * Detect Electron renderer process, which is node, but we should + * Detect Electron renderer / nwjs process, which is node, but we should * treat as a browser. */ -if (typeof process === 'undefined' || process.type === 'renderer') { +if (typeof process === 'undefined' || process.type === 'renderer' || process.__nwjs) { module.exports = require('./browser.js'); } else { module.exports = require('./node.js');