Skip to content

Commit

Permalink
fix: make openSUSE welcome work again
Browse files Browse the repository at this point in the history
Fixes #25.
  • Loading branch information
sowelipililimute committed Sep 19, 2022
1 parent e737c55 commit 5bcc456
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 15 deletions.
2 changes: 1 addition & 1 deletion data/qrc/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ Window {
WebEngineView {
id: webView
anchors.fill: parent
url: "web/home.html"
url: "aqrc:///web/home.html"
webChannel: bridge
property var request;
onLoadingChanged: {
Expand Down
4 changes: 2 additions & 2 deletions data/qrc/web/contribute.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<div class="sticky-top">
<div class="breadcrumb py-0 d-flex justify-content-between align-items-center">
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item active"><a onclick="delayedClick('qrc:///web/home.html')" href=""><i
<li class="breadcrumb-item active"><a onclick="delayedClick('aqrc:///web/home.html')" href=""><i
class="fa fa-home"> </i>{{conTrans.home}}</a></li>
<li class="breadcrumb-item active">{{conTrans.contribute}}</li>
</ol>
Expand Down Expand Up @@ -99,7 +99,7 @@ <h2 id="spread-the-word">{{conTrans.spreadWord}}</h2>
</div>
</div>
<div class="d-flex">
<button class="btn btn-sm btn-secondary ml-3" onclick="delayedClick('qrc:///web/home.html')" lang="en">
<button class="btn btn-sm btn-secondary ml-3" onclick="delayedClick('aqrc:///web/home.html')" lang="en">
<i class="fa fa-arrow-left"></i> {{conTrans.home}}
</button>
<button id="close" class="btn btn-sm btn-danger ml-3" onclick="bridge.close()" lang="en">
Expand Down
8 changes: 4 additions & 4 deletions data/qrc/web/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h1 id="ahoy-this-is-opensuse">{{homeTrans.ahoy}}</h1>

<div class="col-sm-4 btn-showcase my-auto">
<h4>{{homeTrans.basicsHeader}}</h4>
<a class="btn btn-block btn-warning font-weight-bold" href="" onclick="delayedClick('qrc:///web/readme.html')">
<a class="btn btn-block btn-warning font-weight-bold" href="" onclick="delayedClick('aqrc:///web/readme.html')">
<i class="fa fa-book"></i> {{homeTrans.readme}}
</a>
<a class="btn btn-block btn-info" href="" onclick="bridge.openURL('https://doc.opensuse.org/')">
Expand Down Expand Up @@ -113,7 +113,7 @@ <h4>{{homeTrans.supportHeader}}</h4>
onclick="bridge.openURL('https://wiki.deepin.org/?language=en_US')" data-de="deepin">
<i class="fa fa-life-ring"></i> {{homeTrans.aboutcinnamon}}
</a>
<a class="btn btn-block btn-primary" onclick="delayedClick('qrc:///web/contribute.html')" href="">
<a class="btn btn-block btn-primary" onclick="delayedClick('aqrc:///web/contribute.html')" href="">
<i class="fa fa-hand-o-up"></i> {{homeTrans.contribute}}
</a>
<a class="btn btn-block btn-success" href=""
Expand All @@ -131,7 +131,7 @@ <h4>{{homeTrans.supportHeader}}</h4>
</div>

<p>
{{homeTrans.smParagraph}} <a class="" onclick="delayedClick('qrc:///web/socials.html')"
{{homeTrans.smParagraph}} <a class="" onclick="delayedClick('aqrc:///web/socials.html')"
href="">{{homeTrans.smLink}}</a>.
</p>

Expand Down Expand Up @@ -161,7 +161,7 @@ <h4>{{homeTrans.supportHeader}}</h4>
ng-model="autostart" onclick="updateAutoStart()">
{{homeTrans.autostart}}
</checkbox>
<button id="close" class="btn btn-sm btn-warning font-weight-bold de-footer" data-de="xfce" onclick="delayedClick('qrc:///web/xfce.html')" lang="en">
<button id="close" class="btn btn-sm btn-warning font-weight-bold de-footer" data-de="xfce" onclick="delayedClick('aqrc:///web/xfce.html')" lang="en">
<i class="fa fa-arrow-right"></i> {{homeTrans.customize}}
</button>
<button id="close" class="btn btn-sm btn-danger ml-3" onclick="bridge.close()" lang="en">
Expand Down
4 changes: 2 additions & 2 deletions data/qrc/web/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<div class="sticky-top">
<div class="breadcrumb py-0 d-flex justify-content-between align-items-center">
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item active"><a onclick="delayedClick('qrc:///web/home.html')" href=""><i
<li class="breadcrumb-item active"><a onclick="delayedClick('aqrc:///web/home.html')" href=""><i
class="fa fa-home"> </i> {{readTrans.home}}</a></li>
<li class="breadcrumb-item active">{{readTrans.readme}}</li>
</ol>
Expand Down Expand Up @@ -81,7 +81,7 @@ <h2 id="community-repos">{{readTrans.community}}</h2>
</div>
</div>
<div class="d-flex">
<button class="btn btn-sm btn-secondary ml-3" onclick="delayedClick('qrc:///web/home.html')" lang="en">
<button class="btn btn-sm btn-secondary ml-3" onclick="delayedClick('aqrc:///web/home.html')" lang="en">
<i class="fa fa-arrow-left"></i> {{readTrans.home}}
</button>
<button id="close" class="btn btn-sm btn-danger ml-3" onclick="bridge.close()" lang="en">
Expand Down
4 changes: 2 additions & 2 deletions data/qrc/web/socials.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<div class="sticky-top">
<div class="breadcrumb py-0 d-flex justify-content-between align-items-center">
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item active"><a onclick="delayedClick('qrc:///web/home.html')" href=""><i
<li class="breadcrumb-item active"><a onclick="delayedClick('aqrc:///web/home.html')" href=""><i
class="fa fa-home"> </i>{{socialTrans.home}}</a></li>
<li class="breadcrumb-item active">{{socialTrans.socialMedia}}</li>
</ol>
Expand Down Expand Up @@ -119,7 +119,7 @@ <h3 id="telegram">{{socialTrans.smTelegram}}</h3>
</div>
</div>
<div class="d-flex">
<button class="btn btn-sm btn-secondary ml-3" onclick="delayedClick('qrc:///web/home.html')" lang="en">
<button class="btn btn-sm btn-secondary ml-3" onclick="delayedClick('aqrc:///web/home.html')" lang="en">
<i class="fa fa-arrow-left"></i> {{socialTrans.home}}
</button>
<button id="close" class="btn btn-sm btn-danger ml-3" onclick="bridge.close()" lang="en"><i
Expand Down
4 changes: 2 additions & 2 deletions data/qrc/web/xfce.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div class="sticky-top">
<div class="breadcrumb py-0 d-flex justify-content-between align-items-center">
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item active"><a onclick="delayedClick('qrc:///web/home.html')" href=""><i
<li class="breadcrumb-item active"><a onclick="delayedClick('aqrc:///web/home.html')" href=""><i
class="fa fa-home"> </i> {{readTrans.home}}</a></li>
<li class="breadcrumb-item active">{{xfceTrans.customize}}</li>
</ol>
Expand Down Expand Up @@ -132,7 +132,7 @@ <h2>{{xfceTrans.theme}}</h2>
</div>
</div>
<div class="d-flex">
<button class="btn btn-sm btn-secondary ml-3" onclick="delayedClick('qrc:///web/home.html')" lang="en">
<button class="btn btn-sm btn-secondary ml-3" onclick="delayedClick('aqrc:///web/home.html')" lang="en">
<i class="fa fa-arrow-left"></i> {{readTrans.home}}
</button>
<button id="close" class="btn btn-sm btn-danger ml-3" onclick="bridge.close()" lang="en">
Expand Down
56 changes: 54 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtWebEngine/QtWebEngine>
#include <QtWebEngine/QQuickWebEngineProfile>
#include <QTranslator>
#include <QLocale>
#include <QDir>
Expand All @@ -27,12 +28,65 @@
#include "enabler.h"
#include "panellayouter.h"

/// a workaround since QMimeDatabase detects .html as "application/x-extension-html" (chromium doesn't like this)
/// instead of "text/html" as it used to.
///
/// cf QTBUG-106688.
class WorkaroundSchemeHandler : public QWebEngineUrlSchemeHandler
{
public:
WorkaroundSchemeHandler(QObject *parent = nullptr) : QWebEngineUrlSchemeHandler(parent)
{
}
void requestStarted(QWebEngineUrlRequestJob *job) override
{
QByteArray requestMethod = job->requestMethod();
if (requestMethod != "GET") {
job->fail(QWebEngineUrlRequestJob::RequestDenied);
return;
}

QUrl requestUrl = job->requestUrl();
QString requestPath = requestUrl.path();
QScopedPointer<QFile> file(new QFile(':' + requestPath, job));
if (!file->exists() || file->size() == 0) {
job->fail(QWebEngineUrlRequestJob::UrlNotFound);
return;
}
QFileInfo fileInfo(*file);
QMimeDatabase mimeDatabase;
QMimeType mimeType = mimeDatabase.mimeTypeForFile(fileInfo);
if (mimeType.name() == "application/x-extension-html") {
mimeType = mimeDatabase.mimeTypeForName("text/html");
}
job->reply(mimeType.name().toUtf8(), file.take());
}
};

int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

QWebEngineUrlScheme qrcScheme(QByteArrayLiteral("qrc"));
qrcScheme.setFlags(QWebEngineUrlScheme::SecureScheme
| QWebEngineUrlScheme::LocalAccessAllowed
| QWebEngineUrlScheme::CorsEnabled
| QWebEngineUrlScheme::ViewSourceAllowed);
QWebEngineUrlScheme::registerScheme(qrcScheme);
QWebEngineUrlScheme aqrcScheme(QByteArrayLiteral("aqrc"));
aqrcScheme.setFlags(QWebEngineUrlScheme::SecureScheme
| QWebEngineUrlScheme::LocalAccessAllowed
| QWebEngineUrlScheme::CorsEnabled
| QWebEngineUrlScheme::ViewSourceAllowed);
QWebEngineUrlScheme::registerScheme(qrcScheme);
QWebEngineUrlScheme::registerScheme(aqrcScheme);

QtWebEngine::initialize();
QGuiApplication app(argc, argv);

WorkaroundSchemeHandler *handler = new WorkaroundSchemeHandler(&app);
QQuickWebEngineProfile::defaultProfile()->installUrlSchemeHandler("aqrc", handler);

app.setDesktopFileName("org.opensuse.opensuse_welcome.desktop");
app.setOrganizationName("openSUSE");
app.setOrganizationDomain("opensuse.org");
Expand All @@ -43,7 +97,6 @@ int main(int argc, char *argv[])
qmlRegisterType<Enabler>("org.openSUSE.Welcome", 1, 0, "Enabler");
qmlRegisterType<PanelLayouter>("org.openSUSE.Welcome", 1, 0, "XfceLayouter");

qDebug() << QLocale::system().name();
QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(),
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
Expand All @@ -63,6 +116,5 @@ int main(int argc, char *argv[])
if (engine.rootObjects().isEmpty())
return -1;

QtWebEngine::initialize();
return app.exec();
}

0 comments on commit 5bcc456

Please sign in to comment.