Skip to content

Commit

Permalink
Use kiwix-build's github action to download dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr committed Dec 19, 2023
1 parent 352cdcc commit 551efc1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ jobs:

steps:
- name: Install dependencies
shell: bash
run: |
ARCHIVE_NAME=deps2_focal_native_dyn_kiwix-desktop.tar.xz
wget -O- http://tmp.kiwix.org/ci/${ARCHIVE_NAME} | tar -xJ -C ${{env.HOME}}
uses: kiwix/kiwix-build/actions/dl_deps_archive@main
with:
target_platform: native_dyn

- name: Retrieve source code
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ int main(int argc, char *argv[])
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
QWebEngineUrlScheme scheme("zim");
scheme.setSyntax(QWebEngineUrlScheme::Syntax::Host);
QWebEngineUrlScheme::registerScheme(scheme);
#endif
KiwixApp a(argc, argv);
Expand Down
4 changes: 4 additions & 0 deletions src/urlschemehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ UrlSchemeHandler::handleContentRequest(QWebEngineUrlRequestJob *request)
return;
}
try {
qInfo() << "Getting " << QString::fromStdString(url) << "from" << zim_id;
auto entry = getEntryFromPath(*archive, url);
auto item = entry.getItem(true);
if (entry.isRedirect()) {
auto path = QString("/") + QString::fromStdString(item.getPath());
qurl.setPath(path);
request->redirect(qurl);
qInfo() << "-> Redirecting to" << path;
return;
}

Expand All @@ -62,8 +64,10 @@ UrlSchemeHandler::handleContentRequest(QWebEngineUrlRequestJob *request)
mimeType = mimeType.split(';')[0];
connect(request, &QObject::destroyed, buffer, &QObject::deleteLater);
request->reply(mimeType, buffer);
qInfo() << "-> Reply with" << mimeType;
} catch (zim::EntryNotFound&) {
request->fail(QWebEngineUrlRequestJob::UrlNotFound);
qInfo() << "-> Not found";
}
}

Expand Down
26 changes: 25 additions & 1 deletion src/webpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,35 @@ WebPage::WebPage(QObject *parent) :
action(QWebEnginePage::Reload)->setVisible(false);
}

bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType /*type*/, bool /*isMainFrame*/)
bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
{
qInfo() << "Requesting" << url;
qInfo() << "Navigation type :" << type << "MainFrame:" << isMainFrame;

if (url.scheme() != "zim") {
QDesktopServices::openUrl(url);
qInfo() << "=> False";
return false;
}
qInfo() << "=> True";
return true;
}


void WebPage::javaScriptConsoleMessage(QWebEnginePage::JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID) {
auto info = qInfo();
switch (level) {
case QWebEnginePage::InfoMessageLevel:
info << "INFO";
break;
case QWebEnginePage::WarningMessageLevel:
info << "WARN";
break;
case QWebEnginePage::ErrorMessageLevel:
info << "ERRO";
break;
}

info << "in" << sourceID << " at line" << lineNumber;
info << ":" << message;
}
1 change: 1 addition & 0 deletions src/webpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class WebPage : public QWebEnginePage

protected:
bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame);
void javaScriptConsoleMessage(QWebEnginePage::JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID) override;
};

#endif // WEBPAGE_H

0 comments on commit 551efc1

Please sign in to comment.