You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.7 KiB
TypeScript

// Copyright (C) 2020-2021 Intel Corporation
//
// SPDX-License-Identifier: MIT
import platform from 'platform';
const engine = platform.layout || 'unknown';
const name = platform.name || 'unknown';
const version = platform.version || 'unknown';
const os = platform.os ? platform.os.toString() : 'unknown';
let platformNotificationShown = window.localStorage.getItem('platformNotiticationShown') !== null;
let featuresNotificationShown = window.localStorage.getItem('featuresNotificationShown') !== null;
interface PlatformInfo {
engine: string;
name: string;
version: string;
os: string;
}
export function platformInfo(): PlatformInfo {
return {
engine,
name,
version,
os,
};
}
export function stopNotifications(saveInStorage: boolean): void {
platformNotificationShown = true;
featuresNotificationShown = true;
if (saveInStorage) {
window.localStorage.setItem('platformNotiticationShown', 'shown');
window.localStorage.setItem('featuresNotificationShown', 'shown');
}
}
export default function showPlatformNotification(): boolean {
// Blick is engine of Chrome, Microsoft Edge >= v79
// Gecko is engine of Firefox, supported but works worse than in Chrome (let's show the message)
// WebKit is engine of Apple Safary, not supported
const unsupportedPlatform = !['Blink'].includes(engine);
return !platformNotificationShown && unsupportedPlatform;
}
export function showUnsupportedNotification(): boolean {
const nesassaryFeatures = [window.ResizeObserver, Object.fromEntries];
const unsupportedFeatures = nesassaryFeatures.some((feature) => typeof feature === 'undefined');
return !featuresNotificationShown && unsupportedFeatures;
}