<commit_before>import storage = require('electron-json-storage');

interface SettingsValues {
    alwaysOnTop: boolean;
}


export class Settings {

    protected raw: SettingsValues;

    getRaw() {
        return this.raw;
    }

    load(ready) {
        storage.get('settings', (err, savedSettings: SettingsValues) => {
            if (err) savedSettings = <SettingsValues>{};
            if (('alwaysOnTop' in savedSettings) === false) {
                savedSettings['alwaysOnTop'] = this.raw.alwaysOnTop;
            }
            this.raw = savedSettings;
            ready();
        });
    }

    save(newSettings, ready) {
        let oldSettings = {};
        for (let attr in newSettings) {
            oldSettings[attr] = this.raw[attr];
        }
        if (JSON.stringify(newSettings) === JSON.stringify(oldSettings)) {
            console.log('no modifications')
        } else {
            console.log('modified settings!')
            for (let attr in newSettings) {
                this.raw[attr] = newSettings[attr];
            }
            this.persist();
        }
        ready();
    }

    persist(ready?) {
        storage.set('settings', this.raw, (err) => {
            if (err) console.log('Err persisting settings', err);
            ready(err);
        });
    }

    set(key, value) {
        this.raw[key] = value;
        this.persist();
    }

    get(key) {
        return this.raw[key];<commit_msg>Settings working with default values.<commit_after>import storage = require('electron-json-storage');


interface SettingsValues {
    alwaysOnTop: boolean;
    theme: 'dark'|'light';
}


export class Settings {

    protected raw: SettingsValues = <SettingsValues>{};

    getRaw() {
        return this.raw;
    }

    protected setDefaults(settings: SettingsValues) {
        settings.alwaysOnTop = false;
        settings.theme = 'dark';
    }

    load(ready) {
        this.setDefaults(this.raw);
        storage.get('settings', (err, savedSettings: SettingsValues) => {
            if (err) savedSettings = <SettingsValues>{};
            for (let attr in this.raw) {
                if ((attr in savedSettings) === false) {
                    savedSettings[attr] = this.raw[attr];
                }
            }
            this.raw = savedSettings;
            ready();
        });
    }

    save(newSettings, ready?) {
        let oldSettings = {};
        for (let attr in newSettings) {
            oldSettings[attr] = this.raw[attr];
        }
        if (JSON.stringify(newSettings) === JSON.stringify(oldSettings)) {
            console.log('no modifications')
        } else {
            console.log('modified settings!')
            for (let attr in newSettings) {
                this.raw[attr] = newSettings[attr];
            }
            this.persist();
        }
        ready && ready();
    }

    persist(ready?) {
        storage.set('settings', this.raw, (err) => {
            if (err) console.log('Err persisting settings', err);
            ready && ready(err);
        });
    }

    set(key, value) {
        this.raw[key] = value;
        this.persist();
    }

    get(key) {
        return this.raw[key];
{'fraction_non_alphanumeric': 0.13312401883830455, 'fraction_numerical': 0.0, 'mean_word_length': 1.8070484581497797, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5467495', 'n_tokens_mistral': 897, 'n_tokens_neox': 868, 'n_words': 185}