mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-11-11 07:41:04 +00:00
Contain fallback user agent within inferUserAgent
This commit is contained in:
parent
9a9a63c15a
commit
94c9fdb424
@ -2,10 +2,11 @@ import axios from 'axios';
|
||||
import _ from 'lodash';
|
||||
|
||||
const ELECTRON_VERSIONS_URL = 'https://atom.io/download/atom-shell/index.json';
|
||||
const DEFAULT_CHROME_VERSION = '47.0.2526.73';
|
||||
|
||||
function getChromeVersionForElectronVersion(electronVersion, url = ELECTRON_VERSIONS_URL) {
|
||||
|
||||
return axios.get(url)
|
||||
return axios.get(url, {timeout: 5000})
|
||||
.then(response => {
|
||||
if (response.status !== 200) {
|
||||
throw `Bad request: Status code ${response.status}`;
|
||||
@ -40,9 +41,15 @@ export function getUserAgentString(chromeVersion, platform) {
|
||||
return userAgent;
|
||||
}
|
||||
|
||||
export function inferUserAgent(electronVersion, platform) {
|
||||
return getChromeVersionForElectronVersion(electronVersion)
|
||||
function inferUserAgent(electronVersion, platform, url = ELECTRON_VERSIONS_URL) {
|
||||
return getChromeVersionForElectronVersion(electronVersion, url)
|
||||
.then(chromeVersion => {
|
||||
return getUserAgentString(chromeVersion, platform);
|
||||
})
|
||||
.catch(() => {
|
||||
// console.warn(`Unable to infer chrome version for user agent, using ${DEFAULT_CHROME_VERSION}`);
|
||||
return getUserAgentString(DEFAULT_CHROME_VERSION, platform);
|
||||
});
|
||||
}
|
||||
|
||||
export default inferUserAgent;
|
||||
|
@ -6,7 +6,7 @@ import sanitizeFilenameLib from 'sanitize-filename';
|
||||
import inferIcon from './../infer/inferIcon';
|
||||
import inferTitle from './../infer/inferTitle';
|
||||
import inferOs from './../infer/inferOs';
|
||||
import {inferUserAgent, getUserAgentString} from './../infer/inferUserAgent';
|
||||
import inferUserAgent from './../infer/inferUserAgent';
|
||||
import normalizeUrl from './normalizeUrl';
|
||||
import packageJson from './../../package.json';
|
||||
|
||||
@ -14,7 +14,6 @@ const {inferPlatform, inferArch} = inferOs;
|
||||
|
||||
const PLACEHOLDER_APP_DIR = path.join(__dirname, '../../', 'app');
|
||||
const ELECTRON_VERSION = '0.36.4';
|
||||
const CHROME_VERSION = '47.0.2526.73';
|
||||
|
||||
const DEFAULT_APP_NAME = 'APP';
|
||||
|
||||
@ -78,11 +77,7 @@ function optionsFactory(inpOptions, callback) {
|
||||
options.userAgent = userAgent;
|
||||
callback();
|
||||
})
|
||||
.catch(error => {
|
||||
console.warn('Cannot get user agent:', error);
|
||||
options.userAgent = getUserAgentString(CHROME_VERSION, options.platform);
|
||||
callback();
|
||||
});
|
||||
.catch(callback);
|
||||
},
|
||||
callback => {
|
||||
if (options.icon) {
|
||||
|
Loading…
Reference in New Issue
Block a user