From 47b1bc68e06b2def2190093c5c3a90c0b9f8e1c4 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Thu, 9 May 2019 21:08:00 +0200 Subject: [PATCH] BrowserDetect gets browser from env. Package.json updated to provide BROWSER in env --- package.json | 18 ++++++--- src/ext/conf/BrowserDetect.js | 74 ++++------------------------------- 2 files changed, 21 insertions(+), 71 deletions(-) diff --git a/package.json b/package.json index 8287fde..609c27e 100644 --- a/package.json +++ b/package.json @@ -4,19 +4,27 @@ "description": "Ultrawidify but with vue settings and popup", "author": "Tamius Han ", "scripts": { - "build": "cross-env NODE_ENV=production webpack --hide-modules", - "build:dev": "cross-env NODE_ENV=development webpack --hide-modules", + "build": "cross-env NODE_ENV=production BROWSER=firefox webpack --hide-modules", + "build-chrome": "cross-env NODE_ENV=production BROWSER=chrome webpack --hide-modules", + "build-edge": "cross-env NODE_ENV=production BROWSER=edge webpack --hide-modules", + "build:dev": "cross-env NODE_ENV=development BROWSER=firefox webpack --hide-modules", + "build-chrome:dev": "cross-env NODE_ENV=development BROWSER=chrome webpack --hide-modules", + "build-edge:dev": "cross-env NODE_ENV=development BROWSER=edge webpack --hide-modules", "build-zip": "node scripts/build-zip.js", "watch": "npm run build -- --watch", - "watch:dev": "cross-env HMR=true npm run build:dev -- --watch" + "watch-chrome": "npm run build-chrome-- --watch", + "watch-edge": "npm run build-edge -- --watch", + "watch:dev": "cross-env HMR=true npm run build:dev -- --watch", + "watch-chrome:dev": "cross-env HMR=true npm run build-chrome:dev -- --watch", + "watch-edge:dev": "cross-env HMR=true npm run build-edge:dev -- --watch" }, "dependencies": { "@types/core-js": "^2.5.0", "@types/es6-promise": "^3.3.0", + "fs-extra": "^7.0.1", "vue": "^2.5.17", "vuex": "^3.0.1", - "vuex-webextensions": "^1.2.6", - "webextension-polyfill": "^0.3.1" + "vuex-webextensions": "^1.2.6" }, "devDependencies": { "@babel/core": "^7.1.2", diff --git a/src/ext/conf/BrowserDetect.js b/src/ext/conf/BrowserDetect.js index 1e3c8ce..1d61eae 100644 --- a/src/ext/conf/BrowserDetect.js +++ b/src/ext/conf/BrowserDetect.js @@ -1,71 +1,13 @@ -import Debug from '../conf/Debug'; +import Debug from './Debug.js'; -var _bd_usebrowser = "firefox"; -var _bd_isFirefox = true; -var _bd_isChrome = false; -var _bd_isEdge = false; // we'll see if FF +const BrowserDetect = { + firefox: process.env.BROWSER === 'firefox', + chrome: process.env.BROWSER === 'chrome', + edge: process.env.BROWSER === 'edge', +} -try{ - // todo: find something that works in firefox but not in edge (or vice-versa) - // note that this function returns a promise! and is broken for some reason - var browserinfo = browser.runtime.getBrowserInfo(); - - // we don't need to actually check because only firefox supports that. - // if we're not on firefox, the above call will probably throw an exception anyway. - // if browsers other than firefox start supporting that, well ... we'll also need to actually await for promise - // that getBrowserInfo() returns to resolve. - - // if (Browser.name.toLowerCase().indexOf(firefox) !== -1 || Browser.vendor.toLowerCase().indexOf(mozilla) !== -1) { - _bd_isFirefox = true; - _bd_isEdge = false; - // } - -} -catch (e) { - if(Debug.debug) { - console.info("[BrowserDetect] browser.runtime.getBrowserInfo() probably failed. This means we're probably not using firefox.", e) - } -}; - -try { - if(browser === undefined){ // This is a good sign we're in chrome or chromium-based browsers - if(chrome){ - browser = chrome; - _bd_usebrowser = "chrome"; - _bd_isChrome = true; - _bd_isEdge = false; - _bd_isFirefox = false; - } - } -} catch (e) { - console.log("e=",e); - if(chrome){ - // browser = chrome; - _bd_usebrowser = "chrome"; - _bd_isChrome = true; - _bd_isEdge = false; - _bd_isFirefox = false; - } else { - console.log("No chrome either."); - } -} - -console.log("extension didn't crash after browser === undefined failed"); - -var BrowserDetect = { - usebrowser: _bd_usebrowser, - firefox: _bd_isFirefox, - chrome: _bd_isChrome, - edge: _bd_isEdge -} - -if(Debug.debug){ - console.log("BrowserDetect loaded! Here's BrowserDetect object:", BrowserDetect) -} - - -if (BrowserDetect.firefox) { - // browser = window.browser; +if (Debug.debug) { + console.log("Loading: BrowserDetect.js\n\nprocess.env.BROWSER:", process.env.BROWSER, "Exporting BrowserDetect:", BrowserDetect); } export default BrowserDetect; \ No newline at end of file