import * as Main from 'resource:///org/gnome/shell/ui/main.js';

export default class StartupOverviewFeature {
    enable(settings) {
        this._settings = settings;
        this._originalStartInOverview = Main.layoutManager.startInOverview;
        this._settingsChangedId = this._settings.connect(
            'changed::disable-overview-on-startup',
            () => this._applySetting()
        );
        this._applySetting();
    }

    _applySetting() {
        if (this._settings.get_boolean('disable-overview-on-startup'))
            Main.layoutManager.startInOverview = false;
        else
            Main.layoutManager.startInOverview = this._originalStartInOverview;
    }

    disable() {
        if (this._settingsChangedId) {
            this._settings.disconnect(this._settingsChangedId);
            this._settingsChangedId = null;
        }

        if (this._originalStartInOverview !== undefined)
            Main.layoutManager.startInOverview = this._originalStartInOverview;

        this._settings = null;
    }
}
