mirror of
https://github.com/responsively-org/responsively-app
synced 2024-09-20 22:31:59 +00:00
Foundation for device filtering
This commit is contained in:
parent
0e98d36fc6
commit
67d23d405d
1 changed files with 45 additions and 2 deletions
|
@ -1,6 +1,12 @@
|
||||||
// @flow
|
// @flow
|
||||||
import chromeEmulatedDevices from './chromeEmulatedDevices';
|
import chromeEmulatedDevices from './chromeEmulatedDevices';
|
||||||
|
|
||||||
|
type OS = 'iOS' | 'Android' | 'Windows Phone' | 'PC';
|
||||||
|
|
||||||
|
type DeviceType = 'phone' | 'tablet' | 'notebook';
|
||||||
|
|
||||||
|
type Capability = 'mobile' | 'touch';
|
||||||
|
|
||||||
export type Device = {
|
export type Device = {
|
||||||
id: number,
|
id: number,
|
||||||
added: boolean,
|
added: boolean,
|
||||||
|
@ -8,10 +14,44 @@ export type Device = {
|
||||||
height: number,
|
height: number,
|
||||||
name: string,
|
name: string,
|
||||||
useragent: string,
|
useragent: string,
|
||||||
capabilities: Array<string>,
|
capabilities: Array<Capability>,
|
||||||
|
os: OS,
|
||||||
|
type: DeviceType,
|
||||||
};
|
};
|
||||||
let idGen = 1;
|
|
||||||
|
|
||||||
|
export const OS: {[key: string]: OS} = {
|
||||||
|
ios: 'iOS',
|
||||||
|
android: 'Android',
|
||||||
|
windowsPhone: 'Windows Phone',
|
||||||
|
pc: 'PC',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const DEVICE_TYPE: {[key: string]: DeviceType} = {
|
||||||
|
phone: 'phone',
|
||||||
|
tablet: 'tablet',
|
||||||
|
desktop: 'notebook',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const CAPABILITIES: {[key: string]: Capability} = {
|
||||||
|
mobile: 'mobile',
|
||||||
|
touch: 'touch',
|
||||||
|
};
|
||||||
|
|
||||||
|
function getOS(device) {
|
||||||
|
if (device.capabilities.indexOf('mobile') > -1) {
|
||||||
|
const useragent = device['user-agent'];
|
||||||
|
if (useragent.indexOf('like Mac OS X') > -1) {
|
||||||
|
return 'iOS';
|
||||||
|
}
|
||||||
|
if (useragent.indexOf('Lumia') > -1) {
|
||||||
|
return 'Windows Phone';
|
||||||
|
}
|
||||||
|
return 'Android';
|
||||||
|
}
|
||||||
|
return 'PC';
|
||||||
|
}
|
||||||
|
|
||||||
|
let idGen = 1;
|
||||||
export default chromeEmulatedDevices.extensions
|
export default chromeEmulatedDevices.extensions
|
||||||
.sort((a, b) => a.order - b.order)
|
.sort((a, b) => a.order - b.order)
|
||||||
.map(({order, device}) => {
|
.map(({order, device}) => {
|
||||||
|
@ -19,6 +59,7 @@ export default chromeEmulatedDevices.extensions
|
||||||
device.type === 'notebook'
|
device.type === 'notebook'
|
||||||
? device.screen.horizontal
|
? device.screen.horizontal
|
||||||
: device.screen.vertical;
|
: device.screen.vertical;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: idGen++,
|
id: idGen++,
|
||||||
name: device.title,
|
name: device.title,
|
||||||
|
@ -27,5 +68,7 @@ export default chromeEmulatedDevices.extensions
|
||||||
useragent: device['user-agent'],
|
useragent: device['user-agent'],
|
||||||
capabilities: device.capabilities,
|
capabilities: device.capabilities,
|
||||||
added: device['show-by-default'],
|
added: device['show-by-default'],
|
||||||
|
os: getOS(device),
|
||||||
|
type: device.type,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue