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

configuration.js ➔ getGlobalConfiguration   A

Complexity

Conditions 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
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
}