fixed #638
This commit is contained in:
parent
c09fe8eff1
commit
a30823d42a
@ -26,7 +26,7 @@
|
||||
<url type="donation">https://github.com/sponsors/martinrotter</url>
|
||||
<content_rating type="oars-1.1" />
|
||||
<releases>
|
||||
<release version="4.1.2" date="2022-02-14"/>
|
||||
<release version="4.1.2" date="2022-02-15"/>
|
||||
</releases>
|
||||
<content_rating type="oars-1.0">
|
||||
<content_attribute id="violence-cartoon">none</content_attribute>
|
||||
|
@ -38,7 +38,7 @@ WebBrowser::WebBrowser(QWidget* parent) : TabContent(parent),
|
||||
m_actionOpenInSystemBrowser(new QAction(qApp->icons()->fromTheme(QSL("document-open")),
|
||||
tr("Open this website in system web browser"),
|
||||
this)),
|
||||
m_actionReadabilePage(new QAction(qApp->icons()->fromTheme(QSL("document-preview")),
|
||||
m_actionReadabilePage(new QAction(qApp->icons()->fromTheme(QSL("text-html")),
|
||||
tr("View website in reader mode"),
|
||||
this)) {
|
||||
// Initialize the components and layout.
|
||||
@ -223,7 +223,9 @@ void WebBrowser::onIconChanged(const QIcon& icon) {
|
||||
}
|
||||
|
||||
void WebBrowser::setReadabledHtml(const QString& better_html) {
|
||||
m_webView->setHtml(better_html, m_webView->url());
|
||||
if (!better_html.isEmpty()) {
|
||||
m_webView->setHtml(better_html, m_webView->url());
|
||||
}
|
||||
}
|
||||
|
||||
void WebBrowser::readabilityFailed(const QString& error) {
|
||||
|
@ -2,12 +2,88 @@
|
||||
|
||||
#include "network-web/readability.h"
|
||||
|
||||
#include "3rd-party/boolinq/boolinq.h"
|
||||
#include "gui/messagebox.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/nodejs.h"
|
||||
|
||||
Readability::Readability(QObject* parent) : QObject{parent} {}
|
||||
#define READABILITY_PACKAGE "@mozilla/readability"
|
||||
#define READABILITY_VERSION "0.4.2"
|
||||
|
||||
Readability::Readability(QObject* parent) : QObject{parent}, m_modulesInstalling(false), m_modulesInstalled(false) {
|
||||
connect(qApp->nodejs(), &NodeJs::packageInstalledUpdated, this, &Readability::onPackageReady);
|
||||
connect(qApp->nodejs(), &NodeJs::packageError, this, &Readability::onPackageError);
|
||||
}
|
||||
|
||||
void Readability::onPackageReady(const QList<NodeJs::PackageMetadata>& pkgs, bool already_up_to_date) {
|
||||
Q_UNUSED(already_up_to_date)
|
||||
|
||||
bool concerns_readability = boolinq::from(pkgs).any([](const NodeJs::PackageMetadata& pkg) {
|
||||
return pkg.m_name == QSL(READABILITY_PACKAGE);
|
||||
});
|
||||
|
||||
if (!concerns_readability) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_modulesInstalled = true;
|
||||
m_modulesInstalling = false;
|
||||
|
||||
qApp->showGuiMessage(Notification::Event::NodePackageUpdated,
|
||||
{ tr("Packages for reader mode are installed"),
|
||||
tr("You can now use reader mode!"),
|
||||
QSystemTrayIcon::MessageIcon::Information },
|
||||
{ true, true, false });
|
||||
|
||||
// Emit this just to allow readability again for user.
|
||||
emit htmlReadabled({});
|
||||
}
|
||||
|
||||
void Readability::onPackageError(const QList<NodeJs::PackageMetadata>& pkgs, const QString& error) {
|
||||
bool concerns_readability = boolinq::from(pkgs).any([](const NodeJs::PackageMetadata& pkg) {
|
||||
return pkg.m_name == QSL(READABILITY_PACKAGE);
|
||||
});
|
||||
|
||||
if (!concerns_readability) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_modulesInstalled = m_modulesInstalling = false;
|
||||
|
||||
qApp->showGuiMessage(Notification::Event::NodePackageUpdated,
|
||||
{ tr("Packages for reader mode are NOT installed"),
|
||||
tr("There is error: %1").arg(error),
|
||||
QSystemTrayIcon::MessageIcon::Critical },
|
||||
{ true, true, false });
|
||||
|
||||
// Emit this just to allow readability again for user.
|
||||
emit htmlReadabled({});
|
||||
}
|
||||
|
||||
void Readability::makeHtmlReadable(const QString& html, const QString& base_url) {
|
||||
if (!m_modulesInstalled) {
|
||||
NodeJs::PackageStatus st = qApp->nodejs()->packageStatus({ QSL(READABILITY_PACKAGE), QSL(READABILITY_VERSION) });
|
||||
|
||||
if (st != NodeJs::PackageStatus::UpToDate) {
|
||||
if (!m_modulesInstalling) {
|
||||
// We make sure to update modules.
|
||||
m_modulesInstalling = true;
|
||||
|
||||
qApp->showGuiMessage(Notification::Event::NodePackageUpdated,
|
||||
{ tr("Node.js libraries not installed"),
|
||||
tr("%1 will now install some needed libraries, this will take only a few seconds. "
|
||||
"You will be notified when installation is complete.").arg(QSL(APP_NAME)),
|
||||
QSystemTrayIcon::MessageIcon::Information },
|
||||
{ true, true, false });
|
||||
qApp->nodejs()->installUpdatePackages({ { QSL(READABILITY_PACKAGE), QSL(READABILITY_VERSION) } });
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else {
|
||||
m_modulesInstalled = true;
|
||||
}
|
||||
}
|
||||
|
||||
QProcess* proc = new QProcess(this);
|
||||
|
||||
connect(proc, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &Readability::onReadabilityFinished);
|
||||
|
@ -5,6 +5,8 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "miscellaneous/nodejs.h"
|
||||
|
||||
#include <QProcess>
|
||||
|
||||
class Readability : public QObject {
|
||||
@ -17,10 +19,16 @@ class Readability : public QObject {
|
||||
|
||||
private slots:
|
||||
void onReadabilityFinished(int exit_code, QProcess::ExitStatus exit_status);
|
||||
void onPackageReady(const QList<NodeJs::PackageMetadata>& pkgs, bool already_up_to_date);
|
||||
void onPackageError(const QList<NodeJs::PackageMetadata>& pkgs, const QString& error);
|
||||
|
||||
signals:
|
||||
void htmlReadabled(const QString& better_html);
|
||||
void errorOnHtmlReadabiliting(const QString& error);
|
||||
|
||||
private:
|
||||
bool m_modulesInstalling;
|
||||
bool m_modulesInstalled;
|
||||
};
|
||||
|
||||
#endif // READABILITY_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user