example 'meshtastic': add proper local data paths on desktop

This commit is contained in:
pls.153 2023-08-05 08:36:42 +02:00
parent 4fc8ee3ca8
commit bc2e23b4bd
9 changed files with 44 additions and 15 deletions

View file

@ -19,3 +19,4 @@
(:file "lisp/lora")
(:file "lisp/location")
(:file "lisp/main")))

View file

@ -146,6 +146,17 @@ QVariant QT::sqlQuery(const QVariant& vQuery, const QVariant& vValues) {
// etc
QVariant QT::dataPath() {
// for desktop
static QString path;
if (path.isEmpty()) {
path = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
path.truncate(path.lastIndexOf(QChar('/')));
path.append("/cl-meshtastic/data/");
}
return path;
}
QVariant QT::localIp() {
// Returns the local IP string. Private networks may use:
// 10.*.*.*

View file

@ -34,6 +34,7 @@ public:
Q_INVOKABLE QVariant sqlQuery(const QVariant&, const QVariant&);
// etc
Q_INVOKABLE QVariant dataPath();
Q_INVOKABLE QVariant localIp();
Q_INVOKABLE QVariant startTileServer();

View file

@ -1,11 +1,12 @@
(in-package :db)
(defvar *file* (merge-pathnames "data/db"))
(defvar *file* nil)
(defun query (query &rest values)
(qt:sql-query qt:*cpp* query values))
(defun ini ()
(setf *file* (app:in-data-path "db"))
(ensure-directories-exist *file*)
(qt:ini-db qt:*cpp* (namestring *file*))
(query "create table if not exists messages (mid integer primary key, uid integer, message text)"))

View file

@ -81,7 +81,7 @@
0)))
(defun tile-path ()
(namestring (merge-pathnames "data/tiles/")))
(namestring (app:in-data-path "tiles/")))
(defun activate-map ()
(unless (q< |active| ui:*map-loader*)

View file

@ -18,6 +18,12 @@
(ensure-permissions :bluetooth-scan :bluetooth-connect)) ; android >= 12
(lora:start-device-discovery (or (setting :device) "")))
(defun in-data-path (file)
#+mobile
(merge-pathnames (x:cc "data/" file))
#-mobile
(x:cc (qt:data-path qt:*cpp*) file))
(defun view-index-changed (index) ; see QML
(when (and (= 1 index)
(not (app:setting :latest-receiver)))
@ -37,17 +43,17 @@
;;; settings
(defvar *file* (merge-pathnames "data/settings.exp"))
(let (file)
(defun load-settings ()
(when (probe-file *file*)
(with-open-file (s *file*)
(unless file
(setf file (in-data-path "settings.exp")))
(when (probe-file file)
(with-open-file (s file)
(setf lora:*settings* (read s)))))
(defun save-settings ()
(with-open-file (s *file* :direction :output :if-exists :supersede)
(with-open-file (s file :direction :output :if-exists :supersede)
(let ((*print-pretty* nil))
(prin1 lora:*settings* s))))
(prin1 lora:*settings* s)))))
(defun kw (string)
"Intern in KEYWORD package."

View file

@ -3,6 +3,7 @@
(:export
#:change-setting
#:icon-press-and-hold
#:in-data-path
#:ini
#:load-settings
#:my-ip

View file

@ -2,6 +2,7 @@
(:use :cl :qml)
(:export
#:*cpp*
#:data-path
#:ini
#:ini-db
#:ini-positioning

View file

@ -99,8 +99,9 @@ Save / Restore data
-------------------
A local web-server is included on mobile for saving and restoring the message
DB and the app settings. Just use special text message `:w` (for 'web-server')
and `:ws` (for 'stop web-server') after you're done.
DB, the app settings, plus eventually cached map tiles (for offline usage).
Just use special text message `:w` (for 'web-server') and `:ws` (for 'stop
web-server') after you're done.
After starting the server, just enter the shown URL in your desktop browser,
and follow the instructions.
@ -108,6 +109,12 @@ and follow the instructions.
Using this method you can easily transfer all data from one mobile device to
any other device.
The desktop data paths are:
* Linux: `~/.local/share/cl-meshtastic/data/`
* macOS: `~/Library/Application Support/cl-meshtastic/data/`
* Windows: TODO
Tips
----