Hidden settings

Is there a way (vscode or theia way) to hide preferences?
We want to set and get preferences from code but don’t want the user to see them

Are you looking to hide all preferences (UI), or are you trying to hide a single preference from users?

If it’s the former it might get complicated but you can achieve it by:

  • removing the opening of the preferences-widget
  • update the open preferences menu item to no-op (or remove it completely)
  • find a way to hide the settings.json (from the explorer for both theia and vscode) since if a user updates it the new preference values will take effect

We did not have a use-case in mind that app developers would want to remove preferences from the user (as it is a big usability downgrade as to not be able to control your settings).

Is there an API in theia (related to preference or not) to store data on the browser local storage?
I think it can work for this requirement.

You can use LocalStorage directly? If you want to store per a workspace then you should use StorageService. You should always remember that local storage is only 5mb and they are already occupied mostly by layout data. In order to persist anything bigger one should use indexed-db if it is available.

Hi @vince-fugnitto, @akosyakov

I have a related question. We can easily add new preferences. I can’t however find a robust way of removing them. What is the best way to hide/remove a single preference?

Thanks,
Arek

@arekzaluski I don’t believe there is a robust way besides rebinding but I’m not sure of the consequences (ex: using this preference in the code and it now not being present). Perhaps we should think of a mechanism to unregisterPreferences from the framework similarly to menus and commands to give more flexibility to downstream applications.

In the past I talked about having non-overridable preferences which are hidden from users and could not be overridden (remain at their default value), but perhaps unregistering them may be an option but we should think of an implementation and the consequences.

export function bindEditorPreferences(bind: interfaces.Bind): void {
    bind(EditorPreferences).toDynamicValue(ctx => {
        const preferences = ctx.container.get<PreferenceService>(PreferenceService);
        return createEditorPreferences(preferences);
    }).inSingletonScope();

    bind(PreferenceContribution).toConstantValue({ schema: editorPreferenceSchema });
}

Thank you for a quick answer. I’ve tried rebinding. Unfortunately, it doesn’t work great for PreferenceContribution. I agree that unregisterPreferences functionality will be very useful.

Here is a prosal: https://github.com/eclipse-theia/theia/discussions/9144#discussioncomment-420963