Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor settings.load into more sensible functions #5043

Merged
merged 1 commit into from
Jul 7, 2023

Conversation

ericpromislow
Copy link
Contributor

@ericpromislow ericpromislow commented Jun 23, 2023

Fixes #5022

This breaks the settings.load function into three main parts - one for loading an existing settings.json file, one for creating a new one, and common code used by both after the settings object has been created or loaded.

There's also a getSettings function, because overloading settings.load to create, load from disk, and retrieve from memory was too complex and error-prone.

Also the default memory value is calculated on the default settings object, because it's extremely unlikely to change while the program is running (ignore what it means for RD to run on a multi-node system and get handed over from one machine to another).

@ericpromislow ericpromislow marked this pull request as draft June 23, 2023 21:16
Copy link
Contributor

@mook-as mook-as left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking merge because of the big warning in the description.
Feel free to dismiss this once that's been resolved.

(I haven't looked at the changes at all.)

@ericpromislow ericpromislow marked this pull request as ready for review June 29, 2023 22:59
@jandubois jandubois requested a review from mook-as July 3, 2023 18:09
@mook-as mook-as dismissed their stale review July 3, 2023 21:46

This PR is now ready for review

mook-as
mook-as previously approved these changes Jul 6, 2023
pkg/rancher-desktop/config/settings.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/config/settings.ts Outdated Show resolved Hide resolved
- getSettings: just return the current settings
- createSettings: create a new settings object,
                  based on defaults and any deployment profiles (and save it)
- load: Either call createSettings if there's no settings.json, otherwise load it.
- updateSettings: renamed as migrateSettingsToCurrentVersion because `updateSettings`
        is now a function to update the settings via the API.

Set-up code common to both `load` and `createSettings` has been pulled out into a
separate function `finishConfiguringSettings`, which does any sanity-checking and
merges in any locked-field settings.

The `getSettings` call is made to return the current settings from the main process,
which can't send a message requesting them. Now the only place `settings.load` is called is
during startup in `background.ts`.

And now the unit tests can simply call `createSettings` which will read in the current
deployment profile, no need to do an artificial `settings.clear()`.

Signed-off-by: Eric Promislow <epromislow@suse.com>
@ericpromislow ericpromislow merged commit 7fd89df into main Jul 7, 2023
14 checks passed
@ericpromislow ericpromislow deleted the 5022-refactor-settings-load branch July 7, 2023 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor settings:load to make it more robust
2 participants