warning when avatar bookmarks JSON is malformed

This commit is contained in:
HifiExperiments 2024-10-21 16:05:26 -07:00
parent b38237cb8d
commit b8198f20c3
3 changed files with 37 additions and 18 deletions

View file

@ -1741,17 +1741,19 @@ void Application::idle() {
#endif #endif
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
// If tracing is enabled then monitor the CPU in a separate thread {
static std::once_flag once; // If tracing is enabled then monitor the CPU in a separate thread
std::call_once(once, [&] { static std::once_flag once;
if (trace_app().isDebugEnabled()) { std::call_once(once, [&] {
QThread* cpuMonitorThread = new QThread(qApp); if (trace_app().isDebugEnabled()) {
cpuMonitorThread->setObjectName("cpuMonitorThread"); QThread* cpuMonitorThread = new QThread(qApp);
QObject::connect(cpuMonitorThread, &QThread::started, [this] { setupCpuMonitorThread(); }); cpuMonitorThread->setObjectName("cpuMonitorThread");
QObject::connect(qApp, &QCoreApplication::aboutToQuit, cpuMonitorThread, &QThread::quit); QObject::connect(cpuMonitorThread, &QThread::started, [this] { setupCpuMonitorThread(); });
cpuMonitorThread->start(); QObject::connect(qApp, &QCoreApplication::aboutToQuit, cpuMonitorThread, &QThread::quit);
} cpuMonitorThread->start();
}); }
});
}
#endif #endif
auto displayPlugin = getActiveDisplayPlugin(); auto displayPlugin = getActiveDisplayPlugin();
@ -1880,6 +1882,16 @@ void Application::idle() {
_overlayConductor.update(secondsSinceLastUpdate); _overlayConductor.update(secondsSinceLastUpdate);
_gameLoopCounter.increment(); _gameLoopCounter.increment();
{
static std::once_flag once;
std::call_once(once, [] {
const QString& bookmarksError = DependencyManager::get<AvatarBookmarks>()->getBookmarkError();
if (!bookmarksError.isEmpty()) {
OffscreenUi::asyncWarning("Avatar Bookmarks Error", "JSON parse error: " + bookmarksError, QMessageBox::Ok, QMessageBox::Ok);
}
});
}
} }
void Application::update(float deltaTime) { void Application::update(float deltaTime) {

View file

@ -4,6 +4,7 @@
// //
// Created by David Rowe on 13 Jan 2015. // Created by David Rowe on 13 Jan 2015.
// Copyright 2015 High Fidelity, Inc. // Copyright 2015 High Fidelity, Inc.
// Copyright 2024 Overte e.V.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -24,10 +25,6 @@
#include "Menu.h" #include "Menu.h"
#include "InterfaceLogging.h" #include "InterfaceLogging.h"
Bookmarks::Bookmarks() :
_isMenuSorted(false)
{
}
void Bookmarks::deleteBookmark() { void Bookmarks::deleteBookmark() {
QStringList bookmarkList; QStringList bookmarkList;
QList<QAction*> menuItems = _bookmarksMenu->actions(); QList<QAction*> menuItems = _bookmarksMenu->actions();
@ -154,8 +151,14 @@ void Bookmarks::readFromFile() {
} }
QByteArray data = loadFile.readAll(); QByteArray data = loadFile.readAll();
QJsonDocument json(QJsonDocument::fromJson(data)); QJsonParseError error;
_bookmarks = json.object().toVariantMap(); QJsonDocument json = QJsonDocument::fromJson(data, &error);
if (json.isNull()) {
_bookmarkError = error.errorString();
} else {
_bookmarks = json.object().toVariantMap();
}
} }
void Bookmarks::persistToFile() { void Bookmarks::persistToFile() {

View file

@ -4,6 +4,7 @@
// //
// Created by David Rowe on 13 Jan 2015. // Created by David Rowe on 13 Jan 2015.
// Copyright 2015 High Fidelity, Inc. // Copyright 2015 High Fidelity, Inc.
// Copyright 2024 Overte e.V.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -25,12 +26,14 @@ class Bookmarks: public QObject {
Q_OBJECT Q_OBJECT
public: public:
Bookmarks(); Bookmarks() : _isMenuSorted(false) {}
virtual void setupMenus(Menu* menubar, MenuWrapper* menu) = 0; virtual void setupMenus(Menu* menubar, MenuWrapper* menu) = 0;
void insert(const QString& name, const QVariant& address); // Overwrites any existing entry with same name. void insert(const QString& name, const QVariant& address); // Overwrites any existing entry with same name.
QString addressForBookmark(const QString& name) const; QString addressForBookmark(const QString& name) const;
const QString& getBookmarkError() const { return _bookmarkError; }
protected: protected:
void deleteBookmark(const QString& bookmarkName); void deleteBookmark(const QString& bookmarkName);
@ -45,6 +48,7 @@ protected:
void remove(const QString& name); void remove(const QString& name);
QVariantMap _bookmarks; // { name: url, ... } QVariantMap _bookmarks; // { name: url, ... }
QString _bookmarkError;
QPointer<MenuWrapper> _bookmarksMenu; QPointer<MenuWrapper> _bookmarksMenu;
QPointer<QAction> _deleteBookmarksAction; QPointer<QAction> _deleteBookmarksAction;
QString _bookmarksFilename; QString _bookmarksFilename;