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

feat(settings): add the ability to read and update settings without tauri store plugin #5774

Closed
wants to merge 1 commit into from

Conversation

krlvi
Copy link
Member

@krlvi krlvi commented Dec 7, 2024

No description provided.

Copy link

vercel bot commented Dec 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
gitbutler-components ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 7, 2024 8:47pm
gitbutler-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 7, 2024 8:47pm

@krlvi
Copy link
Member Author

krlvi commented Dec 7, 2024

in theory this should be backwards compatible with the existing setup, and we could just switch on the javascript end

@krlvi
Copy link
Member Author

krlvi commented Dec 7, 2024

@Byron so i am toying with an idea here of replacing the tauri-store plugin. Can it be as simple as this?

use serde::{Deserialize, Serialize};
use std::{fs, path::PathBuf};

const SETTINGS_FILE: &str = "projects.json";
Copy link
Contributor

Choose a reason for hiding this comment

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

settings.json!

@@ -9,3 +15,42 @@ pub struct AppSettings {
/// Client ID for the GitHub OAuth application
pub github_oauth_client_id: Option<String>,
}

#[derive(Debug, Deserialize, Serialize, Clone, Default, PartialEq, Hash)]
pub struct AppSettingsUpdateRequest {
Copy link
Contributor

@mtsgrd mtsgrd Dec 7, 2024

Choose a reason for hiding this comment

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

Is it possible to apply #[serde(default, skip_serializing_if = "Option::is_none")] to the struct itself? *edit: so we don't end up with null for anything not set.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure I am following here

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have never seen it on the struct itself, but if there was a field: AppSettingsUpdateRequest it would certainly be possible to implement something like it.
Right now I see it used only on the top-level of tauri function calls.
Probably I am missing something though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand the issue tbh - having the update request contain Option fields allows us to do partial updating without having to pass the entire settings struct over, which I think is desirable. @mtsgrd can you clarify what you meant?

Copy link
Contributor

Choose a reason for hiding this comment

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

What I mean is, if you have a struct with a bunch of optional values then on serializing that it will write out all keys, and null values for them. Instead, it would be great if it omits unset fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

Lol, sorry, I could be more clear from start. I just don't want the settings.json file to contain every possible key unless set. Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah, that makes total sense. We anyways need to make sure that the settings is backwards / forwards compatible.
But - I sense the reason you are saying this is for user edit-ability. But this setup is inherently not appropriate for that. I wanna make this friendly for a user to modify and screw up, but not sure yet how to build it in a nice way. This was actually the root discussion point i had here #5774 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Editability yes, but also readability and to make settings easier to share. Most of the time I edit vscode settings in the UI, but every once in a while I copy paste something in that I found online or got in a chat.

While we're on this topic. Could there be any settings we want to share at the repo level? Similar to how .vscode is used.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess what I am saying is - I would like to make a separation between the settings and the file that a user reads and updates. Have them be two separate things, such that it's both safer to update and as you said easier to read.
I am not sure yet what is the best way to implement that, but this PR was not trying to implement this, but instead just move us away from that tauri store plugin.

Regarding project settings - yes it will be great to move away from projects.json but let's nail app settings first, then it will be easy to extend from there

Copy link
Member Author

Choose a reason for hiding this comment

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

Just to clarify and summarize - the settings.json in it's current form is not appropriate for user editing.
The reason for that is not just the readability and serializing the None values, but also the fact that it is fragile - if this file doesn't parse, the app will not start.

I would love to move to a settings.json VSCode style, and not serializing unset values is necessary but not sufficient to getting there. I was initially thinking of this PR as simple change to get off the tauri store plugin, but since you fixed the state issue in the frontend, perhaps the scope of this can be expanded to land us in the endgame setup

Copy link
Collaborator

@Byron Byron left a comment

Choose a reason for hiding this comment

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

@Byron so i am toying with an idea here of replacing the tauri-store plugin. Can it be as simple as this?

I vaguely remember the tauri settings plugin implementation and can say that it also unsafely wrote the file contents (i..e without temporary file).

But its main selling point to me was that it would let subscribers be informed when updates happened automatically. Lastly, it could also debounce and throttle these updates.

Without subscription, UIs will be forced to poll to assure updates are picked up, and I think once there are multiple windows, keeping settings in sync gets much harder.

Personally, I still find that using a settings file for storage is a bit error prone, but with built-in rate limiting it probably is OK to write consistently even on Windows. If there was partial-write protection I think I'd be happy with the tauri plugin as something that can scale.

@@ -9,3 +15,42 @@ pub struct AppSettings {
/// Client ID for the GitHub OAuth application
pub github_oauth_client_id: Option<String>,
}

#[derive(Debug, Deserialize, Serialize, Clone, Default, PartialEq, Hash)]
pub struct AppSettingsUpdateRequest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have never seen it on the struct itself, but if there was a field: AppSettingsUpdateRequest it would certainly be possible to implement something like it.
Right now I see it used only on the top-level of tauri function calls.
Probably I am missing something though.

@mtsgrd
Copy link
Contributor

mtsgrd commented Dec 8, 2024

But its main selling point to me was that it would let subscribers be informed when updates happened automatically.

I think this hits the nail on the head, afaik there is need for pushing changes to the front end.

Actually yes, needed for multi-window setup.

@mtsgrd
Copy link
Contributor

mtsgrd commented Dec 8, 2024

It's worth noting, the one feature we need that isn't provided by the plugin is an ability to store nested json. While e.g. vscode supports both nested objects, as well as a flatter dot.notation, forcing a flat key/value structure is too restrictive.

@krlvi
Copy link
Member Author

krlvi commented Dec 8, 2024

The 'Store' that comes with '@tauri-apps/plugin-store' is one of the things I would love to get away from. We have had incidents of settings not being persisted, and it is all too easy to mix up assumptions around undefined/null etc.

The thinking here is using a good old boring RPC in the fronted - read the config when a settings page is loaded and persist the config when a "save" button is pressed.


On the storage end and also the long term idea for this - I would love to have a settings.json file similar to apps like Zed or VSCode that are user-friendly and editable. Right now, if the user messes up the name of a key or something, the config will not load at all. What would be a good way of achieving a nice user-editable setup? In my head I was thinking of having some sort of schema with defaults, and then, when parsing the settings.json values get merged in if they match an existing setting. Is there a library or a technique we could borrow for this?

@mtsgrd
Copy link
Contributor

mtsgrd commented Dec 8, 2024

The thinking here is using a good old boring RPC in the fronted - read the config when a settings page is loaded and persist the config when a "save" button is pressed.

Imagine you turn off telemetry in window A, you would reasonably expect all windows to immediately stop sharing such data right? It would be great if we had our own custom config, and some minimal thing we can subscribe to so the front end knows when to reload.

@krlvi
Copy link
Member Author

krlvi commented Dec 8, 2024

The thinking here is using a good old boring RPC in the fronted - read the config when a settings page is loaded and persist the config when a "save" button is pressed.

Imagine you turn off telemetry in window A, you would reasonably expect all windows to immediately stop sharing such data right? It would be great if we had our own custom config, and some minimal thing we can subscribe to so the front end knows when to reload.

Yeah we can totally add an event "settings" updated that all windows would get. I guess reliability is my primary motivation in wanting to keep stuff simple as much as possible, but this seems needed

@Byron
Copy link
Collaborator

Byron commented Dec 8, 2024

What really helped me in this conversation is the goal of eventually having a user-editable file of sorts, similar to Zed or VSCode. Last time I checked the plugin I also noticed that it was able to force pending writes during shutdown as well, so overall the lifecycle seemed well thought out.
My reliability concern has always been the direct write.

Personally, I also wouldn't be surprised if ultimately we would end up with a 'lite' implementation of the plugin, with all the tweaks and customisations that were needed to get there.

@krlvi
Copy link
Member Author

krlvi commented Dec 9, 2024

What really helped me in this conversation is the goal of eventually having a user-editable file of sorts, similar to Zed or VSCode. Last time I checked the plugin I also noticed that it was able to force pending writes during shutdown as well, so overall the lifecycle seemed well thought out. My reliability concern has always been the direct write.

Personally, I also wouldn't be surprised if ultimately we would end up with a 'lite' implementation of the plugin, with all the tweaks and customisations that were needed to get there.

I started implementing something new so I will probably abandon this pr

@krlvi
Copy link
Member Author

krlvi commented Dec 11, 2024

closing in favor of #5815

@krlvi krlvi closed this Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants