Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Platform} from 'react-native';
import CONST from '../../CONST';
import GetOperatingSystem from './types';

/**
* Reads the current operating system for native platforms.
* @return {String | null}
*/
export default () => {
const getOperatingSystem: GetOperatingSystem = () => {
switch (Platform.OS) {
case 'ios':
return CONST.OS.IOS;
Expand All @@ -15,3 +15,5 @@ export default () => {
return CONST.OS.NATIVE;
}
};

export default getOperatingSystem;
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import _ from 'underscore';
import CONST from '../../CONST';
import GetOperatingSystem from './types';

/**
* Reads the current operating system when running on Web/Mobile-Web/Desktop
* @return {String | null}
*/
export default () => {
const getOperatingSystem: GetOperatingSystem = () => {
const {userAgent, platform} = window.navigator;
const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'];
const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'];
const iosPlatforms = ['iPhone', 'iPad', 'iPod'];

let os = null;
if (_.contains(macosPlatforms, platform)) {
if (macosPlatforms.includes(platform)) {
os = CONST.OS.MAC_OS;
} else if (_.contains(iosPlatforms, platform)) {
} else if (iosPlatforms.includes(platform)) {
os = CONST.OS.IOS;
} else if (_.contains(windowsPlatforms, platform)) {
} else if (windowsPlatforms.includes(platform)) {
os = CONST.OS.WINDOWS;
} else if (/Android/.test(userAgent)) {
os = CONST.OS.ANDROID;
Expand All @@ -25,3 +24,5 @@ export default () => {
}
return os;
};

export default getOperatingSystem;
7 changes: 7 additions & 0 deletions src/libs/getOperatingSystem/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {ValueOf} from 'type-fest';
import CONST from '../../CONST';

type OS = ValueOf<typeof CONST.OS> | null;
type GetOperatingSystem = () => OS;

export default GetOperatingSystem;