mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2025-02-03 12:18:25 +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';
|
import _ from 'lodash';
|
||||||
|
|
||||||
const ELECTRON_VERSIONS_URL = 'https://atom.io/download/atom-shell/index.json';
|
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) {
|
function getChromeVersionForElectronVersion(electronVersion, url = ELECTRON_VERSIONS_URL) {
|
||||||
|
|
||||||
return axios.get(url)
|
return axios.get(url, {timeout: 5000})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
throw `Bad request: Status code ${response.status}`;
|
throw `Bad request: Status code ${response.status}`;
|
||||||
@ -40,9 +41,15 @@ export function getUserAgentString(chromeVersion, platform) {
|
|||||||
return userAgent;
|
return userAgent;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function inferUserAgent(electronVersion, platform) {
|
function inferUserAgent(electronVersion, platform, url = ELECTRON_VERSIONS_URL) {
|
||||||
return getChromeVersionForElectronVersion(electronVersion)
|
return getChromeVersionForElectronVersion(electronVersion, url)
|
||||||
.then(chromeVersion => {
|
.then(chromeVersion => {
|
||||||
return getUserAgentString(chromeVersion, platform);
|
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 inferIcon from './../infer/inferIcon';
|
||||||
import inferTitle from './../infer/inferTitle';
|
import inferTitle from './../infer/inferTitle';
|
||||||
import inferOs from './../infer/inferOs';
|
import inferOs from './../infer/inferOs';
|
||||||
import {inferUserAgent, getUserAgentString} from './../infer/inferUserAgent';
|
import inferUserAgent from './../infer/inferUserAgent';
|
||||||
import normalizeUrl from './normalizeUrl';
|
import normalizeUrl from './normalizeUrl';
|
||||||
import packageJson from './../../package.json';
|
import packageJson from './../../package.json';
|
||||||
|
|
||||||
@ -14,7 +14,6 @@ const {inferPlatform, inferArch} = inferOs;
|
|||||||
|
|
||||||
const PLACEHOLDER_APP_DIR = path.join(__dirname, '../../', 'app');
|
const PLACEHOLDER_APP_DIR = path.join(__dirname, '../../', 'app');
|
||||||
const ELECTRON_VERSION = '0.36.4';
|
const ELECTRON_VERSION = '0.36.4';
|
||||||
const CHROME_VERSION = '47.0.2526.73';
|
|
||||||
|
|
||||||
const DEFAULT_APP_NAME = 'APP';
|
const DEFAULT_APP_NAME = 'APP';
|
||||||
|
|
||||||
@ -78,11 +77,7 @@ function optionsFactory(inpOptions, callback) {
|
|||||||
options.userAgent = userAgent;
|
options.userAgent = userAgent;
|
||||||
callback();
|
callback();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(callback);
|
||||||
console.warn('Cannot get user agent:', error);
|
|
||||||
options.userAgent = getUserAgentString(CHROME_VERSION, options.platform);
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
callback => {
|
callback => {
|
||||||
if (options.icon) {
|
if (options.icon) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user