From 260a56c748106dad5826fda002f6f78fb64528b8 Mon Sep 17 00:00:00 2001 From: Adam Treat Date: Wed, 7 Feb 2024 09:53:14 -0500 Subject: [PATCH] Don't show the download button if we are not connected to an online network. Signed-off-by: Adam Treat --- gpt4all-chat/llm.cpp | 13 +++++++++++++ gpt4all-chat/llm.h | 6 ++++-- gpt4all-chat/main.qml | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gpt4all-chat/llm.cpp b/gpt4all-chat/llm.cpp index e5797c1b..0f454908 100644 --- a/gpt4all-chat/llm.cpp +++ b/gpt4all-chat/llm.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #ifndef GPT4ALL_OFFLINE_INSTALLER @@ -39,6 +40,10 @@ LLM::LLM() #endif m_compatHardware = minimal; + + QNetworkInformation::loadDefaultBackend(); + connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, + this, &LLM::isNetworkOnlineChanged); } bool LLM::hasSettingsAccess() const @@ -100,3 +105,11 @@ QString LLM::systemTotalRAMInGBString() const { return QString::fromStdString(getSystemTotalRAMInGBString()); } + +bool LLM::isNetworkOnline() const +{ + if (!QNetworkInformation::instance()) + return false; + + return QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Online; +} diff --git a/gpt4all-chat/llm.h b/gpt4all-chat/llm.h index 067ee671..55367742 100644 --- a/gpt4all-chat/llm.h +++ b/gpt4all-chat/llm.h @@ -6,6 +6,8 @@ class LLM : public QObject { Q_OBJECT + Q_PROPERTY(bool isNetworkOnline READ isNetworkOnline NOTIFY isNetworkOnlineChanged) + public: static LLM *globalInstance(); @@ -17,10 +19,10 @@ public: Q_INVOKABLE static bool fileExists(const QString &path); Q_INVOKABLE qint64 systemTotalRAMInGB() const; Q_INVOKABLE QString systemTotalRAMInGBString() const; + Q_INVOKABLE bool isNetworkOnline() const; Q_SIGNALS: - void chatListModelChanged(); - void modelListChanged(); + void isNetworkOnlineChanged(); private: bool m_compatHardware; diff --git a/gpt4all-chat/main.qml b/gpt4all-chat/main.qml index 4cfb11ad..72fbc3b8 100644 --- a/gpt4all-chat/main.qml +++ b/gpt4all-chat/main.qml @@ -869,6 +869,7 @@ Window { MyButton { id: downloadButton + visible: LLM.isNetworkOnline Layout.alignment: Qt.AlignHCenter Layout.topMargin: 40 text: qsTr("Download models")