#48 Better browser detection

This commit is contained in:
Serraniel 2020-12-29 16:49:18 +01:00
parent b08e38e915
commit 421c191e1d
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3

View file

@ -1,5 +1,11 @@
const { assigned } = require("../utils/helpers") const { assigned } = require("../utils/helpers")
enum BrowserApi {
Unknown,
Chromium,
Firefox,
}
export type ConfigurationStorageBooleanCallback = (value: boolean) => void; export type ConfigurationStorageBooleanCallback = (value: boolean) => void;
export interface ICustomBrowserStorageProvider { export interface ICustomBrowserStorageProvider {
@ -70,18 +76,36 @@ class StorageProviderFirefox implements ICustomBrowserStorageProvider {
let __storageProvieder: ICustomBrowserStorageProvider; let __storageProvieder: ICustomBrowserStorageProvider;
function getBrowserApi(): BrowserApi {
if (assigned(chrome)) {
if (assigned(browser)) {
return BrowserApi.Firefox;
}
return BrowserApi.Chromium;
}
else if (assigned(browser)) {
return BrowserApi.Firefox;
}
return BrowserApi.Unknown;
}
function createStorageProvider() { function createStorageProvider() {
// chrome based browser
// TODO: chrome.app? let api = getBrowserApi();
// if (assigned(chrome?.app)) {
if (true) { // chromium
if (api === BrowserApi.Chromium) {
__storageProvieder = new StorageProviderChromium(); __storageProvieder = new StorageProviderChromium();
} }
// firefox // firefox
else { else if (api === BrowserApi.Firefox) {
__storageProvieder = new StorageProviderFirefox(); __storageProvieder = new StorageProviderFirefox();
} }
else {
throw "Unknown browser API. Cannot create storage provider.";
}
} }
export function getGlobalStorageProvider(): ICustomBrowserStorageProvider { export function getGlobalStorageProvider(): ICustomBrowserStorageProvider {