Desktop/Mobile apps with persistent local storage #3898
-
Is there a way to build a desktop or mobile binary that has a backend (for instance, creating it's own sqlite db on the desktop/mobile device to persist structured data) but where that backend isn't managed by a separate server binary? In the hot_dog example, when you bundle the app for desktop, the server is a separate binary. Installing the .exe installs the client on your machine, but the client needs the server process to be running separately to modify/view favorites (and the client will panic if you try to hit the 'favorites' route without the server process running). I think the assumption with the Is there a way to either:
I'm looking at the example desktop projects like the file explorer as well, but none of them store their own structured data. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Desktop and mobile apps already run using native code. They control a webview instance, but they don't run their code inside of a webview. That means you can use native APIs like reading the filesystem or creating a database directly from the desktop or mobile code. If you also want the option to ship a separate server binary for your web build, you can move your server functions behind a config flag like this: // If we are not using fullstack, define our own server function error type
#[not(any(feature = "web", feature = "server")]
type ServerFnError = dioxus::CapturedError;
// If we are using fullstack, annotate this as a server function
#[cfg_attr(any(feature = "web", feature = "server"), server)]
async fn init_db() -> Result<Vec<Item>, ServerFnError> {...} |
Beta Was this translation helpful? Give feedback.
Hey @ealmloff, thanks for the reply. I think that got me going.
The first expression is missing some parens and an attribute. Should that be something like this?
For the second expression, suppose I'm using the local thread macro from the hot dog tutorial. If I want to ship a desktop and mobile app that don't require a server, but also have the option to ship a fullstack web app with it's own server binary, would I just add in the desktop/mobile features...
...like so?
#[cfg(any(feature = …