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/lora")
(:file "lisp/location") (:file "lisp/location")
(:file "lisp/main"))) (:file "lisp/main")))

View file

@ -146,6 +146,17 @@ QVariant QT::sqlQuery(const QVariant& vQuery, const QVariant& vValues) {
// etc // 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() { QVariant QT::localIp() {
// Returns the local IP string. Private networks may use: // Returns the local IP string. Private networks may use:
// 10.*.*.* // 10.*.*.*

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -2,6 +2,7 @@
(:use :cl :qml) (:use :cl :qml)
(:export (:export
#:*cpp* #:*cpp*
#:data-path
#:ini #:ini
#:ini-db #:ini-db
#:ini-positioning #: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 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') DB, the app settings, plus eventually cached map tiles (for offline usage).
and `:ws` (for 'stop web-server') after you're done. 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, After starting the server, just enter the shown URL in your desktop browser,
and follow the instructions. 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 Using this method you can easily transfer all data from one mobile device to
any other device. any other device.
The desktop data paths are:
* Linux: `~/.local/share/cl-meshtastic/data/`
* macOS: `~/Library/Application Support/cl-meshtastic/data/`
* Windows: TODO
Tips Tips
---- ----