multiple fixes for nodejs integration
This commit is contained in:
parent
02c183b2c7
commit
919f3bd26f
@ -6,23 +6,17 @@
|
||||
#include "gui/webbrowser.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/skinfactory.h"
|
||||
#include "network-web/adblock/adblockmanager.h"
|
||||
#include "network-web/adblock/adblockrequestinfo.h"
|
||||
#include "network-web/networkfactory.h"
|
||||
#include "network-web/webfactory.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QWheelEvent>
|
||||
|
||||
LiteHtmlViewer::LiteHtmlViewer(QWidget* parent) : QLiteHtmlWidget(parent) {
|
||||
setResourceHandler([this](const QUrl& url) {
|
||||
QByteArray output;
|
||||
|
||||
NetworkFactory::performNetworkOperation(
|
||||
url.toString(),
|
||||
5000,
|
||||
{},
|
||||
output,
|
||||
QNetworkAccessManager::Operation::GetOperation);
|
||||
|
||||
return output;
|
||||
return handleResource(url);
|
||||
});
|
||||
}
|
||||
|
||||
@ -204,3 +198,31 @@ void LiteHtmlViewer::wheelEvent(QWheelEvent* event) {
|
||||
|
||||
QLiteHtmlWidget::wheelEvent(event);
|
||||
}
|
||||
|
||||
QByteArray LiteHtmlViewer::handleResource(const QUrl& url) {
|
||||
AdblockRequestInfo block_request(url);
|
||||
|
||||
if (url.path().endsWith(QSL("css"))) {
|
||||
block_request.setResourceType(QSL("stylesheet"));
|
||||
}
|
||||
else {
|
||||
block_request.setResourceType(QSL("image"));
|
||||
}
|
||||
|
||||
if (qApp->web()->adBlock()->block(block_request).m_blocked) {
|
||||
qWarningNN << LOGSEC_ADBLOCK << "Blocked request:" << QUOTE_W_SPACE_DOT(block_request.requestUrl().toString());
|
||||
return {};
|
||||
}
|
||||
else {
|
||||
QByteArray output;
|
||||
|
||||
NetworkFactory::performNetworkOperation(
|
||||
url.toString(),
|
||||
5000,
|
||||
{},
|
||||
output,
|
||||
QNetworkAccessManager::Operation::GetOperation);
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,9 @@ class LiteHtmlViewer : public QLiteHtmlWidget, public WebViewer {
|
||||
|
||||
protected:
|
||||
virtual void wheelEvent(QWheelEvent* event);
|
||||
|
||||
private:
|
||||
QByteArray handleResource(const QUrl& url);
|
||||
};
|
||||
|
||||
#endif // LITEHTMLVIEWER_H
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "miscellaneous/settings.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
@ -58,6 +59,15 @@ QString NodeJs::processedPackageFolder() const {
|
||||
qCriticalNN << LOGSEC_NODEJS << "Failed to create package folder structure" << QUOTE_W_SPACE_DOT(path);
|
||||
}
|
||||
|
||||
if (!QDir(path).exists(QSL("package.json"))) {
|
||||
QFile fl(path + QDir::separator() + QSL("package.json"));
|
||||
|
||||
fl.open(QIODevice::OpenModeFlag::WriteOnly);
|
||||
fl.write(QString("{}").toUtf8());
|
||||
fl.flush();
|
||||
fl.close();
|
||||
}
|
||||
|
||||
return QDir::toNativeSeparators(path);
|
||||
}
|
||||
|
||||
@ -80,7 +90,9 @@ QString NodeJs::npmVersion(const QString& npm_exe) const {
|
||||
NodeJs::PackageStatus NodeJs::packageStatus(const PackageMetadata& pkg) const {
|
||||
QString npm_ls = IOFactory::startProcessGetOutput(npmExecutable(),
|
||||
{ QSL("ls"), QSL("--unicode"), QSL("--json"), QSL("--prefix"),
|
||||
processedPackageFolder() });
|
||||
processedPackageFolder() },
|
||||
{},
|
||||
processedPackageFolder());
|
||||
QJsonDocument json = QJsonDocument::fromJson(npm_ls.toUtf8());
|
||||
QJsonObject deps = json.object()["dependencies"].toObject();
|
||||
|
||||
@ -180,10 +192,11 @@ void NodeJs::installPackages(const QList<PackageMetadata>& pkgs) {
|
||||
|
||||
to_install.prepend(QSL("--production"));
|
||||
to_install.prepend(QSL("install"));
|
||||
to_install.append(QSL("--prefix"));
|
||||
to_install.append(processedPackageFolder());
|
||||
|
||||
IOFactory::startProcess(proc, npmExecutable(), to_install);
|
||||
//to_install.append(QSL("--prefix"));
|
||||
//to_install.append(processedPackageFolder());
|
||||
|
||||
IOFactory::startProcess(proc, npmExecutable(), to_install, {}, processedPackageFolder());
|
||||
}
|
||||
catch (const ProcessException& ex) {
|
||||
qCriticalNN << LOGSEC_NODEJS << "Packages" << QUOTE_W_SPACE(to_install)
|
||||
|
@ -103,6 +103,6 @@ void AdblockRequestInfo::initialize(const QUrl& url) {
|
||||
#if defined(USE_WEBENGINE)
|
||||
setResourceType(convertResourceType(QWebEngineUrlRequestInfo::ResourceType::ResourceTypeMainFrame));
|
||||
#else
|
||||
setResourceType(QSL("image"));
|
||||
setResourceType(QSL("main_frame"));
|
||||
#endif
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user