aboutsummaryrefslogtreecommitdiffstats
path: root/webapp/src/app/services/utils.service.ts
blob: e665e2ab882d7fc0cb5ae39f53ba51f7957fb37e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Injectable } from '@angular/core';

@Injectable()
export class UtilsService {
    constructor() { }

    getOSName(lowerCase?: boolean): string {
        const checkField = function (ff) {
            if (ff.indexOf('Linux') !== -1) {
                return 'Linux';
            } else if (ff.indexOf('Win') !== -1) {
                return 'Windows';
            } else if (ff.indexOf('Mac') !== -1) {
                return 'MacOS';
            } else if (ff.indexOf('X11') !== -1) {
                return 'UNIX';
            }
            return '';
        };

        let OSName = checkField(navigator.platform);
        if (OSName === '') {
            OSName = checkField(navigator.appVersion);
        }
        if (OSName === '') {
            OSName = 'Unknown OS';
        }
        if (lowerCase) {
            return OSName.toLowerCase();
        }
        return OSName;
    }
}