Skip to content

Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.

fix(desktop): Qt's log goes to the app's own logs folder

Bee1f33057254c3
diff --git a/desktop/app/cpp/app_helpers.cpp b/desktop/app/cpp/app_helpers.cpp
index e215eaf..2857fb3 100644
--- a/desktop/app/cpp/app_helpers.cpp
+++ b/desktop/app/cpp/app_helpers.cpp
@@ -95,7 +95,6 @@ void register_qml_app_engine(QQmlApplicationEngine &engine)
#include <QtCore/QDateTime>
#include <QtCore/QFile>
-#include <QtCore/QStandardPaths>
#include <QtCore/QTextStream>
#include <atomic>
@@ -129,12 +128,21 @@ void uiCheckMessageHandler(QtMsgType type, const QMessageLogContext &ctx, const
std::fflush(stderr);
}
+// The app's logs folder (`<data>/logs`), so a test instance with its own
+// data folder doesn't write into the installed app's.
+QString &qmlLogDir()
+{
+ static QString dir;
+ return dir;
+}
+
void qtLogMessageHandler(QtMsgType type, const QMessageLogContext &ctx, const QString &msg)
{
if (type == QtDebugMsg)
return;
- const QString dirPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
- + QStringLiteral("/Nectarlink/logs");
+ const QString &dirPath = qmlLogDir();
+ if (dirPath.isEmpty())
+ return;
QDir().mkpath(dirPath);
QFile file(dirPath + QStringLiteral("/qml.log"));
if (file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
@@ -145,8 +153,9 @@ void qtLogMessageHandler(QtMsgType type, const QMessageLogContext &ctx, const QS
}
} // namespace
-void prepare_qt()
+void prepare_qt(rust::Str log_dir)
{
+ qmlLogDir() = QString::fromUtf8(log_dir.data(), static_cast<qsizetype>(log_dir.size()));
qInstallMessageHandler(qtLogMessageHandler);
prepare_qt_without_log();
}
diff --git a/desktop/app/cpp/app_helpers.h b/desktop/app/cpp/app_helpers.h
index 9a04219..589a3df 100644
--- a/desktop/app/cpp/app_helpers.h
+++ b/desktop/app/cpp/app_helpers.h
@@ -13,7 +13,7 @@ class QGuiApplication;
std::unique_ptr<QGuiApplication> create_qt_app();
// Qt setup that must happen before QGuiApplication is created.
-void prepare_qt();
+void prepare_qt(rust::Str log_dir);
void prepare_qt_without_log();
void prepare_qt_for_ui_check();
int32_t qml_problem_count();
diff --git a/desktop/app/src/bridge/native.rs b/desktop/app/src/bridge/native.rs
index 3ef4e1e..52958c7 100644
--- a/desktop/app/src/bridge/native.rs
+++ b/desktop/app/src/bridge/native.rs
@@ -20,8 +20,9 @@ pub mod ffi {
/// The stream ended: its views go blank. Any thread.
fn video_clear(stream: &str);
- /// Must run before `QGuiApplication` is created.
- fn prepare_qt();
+ /// Must run before `QGuiApplication` is created. Qt's messages go to
+ /// `qml.log` in `log_dir`, beside the app's own log.
+ fn prepare_qt(log_dir: &str);
/// Like `prepare_qt`, without the QML log file: for the installer
/// and uninstaller, which mustn't create the app's data folder.
fn prepare_qt_without_log();
diff --git a/desktop/app/src/main.rs b/desktop/app/src/main.rs
index c53ddfc..4e0c857 100644
--- a/desktop/app/src/main.rs
+++ b/desktop/app/src/main.rs
@@ -653,7 +653,7 @@ fn main() -> ExitCode {
if options.ui_check {
bridge::native::ffi::prepare_qt_for_ui_check();
} else {
- bridge::native::ffi::prepare_qt();
+ bridge::native::ffi::prepare_qt(&logging::logs_dir(&data_dir).to_string_lossy());
}
#[cfg(target_os = "linux")]
let mut app = bridge::native::ffi::create_qt_app();