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

Add system settings manager #1685

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ArturoManzoli
Copy link
Contributor

@ArturoManzoli ArturoManzoli commented Feb 11, 2025

  • Users can edit, save and upload settings;
  • Reset settings button will be implemented on a second approach. For now a reset for the browser storage is implemented only.
Screenshare.-.2025-02-14.9_18_13.AM.mp4

Closes #1486

@ArturoManzoli ArturoManzoli force-pushed the 1486-Cockpit-is-missing-the-option-to-reset-settings branch from 2194b7d to 6617c9f Compare February 11, 2025 14:37
@@ -901,3 +907,90 @@ export const defaultSensorDataloggerProfile: OverlayGrid = {
export const defaultDisplayUnitPreferences = {
distance: DistanceDisplayUnit.Meters,
}

export const defaultCockpitSettings = {
Copy link
Member

Choose a reason for hiding this comment

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

I liked the idea of having all the defaults centralized in one place!

One thing thought is that we need to use those in the places where they are required (e.g.: calls to useStorage and useBlueOsStorage), otherwise if someone changes the value there, the value here will be deprecated and the code will not work.

{ level: 'warning', enabled: true },
{ level: 'critical', enabled: true },
],
'cockpit-mission-start-time': '2025-02-10T21:34:50.113Z',
Copy link
Member

Choose a reason for hiding this comment

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

It's crucial that we don't change the default values from what they are today. This one should be new Date(), and not that random date.

The same happens for several others. I believe you copied your own settings instead of the real defaults.


// Trying to sync automatically
watch(
() => userSettings.value,
Copy link
Member

Choose a reason for hiding this comment

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

A tip here: it looks like you're creating an extra localStorage entry to store a duplication of all variables just to be alerted by the useStorage composable about changes in the value. You can instead just listen to the "storage" event. This way you don't duplicate everything (which can cause a lot of confusion for someone reading the stored values, as there would be two possible two sources of truth) and you can monitor for changes directly in the values of the keys.

addEventListener("storage", (event) => {});

Actually, from this code, I assume you're not receiving changes made to the original settings, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, I'm not receiving the changes.

Actually what I was trying to do there was to check for changes on the local copy of the settings. and if there was any change, save it to the storage.

I'll implement the event listener and check the results

@ArturoManzoli ArturoManzoli force-pushed the 1486-Cockpit-is-missing-the-option-to-reset-settings branch from 6617c9f to 8119e18 Compare February 14, 2025 12:25
@@ -519,7 +533,6 @@ const tryToPrettifyRtcConfig = (): void => {

const openTutorial = (): void => {
interfaceStore.isMainMenuVisible = false
interfaceStore.configComponent = -1
Copy link
Member

Choose a reason for hiding this comment

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

To better understand, why was this removed?

Copy link
Contributor Author

@ArturoManzoli ArturoManzoli Feb 14, 2025

Choose a reason for hiding this comment

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

Maybe this should be on its own commit.

On a recent PR you added a 'tools' submenu that modified a little bit the way submenus and its contents work. This was leftover from that, I suppose.

image

Copy link
Member

Choose a reason for hiding this comment

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

Got it! Was a leftover indeed!

Yes, makes sense to be on a separate PR.

Sad that our linter is partially broken and not catching all errors. I should revisit the PR that fixes it at some point.

Copy link
Contributor Author

@ArturoManzoli ArturoManzoli Feb 14, 2025

Choose a reason for hiding this comment

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

Removed!

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I meant commit and not PR 😅

@ArturoManzoli ArturoManzoli marked this pull request as ready for review February 14, 2025 15:59
@ArturoManzoli ArturoManzoli force-pushed the 1486-Cockpit-is-missing-the-option-to-reset-settings branch from 8119e18 to cb7c4d5 Compare February 14, 2025 16:34
Show tutorial
</v-btn>
<v-btn
v-if="isElectron()"
Copy link
Member

Choose a reason for hiding this comment

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

This if should not be removed. It guarantees we don't show the button to open the folder while in a browser, which doesn't work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was a mistake I made. Nice that you saw. I was checking the menu with all buttons and forgot to put this back.

Returning now. Thanks

text: 'Reset settings',
action: () => {
localStorage.clear()
location.reload()
Copy link
Member

Choose a reason for hiding this comment

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

This will reload the page immediately, so the snackbar won't show or will do for a quick moment.

There's a utils method that deals with warning about the reload and setting a timeout so the user can read any message left. It can help here.

@ArturoManzoli ArturoManzoli force-pushed the 1486-Cockpit-is-missing-the-option-to-reset-settings branch from a8efdd6 to 9385ddd Compare February 14, 2025 17:20
Copy link
Member

@rafaellehmkuhl rafaellehmkuhl left a comment

Choose a reason for hiding this comment

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

Code looks good now.
Will just test it before approve.

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.

Cockpit is missing the option to reset it's settings
2 participants