Passed
Push — develop ( 18945a...910cfa )
by Daniel
01:04 queued 10s
created

Configuration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 4

2 Functions

Rating   Name   Duplication   Size   Complexity  
A constructor 0 3 1
A getProperty 0 12 3
1
import { getGlobalStorageProvider } from "../browserApi/storageProvider";
2
import { assigned } from "../utils/helpers";
3
4
// website
5
export const SETTINGS_websiteDisplayQuickSearch = 'websiteDisplayQuickSearch';
6
export const SETTINGS_websiteShowNotificationsCountInTab = 'websiteShowNotificationsCountInTab';
7
export const SETTINGS_websiteHideUnusedTabs = 'websiteHideUnusedTabs';
8
export const SETTINGS_websiteOptimizeListAppearance = 'websiteOptimizeListAppearance';
9
// anime
10
export const SETTINGS_animeLanguageDisplay = 'animeLanguageDisplay';
11
// requests 
12
export const SETTINGS_requestBeautifyPage = 'requestBeautifyPage';
13
// player
14
export const SETTINGS_playerAutoplayAfterScreenshot = 'playerAutoplayAfterScreenshot';
15
// w2g
16
export const SETTINGS_w2gDisplayCharacterCounter = 'w2gDisplayCharacterCounter';
17
class Configuration {
18
    constructor() {
19
        this.settingsCache = new Map();
20
    }
21
22
    getProperty(key, callback) {
23
        if (this.settingsCache.has(key)) {
24
            callback(this.settingsCache.get(key));
25
        }
26
        else {
27
            // OOOPS // currently all settings are default true. This isn´t a problem but there should be much better soloutions after migration to typescript....
28
            getGlobalStorageProvider().getData(key, true, value => {
29
                this.settingsCache.set(key, value);
30
                callback(value);
31
            });
32
        }
33
    }
34
}
35
36
let __globalConfig;
37
38
export function getGlobalConfiguration() {
39
    if (!assigned(__globalConfig)) {
40
        __globalConfig = new Configuration();
41
    }
42
43
    return __globalConfig;
0 ignored issues
show
Bug introduced by
The variable __globalConfig does not seem to be initialized in case !assigned(__globalConfig) on line 39 is false. Are you sure this can never be the case?
Loading history...
44
}