Persistence for Electron/Cordova?
-
Hi
There’s one thing that I’m still confused about: I develop using quasar.
I run quasar build and create a web application that runs on my server.
I run quasar build -m electron and create a Windows executable that runs on my Windows OS.
I run quasar build -m cordova -T android and create an APK file that runs on my Android device.For all 3 modes, I want to store something locally (a small settings file with a very simplistic data). I want it to be stored cross session so the next time the user opens up the app/lication/APK, that data will be available for him.
Is there a one-size-fits-all mechanism for this?
Thanks -
I run quasar build and create a web application that runs on my server.
No Quasar, and in general all webapp’s made in JS(SPA’s) run on the client’s web browser. The role of the server (where Quasar resides) is serving the files to the client’s web browser ( SSR not taken into account).
because it runs in a web browser you can use
localstorage
to store cross session information.I run quasar build -m electron and create a Windows executable that runs on my Windows OS
Yes, but the important thing to remember is that it also run’s on web tech:
https://en.wikipedia.org/wiki/Electron_(software_framework)because of this you use
localstorage
to store cross session information.I run quasar build -m cordova -T android and create an APK file that runs on my Android device.
Yes, but the code in the apk will create a webview to run Quasar JS code on your phone just like chrome does( with a few differences, like for example cors restrictions).
So, because it run’s in a webview you can use
localstorage
to store cross session information.For more info about
localstorage
: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorageHere’s th doc about a Quasar localstorage plugin( has some extra features that the standard localstorage does not have):
https://quasar.dev/quasar-plugins/web-storage#LocalStorage-API
-
I stand corrected, the js code is obviously running on the client’s browser.
I understand what you wrote about localstorage when working with the browser.
cordova/electron are actually a wrapper of a browser but does this “internal” browser remembers itself when I open the app again? -
does this “internal” browser remembers itself when I open the app again?
Yes it will, unless of course the user has cleared it manually. But that can happen on a normal browser too.
-
Thanks a lot, I will give it a try.
-
Well, it works perfectly, I always thought that in electron/cordova mode, the browser starts from scratch every time.
Thanks a lot!! -
You’re welcome. There’s also a
sessionStorage
that will be cleared on start. -
I think you could use localstorage