Skip to content

Commit

Permalink
fix(210): fix Chrome and Safari not detected as desktop anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanAyaz committed May 5, 2021
1 parent d40f49b commit cea0f9e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ export const DEVICES = {
WINDOWS_PHONE: 'Windows-Phone',
VITA: 'Vita',
PS4: 'PS4',
MAC: 'Macintosh',
CHROMECAST: 'Chromecast',
APPLE_TV: 'Apple-TV',
GOOGLE_TV: 'Google-TV',
Expand Down Expand Up @@ -387,10 +388,18 @@ export const DEVICES = {
AMOI: 'Amoi',
INQ: 'INQ',
GENERIC_PHONE: 'Generic Phone',
MAC: 'Macintosh',
MI_SE_9: 'Mi SE 9',
};

export const DESKTOP_DEVICES = [
DEVICES.PS4,
DEVICES.CHROME_BOOK,
DEVICES.MAC,
DEVICES.DELL,
DEVICES.ASUS,
DEVICES.UNKNOWN,
];

export const OS = {
WINDOWS: 'Windows',
MAC: 'Mac',
Expand Down Expand Up @@ -511,6 +520,9 @@ export const DEVICES_RE: any = {
GOOGLE_TV: /\bGoogleTV\b/,
Tesla: /Tesla\/([0-9]{4}.[0-9]{1,2}.?[0-9]{0,2}.?[0-9]{0,2})-(.{7})/,
MI_SE_9: /\bXiaomi\b/,
MAC: {
and: [/\bMac OS\b/, { not: { or: [/\biPhone\b/, /\biPad\b/, /\biPod\b/, /\bWindows Phone\b/] } }],
},
};

export const OS_VERSIONS_RE_MAP: any = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe('DeviceDetectorService', () => {
'Firefox v 82.0.3 - Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:82.0) Gecko/20100101 Firefox/82.0';
service.setDeviceInfo(userAgent);
expect(service.isMobile(userAgent)).toBeFalsy();
expect(service.isDesktop(userAgent)).toBeFalsy();
expect(service.isDesktop(userAgent)).toBeTruthy();
expect(service.isTablet(userAgent)).toBeFalsy();
const deviceInfo = service.getDeviceInfo();
expect(deviceInfo.device).toBe('Macintosh');
Expand All @@ -194,7 +194,7 @@ describe('DeviceDetectorService', () => {
'Google Chrome v 86.0 - Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36';
service.setDeviceInfo(userAgent);
expect(service.isMobile(userAgent)).toBeFalsy();
expect(service.isDesktop(userAgent)).toBeFalsy();
expect(service.isDesktop(userAgent)).toBeTruthy();
expect(service.isTablet(userAgent)).toBeFalsy();
const deviceInfo = service.getDeviceInfo();
expect(deviceInfo.device).toBe('Macintosh');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,11 @@ export class DeviceDetectorService {
* @returns whether the current device is a desktop device
*/
public isDesktop(userAgent = this.userAgent): boolean {
const desktopDevices = [Constants.DEVICES.PS4, Constants.DEVICES.CHROME_BOOK, Constants.DEVICES.UNKNOWN];
if (this.device === Constants.DEVICES.UNKNOWN) {
if (this.isMobile(userAgent) || this.isTablet(userAgent)) {
return false;
}
}
return desktopDevices.indexOf(this.device) > -1;
return Constants.DESKTOP_DEVICES.indexOf(this.device) > -1;
}
}

0 comments on commit cea0f9e

Please sign in to comment.