Skip to content

Commit

Permalink
[docs:3.18] Workaround dysfunctional anchors
Browse files Browse the repository at this point in the history
Close #109

Co-authored-by: @brenns10
  • Loading branch information
ManuelSchneid3r committed Aug 20, 2024
1 parent 1995a7a commit 04f2d44
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if(NOT APPLE)

cmake_minimum_required(VERSION 3.17)
cmake_minimum_required(VERSION 3.18)
find_package(Albert REQUIRED)

project(docs VERSION 6.5)
Expand Down
30 changes: 23 additions & 7 deletions docs/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace albert;
using namespace std;

static const char *docsets_dir = "docsets";
Plugin *plugin;

static QString extract(const QString &src, const QString &dst)
{
Expand Down Expand Up @@ -123,20 +124,35 @@ class DocumentationItem : public albert::Item
{ return name; }

vector<Action> actions() const override
{ return {{ id(), Plugin::tr("Open documentation"), [this] { open(); } }}; }

// Workaround for some browsers not opening "file:" urls having an anchor
void open() const
{
return {
{
id(), Plugin::tr("Open documentation"), [this] {
openUrl(QString("file://%1/Contents/Resources/Documents/%2")
.arg(docset->path, path));
}
}};
// QTemporaryFile will not work here because its deletion introduces race condition
if (QFile file(QDir(plugin->cacheLocation()).filePath("trampoline.html"));
file.open(QIODevice::WriteOnly))
{
auto s = QString("file://%1/Contents/Resources/Documents/%2").arg(docset->path, path);
s = QString(R"(<html><head><meta http-equiv="refresh" content="0;%1"></head></html>)")
.arg(s);

QTextStream stream(&file);
stream << s;
file.close();

openUrl("file:" + file.fileName());
}
else
WARN << "Failed to open file for writing" << file.fileName() << file.errorString();
}
};


Plugin::Plugin()
{
::plugin = this;

if(!QSqlDatabase::isDriverAvailable("QSQLITE"))
throw "QSQLITE driver unavailable";

Expand Down

0 comments on commit 04f2d44

Please sign in to comment.