Global application state in Rust - Using Singleton?
Hi, I'm new to KDE/Qt/Rust development, but I'm a proud Pinephone owner and want to contribute to the app ecosystem.
Not sure where else to ask this question so here we go: Can I store global state in my Rust code?
I'm writing an app where the user needs to login and all data is encrypted/decrypted on the client. So I need to store the encryption keys in memory for pretty much anything the user wants to do.
Now I have multiple pages in my application. I instantiate my Rust object from QML in order to log in and it works great. However, when I replace the current page via applicationWindow().pageStack.replace("qrc:/LoggedInPage.qml")
and have another MyApp { id: myApp }
object, it is re-instantiated and looses the in memory data from the previous page.
I could find there are some kind of Singleton objects in Qt - https://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html#registering-singleton-objects-with-a-singleton-type - but couldn't find any mention of it in this repo.
Any advice on how I can have global application state accessible in my Rust code? Unfortunately it's not easily serialized to string to pass it around from instance to instance (which would be tedious and inefficient too).
Thank you so much for your help and all the great work on this and other KDE projects! Axel