What's the best practice to load default configurations? #4018
-
I'm developing an app that need to have a default configuration builtin. Users also need to be able to customize it. I'm wondering what's the best way to load that default config, besides calling the functions of the Preferences API one by one? The config looks like this: {
"languages": [
{
"name": "C++14",
"suffix": "cpp",
"beforeCommand": "g++ {{FULL}} -o {{FILE}}",
"execCommand": "./{{FILE}}",
"cleanupCommand": "rm ./{{FILE}}"
}
]
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Using the latest stable, it is likely the best option to either call the methods on by one or save your JSON as a string store that once instead. The new lists API in #3932 might be useful once we release v2.4.0 as well. |
Beta Was this translation helpful? Give feedback.
-
Another solution that might be useful: When load configuration, first check if we can read from fyne's Preferences API, if so we use it; if not, we fallback to a JSON that's compiled into the binary. |
Beta Was this translation helpful? Give feedback.
-
The benefit of calling them "one by one" is that you can monitor for changes using data binding and the app will only refresh the impacted items - so it's very efficient. |
Beta Was this translation helpful? Give feedback.
Let me rephrase that... When we founnd that nothing has been loaded into Preferences, we fallback to the builtin JSON.
Or I can just use the Fallback-version and integrate the default configuration into it?