mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-23 01:36:15 +03:00
Make WebUI error non-fatal
* Do not exit the app when WebUI is failed for start. * Print the error to stdout. PR #19697. Closes #19695. Closes #19469.
This commit is contained in:
parent
6860c0d60d
commit
35e4b35d12
3 changed files with 21 additions and 9 deletions
|
@ -890,13 +890,17 @@ int Application::exec()
|
||||||
#ifndef DISABLE_WEBUI
|
#ifndef DISABLE_WEBUI
|
||||||
m_webui = new WebUI(this);
|
m_webui = new WebUI(this);
|
||||||
#ifdef DISABLE_GUI
|
#ifdef DISABLE_GUI
|
||||||
if (m_webui->isErrored())
|
connect(m_webui, &WebUI::error, this, [](const QString &message) { fprintf(stderr, "%s\n", qUtf8Printable(message)); });
|
||||||
QCoreApplication::exit(EXIT_FAILURE);
|
|
||||||
connect(m_webui, &WebUI::fatalError, this, []() { QCoreApplication::exit(EXIT_FAILURE); });
|
|
||||||
|
|
||||||
printf("%s", qUtf8Printable(u"\n******** %1 ********\n"_s.arg(tr("Information"))));
|
printf("%s", qUtf8Printable(u"\n******** %1 ********\n"_s.arg(tr("Information"))));
|
||||||
|
|
||||||
if (m_webui->isEnabled())
|
if (m_webui->isErrored())
|
||||||
|
{
|
||||||
|
const QString error = m_webui->errorMessage() + u'\n'
|
||||||
|
+ tr("To fix the error, you may need to edit the config file manually.");
|
||||||
|
fprintf(stderr, "%s\n", qUtf8Printable(error));
|
||||||
|
}
|
||||||
|
else if (m_webui->isEnabled())
|
||||||
{
|
{
|
||||||
const QHostAddress address = m_webui->hostAddress();
|
const QHostAddress address = m_webui->hostAddress();
|
||||||
const QString url = u"%1://%2:%3"_s.arg((m_webui->isHttps() ? u"https"_s : u"http"_s)
|
const QString url = u"%1://%2:%3"_s.arg((m_webui->isHttps() ? u"https"_s : u"http"_s)
|
||||||
|
|
|
@ -48,6 +48,7 @@ WebUI::WebUI(IApplication *app)
|
||||||
void WebUI::configure()
|
void WebUI::configure()
|
||||||
{
|
{
|
||||||
m_isErrored = false; // clear previous error state
|
m_isErrored = false; // clear previous error state
|
||||||
|
m_errorMsg.clear();
|
||||||
|
|
||||||
const QString portForwardingProfile = u"webui"_s;
|
const QString portForwardingProfile = u"webui"_s;
|
||||||
const Preferences *pref = Preferences::instance();
|
const Preferences *pref = Preferences::instance();
|
||||||
|
@ -113,13 +114,13 @@ void WebUI::configure()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const QString errorMsg = tr("Web UI: Unable to bind to IP: %1, port: %2. Reason: %3")
|
m_errorMsg = tr("Web UI: Unable to bind to IP: %1, port: %2. Reason: %3")
|
||||||
.arg(serverAddressString).arg(port).arg(m_httpServer->errorString());
|
.arg(serverAddressString).arg(port).arg(m_httpServer->errorString());
|
||||||
LogMsg(errorMsg, Log::CRITICAL);
|
LogMsg(m_errorMsg, Log::CRITICAL);
|
||||||
qCritical() << errorMsg;
|
qCritical() << m_errorMsg;
|
||||||
|
|
||||||
m_isErrored = true;
|
m_isErrored = true;
|
||||||
emit fatalError();
|
emit error(m_errorMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +157,11 @@ bool WebUI::isErrored() const
|
||||||
return m_isErrored;
|
return m_isErrored;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString WebUI::errorMessage() const
|
||||||
|
{
|
||||||
|
return m_errorMsg;
|
||||||
|
}
|
||||||
|
|
||||||
bool WebUI::isHttps() const
|
bool WebUI::isHttps() const
|
||||||
{
|
{
|
||||||
if (!m_httpServer) return false;
|
if (!m_httpServer) return false;
|
||||||
|
|
|
@ -56,12 +56,13 @@ public:
|
||||||
|
|
||||||
bool isEnabled() const;
|
bool isEnabled() const;
|
||||||
bool isErrored() const;
|
bool isErrored() const;
|
||||||
|
QString errorMessage() const;
|
||||||
bool isHttps() const;
|
bool isHttps() const;
|
||||||
QHostAddress hostAddress() const;
|
QHostAddress hostAddress() const;
|
||||||
quint16 port() const;
|
quint16 port() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void fatalError();
|
void error(const QString &message);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void configure();
|
void configure();
|
||||||
|
@ -69,6 +70,7 @@ private slots:
|
||||||
private:
|
private:
|
||||||
bool m_isEnabled = false;
|
bool m_isEnabled = false;
|
||||||
bool m_isErrored = false;
|
bool m_isErrored = false;
|
||||||
|
QString m_errorMsg;
|
||||||
QPointer<Http::Server> m_httpServer;
|
QPointer<Http::Server> m_httpServer;
|
||||||
QPointer<Net::DNSUpdater> m_dnsUpdater;
|
QPointer<Net::DNSUpdater> m_dnsUpdater;
|
||||||
QPointer<WebApplication> m_webapp;
|
QPointer<WebApplication> m_webapp;
|
||||||
|
|
Loading…
Reference in a new issue