9 Replies
this is my
App.axaml.cs
file. I am trying to get it to do the following functionality.
- Launch SplashScreen
- Set splashscreen message to Checking If config.json File Exists...
- Run function to check if json file exists. If so, return true, else return false
- if json check function returns true, then file exists and launch the home screen
- if json check function returns false, then create the new json file and launch the setup screen
I'm having some issues with getting this to work correctly. The first issue being that I'm not sure how to import json into the project. The rest of the issues is knowing that the logic works, etc. I have not ran this as I know it doesn't work and am requestin assistance on getting it to work. Thanks in advance. I do not have a creating a json file function in my code as I'm not sure if one is needed.
the code for checking if the json file exists came from https://stackoverflow.com/questions/34064067/test-for-a-json-file-in-the-bin-folder and the repo that I'm following for creating my splash screen came from https://github.com/kivarsen/AvaloniaSplashScreenDemo/tree/master/AvaloniaSplashScreenDemoi would just try refactoring checks to be sequential instead of nested
also what does "import json onto the project" means
also what does "import json onto the project" meansusing Json.convert or whatever the import statement is for working with a JSON file
i would just try refactoring checks to be sequential instead of nestedidk what this means
idk what this meansnot doing this but this so you mean deserialization
Yes or whatever nuget package works with json
mainly two, System.Text.Json and Newtonsoft, the usuals
Multiple things we can unpack here.
- You seem to be using
vm.StartupMessage = ""
and await Task.Delay(...)
a lot, you can refactor this into a method. Simplest I can think of is adding a method to the VM as an async method then you just await that.
- Your persistence logic (checking for json and loading it) can be its own class, then you can do saving / loading pretty nicely. If you plan to just use Json loading and saving, i'd recommend doing a sort of "safe-save"
What I mean by safe-save is, write the settings to a temp file, when thats done, replace the temp file's name with the save file, temporarily name it something like config.part, everytime you save, delete all .part files in your app data folder (Saving something many times and then having your computer crash can wipe your config to just be an empty file)
Additionally, Jot is a nice library I've come to use more often for settings persistence (even shows examples for GUI settings persistence (like window location)
https://github.com/anakic/JotGitHub
GitHub - anakic/Jot: Jot is a library for persisting and applying ....
Jot is a library for persisting and applying .NET application state. - GitHub - anakic/Jot: Jot is a library for persisting and applying .NET application state.
Avalonia also has a Dispatcher that you can dispatch async code so you don't have to use
async void
in your method
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.