Skip to content

Commit

Permalink
AppImage - support for embedded documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
triplus committed Oct 6, 2019
1 parent 6663d62 commit f100424
Showing 1 changed file with 45 additions and 26 deletions.
71 changes: 45 additions & 26 deletions src/Gui/Assistant.cpp
Expand Up @@ -99,32 +99,6 @@ bool Assistant::startAssistant()
QString doc = QString::fromUtf8(App::Application::getHelpDir().c_str());
QString qhc = doc + exe.toLower() + QLatin1String(".qhc");

// AppImage mount location changes on each start. Assistant caches freecad.qhc
// file and sets an absolute path. As a result embedded documentation only works
// on the first AppImage start. Register the .gch file, to overcome the issue.
static bool start = true;
if (start) {
char* appimage = getenv("APPIMAGE");
if (appimage) {
QString qch = doc + exe.toLower() + QLatin1String(".qch");
QFileInfo fi(qch);
if (!fi.isReadable()) {
QMessageBox::critical(0, tr("%1 Help").arg(exe),
tr("%1 help files not found (%2). You might need to install the %1 documentation package.").arg(exe, qch));
return false;
}
Base::Console().Log("Help file at %s\n", (const char*)qch.toUtf8());
QStringList args;
args << QLatin1String("-register") << qch;
proc->start(app, args);
if (!proc->waitForFinished(50000)) {
QMessageBox::critical(0, tr("%1 Help").arg(exe),
tr("Unable to launch Qt Assistant (%1)").arg(app));
return false;
}
}
start = false;
}

QFileInfo fi(qhc);
if (!fi.isReadable()) {
Expand All @@ -139,6 +113,51 @@ bool Assistant::startAssistant()
first = false;
}

// AppImage start
// AppImage mount location changes on each start. Assistant caches freecad.qhc
// file and sets an absolute path. As a result embedded documentation only works
// on the first AppImage (help) run. Register the .gch file, to overcome the issue.
static bool start = true;
if (start) {
char* appimage = getenv("APPIMAGE");
if (appimage) {
QString qch = doc + exe.toLower() + QLatin1String(".qch");
QFileInfo fi(qch);
if (fi.isReadable()) {
// Assume documentation is embedded
// Unregister qch file (path) from previous AppImage run
QStringList args;

args << QLatin1String("-collectionFile") << qhc
<< QLatin1String("-unregister") << qch;

proc->start(app, args);

if (!proc->waitForFinished(50000)) {
QMessageBox::critical(0, tr("%1 Help").arg(exe),
tr("Unable to launch Qt Assistant (%1)").arg(app));
return false;
}

// Register qch file (path) for current AppImage run
args.clear();

args << QLatin1String("-collectionFile") << qhc
<< QLatin1String("-register") << qch;

proc->start(app, args);

if (!proc->waitForFinished(50000)) {
QMessageBox::critical(0, tr("%1 Help").arg(exe),
tr("Unable to launch Qt Assistant (%1)").arg(app));
return false;
}
}
}
start = false;
}
// AppImage end

QStringList args;

args << QLatin1String("-collectionFile") << qhc
Expand Down

0 comments on commit f100424

Please sign in to comment.