Skip to content

Hard loading registries

Falcion edited this page Oct 18, 2024 · 2 revisions

UNITADE provides several functionalities to work with Obsidian's registry; one of them is the so-called "Hard-load" functionality. This feature simulates enabling a plugin or restarting the app with the plugin enabled by attempting to apply extensions in the vault to views and the extensions registry.

Upon clicking, this button, as opposed to "Force-unload," causes the plugin to imitate the "startup" process of itself, inserting operations into the registry based on any settings you configured before activating it.

Important

If you type repeated extensions in the settings or default ones and try to use this feature, it may cause mayhem in your Obsidian Vault. Since the extensions are already registered in multiple formats, it would try to overwrite some things, or other issues may occur, causing it to not work properly.

Here is an example code of this trigger-method (it may differ in the source code):

private __apply(): void {
    if (this.settings.is_grouped) {
        const data: { [key: string]: string[] } = parsegroup(this.settings.grouped_extensions);

        for (const view in data) {
            this.__applyCfg(data[view].join(';'), view);
        }
    }

    if (this.is_mobile) {
        this.__applyCfg(this.settings.mobile_settings.extensions ?? this.settings.extensions, 'markdown');
    } else {
        this.__applyCfg(this.settings.extensions, 'markdown');
    }

    const forced_extensions = this.settings.forced_extensions.split(';').map(s => s.trim());

    for (const extension of forced_extensions) {
        try {
            this.registerView(extension, (leaf: WorkspaceLeaf) => {
                return new UNITADE_VIEW(leaf, extension);
            });
        } catch (err: any) {
            this.settings.errors[extension] = `${this.locale.getLocaleItem('ERROR_COMMON_MESSAGE')[0]!} ${err}`;

            if (!this.settings.silence_errors) {
                new Notification(this.locale.getLocaleItem('ERROR_COMMON_MESSAGE')[0]!, { body: `${err}` });

                console.error(err);
            } else {
                console.debug(`[UNITADE-ERROR]: ERROR IS SILENCED, ERROR: ${err}`);
            }
        }
    }
}

public apply(): void {
    this.__apply();
}

Note

Since this is a public API of UNITADE's core, you can call this method from other places, like a custom plugin or the developer console.

Clone this wiki locally