Feature/#48 migrate to typescript #151
|
@ -1,20 +1,22 @@
|
||||||
const { assigned } = require("../utils/helpers")
|
const { assigned } = require("../utils/helpers")
|
||||||
|
|
||||||
|
export type ConfigurationStorageBooleanCallback = (value: boolean) => void;
|
||||||
|
|
||||||
export interface ICustomBrowserStorageProvider {
|
export interface ICustomBrowserStorageProvider {
|
||||||
setData(key: string, value: string): void;
|
setDataAsBoolean(key: string, value: boolean): void;
|
||||||
getData(key: string, defaultValue: string, callback: (x: string) => void): void;
|
getDataAsBoolean(key: string, defaultValue: boolean, callback: ConfigurationStorageBooleanCallback): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
class StorageProviderChromium implements ICustomBrowserStorageProvider {
|
class StorageProviderChromium implements ICustomBrowserStorageProvider {
|
||||||
|
|
||||||
setData(key: string, value: string): void {
|
setDataAsBoolean(key: string, value: boolean): void {
|
||||||
let obj = {};
|
let obj = {};
|
||||||
obj[key] = value;
|
obj[key] = value;
|
||||||
|
|
||||||
this.getStorage().set(obj);
|
this.getStorage().set(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
getData(key: string, defaultValue: string, callback: (x: string) => void): void {
|
getDataAsBoolean(key: string, defaultValue: boolean, callback: ConfigurationStorageBooleanCallback): void {
|
||||||
this.getStorage().get(key, items => {
|
this.getStorage().get(key, items => {
|
||||||
if (assigned(items) && assigned(items[key])) {
|
if (assigned(items) && assigned(items[key])) {
|
||||||
callback(items[key]);
|
callback(items[key]);
|
||||||
|
@ -37,19 +39,19 @@ class StorageProviderChromium implements ICustomBrowserStorageProvider {
|
||||||
|
|
||||||
class StorageProviderFirefox implements ICustomBrowserStorageProvider {
|
class StorageProviderFirefox implements ICustomBrowserStorageProvider {
|
||||||
|
|
||||||
setData(key: string, value: string): void {
|
setDataAsBoolean(key: string, value: boolean): void {
|
||||||
let obj = {};
|
let obj = {};
|
||||||
obj[key] = value;
|
obj[key] = value;
|
||||||
|
|
||||||
this.getStorage().set(obj);
|
this.getStorage().set(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
getData(key: string, defaultValue: string, callback: (x: string) => void): void {
|
getDataAsBoolean(key: string, defaultValue: boolean, callback: ConfigurationStorageBooleanCallback): void {
|
||||||
let promise = this.getStorage().get(key);
|
let promise = this.getStorage().get(key);
|
||||||
|
|
||||||
promise.then(items => {
|
promise.then(items => {
|
||||||
if (assigned(items) && assigned(items[key])) {
|
if (assigned(items) && assigned(items[key])) {
|
||||||
callback(items[key] as string);
|
callback(items[key] as boolean);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
callback(defaultValue);
|
callback(defaultValue);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { getGlobalStorageProvider } from "../browserApi/storageProvider";
|
import { ConfigurationStorageBooleanCallback, getGlobalStorageProvider } from "../browserApi/storageProvider";
|
||||||
import { assigned } from "../utils/helpers";
|
import { assigned } from "../utils/helpers";
|
||||||
|
|
||||||
// website
|
// website
|
||||||
|
@ -16,17 +16,20 @@ export const SETTINGS_playerAutoplayAfterScreenshot = 'playerAutoplayAfterScreen
|
||||||
// w2g
|
// w2g
|
||||||
export const SETTINGS_w2gDisplayCharacterCounter = 'w2gDisplayCharacterCounter';
|
export const SETTINGS_w2gDisplayCharacterCounter = 'w2gDisplayCharacterCounter';
|
||||||
class Configuration {
|
class Configuration {
|
||||||
|
settingsCache: Map<string, boolean>;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.settingsCache = new Map();
|
this.settingsCache = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
getProperty(key, callback) {
|
getProperty(key: string, callback: ConfigurationStorageBooleanCallback): void {
|
||||||
if (this.settingsCache.has(key)) {
|
if (this.settingsCache.has(key)) {
|
||||||
callback(this.settingsCache.get(key));
|
callback(this.settingsCache.get(key));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// TODO see commenz
|
||||||
// OOOPS // currently all settings are default true. This isn´t a problem but there should be much better soloutions after migration to typescript....
|
// OOOPS // currently all settings are default true. This isn´t a problem but there should be much better soloutions after migration to typescript....
|
||||||
getGlobalStorageProvider().getData(key, true, value => {
|
getGlobalStorageProvider().getDataAsBoolean(key, true, value => {
|
||||||
this.settingsCache.set(key, value);
|
this.settingsCache.set(key, value);
|
||||||
callback(value);
|
callback(value);
|
||||||
});
|
});
|
||||||
|
@ -34,7 +37,7 @@ class Configuration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let __globalConfig;
|
let __globalConfig: Configuration;
|
||||||
|
|
||||||
export function getGlobalConfiguration() {
|
export function getGlobalConfiguration() {
|
||||||
if (!assigned(__globalConfig)) {
|
if (!assigned(__globalConfig)) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ const OPTION_SELECTOR = 'input[type="checkbox"';
|
||||||
|
|
||||||
function storeOptions() {
|
function storeOptions() {
|
||||||
document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {
|
document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {
|
||||||
getGlobalStorageProvider().setData(optionElement.id, optionElement.checked);
|
getGlobalStorageProvider().setDataAsBoolean(optionElement.id, optionElement.checked);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ function restoreOptions() {
|
||||||
document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {
|
document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {
|
||||||
let defaultValue = optionElement.dataset.defaultValue === 'true' ? true : false;
|
let defaultValue = optionElement.dataset.defaultValue === 'true' ? true : false;
|
||||||
|
|
||||||
getGlobalStorageProvider().getData(optionElement.id, defaultValue, value => {
|
getGlobalStorageProvider().getDataAsBoolean(optionElement.id, defaultValue, value => {
|
||||||
optionElement.checked = value;
|
optionElement.checked = value;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue