Skip to content

Commit

Permalink
Linux portable stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Aug 17, 2024
1 parent c450d2b commit a844c39
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,15 @@ int main(int argc, char *argv[])

#ifdef Q_OS_LINUX
if (AppSupport::isAppPortable()) {
if (QApplication::arguments().contains("--xdg-remove")) {
const auto args = QApplication::arguments();
if (args.contains("--xdg-remove")) {
const bool removedXDG = AppSupport::removeXDGDesktopIntegration();
qWarning() << "Removed XDG Integration:" << removedXDG;
return removedXDG ? 0 : -1;
} else if (args.contains("--xdg-install")) {
const bool installedXDG = AppSupport::setupXDGDesktopIntegration();
qWarning() << "Installed XDG Integration:" << installedXDG;
return installedXDG ? 0 : -1;
}
}
#endif
Expand Down Expand Up @@ -208,17 +213,22 @@ int main(int argc, char *argv[])
if (AppSupport::isAppPortable()) {
if (!AppSupport::hasXDGDesktopIntegration()) {
const auto ask = QMessageBox::question(nullptr,
QObject::tr("Setup Desktop Integration?"),
QObject::tr("Setup Desktop Integration"),
QObject::tr("Would you like to setup desktop integration?"
" This will add Friction to your application launcher"
" and add mime type for project files."));
" and add required mime types.<br><br>"
"You also can manage the desktop integration with:"
"<br><br><code>friction --xdg-install</code>"
"<br><code>friction --xdg-remove</code>"));
if (ask == QMessageBox::Yes) {
if (!AppSupport::setupXDGDesktopIntegration()) {
QMessageBox::warning(nullptr,
QObject::tr("Desktop Integration Failed"),
QObject::tr("Failed to install the required files for desktop integration,"
" please check your permissions."));
}
} else {
AppSupport::setSettings("portable", "ignoreXDG", true);
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/core/appsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,9 @@ bool AppSupport::isAppPortable()

bool AppSupport::hasXDGDesktopIntegration()
{
const bool ignoreXDG = getSettings("portable", "ignoreXDG", false).toBool();
if (ignoreXDG) { return true; }

QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
if (path.isEmpty() ||
!path.startsWith(QDir::homePath())) { path = QString("%1/.local/share").arg(QDir::homePath()); }
Expand Down Expand Up @@ -881,7 +884,10 @@ bool AppSupport::removeXDGDesktopIntegration()
for (const auto &file : files) {
QFile fileName(QString("%1/%2").arg(path, file));
if (fileName.exists()) {
if (!fileName.remove()) { return false; }
if (!fileName.remove()) {
qWarning() << "Failed to remove" << fileName;
return false;
}
}
}
return true;
Expand Down

0 comments on commit a844c39

Please sign in to comment.