Merge pull request #568 from leo78913/flatpak-shortcuts

This commit is contained in:
flow 2022-12-08 17:53:33 -08:00 committed by GitHub
commit 9ad4ae5340
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -372,8 +372,6 @@ bool createShortcut(QString destination, QString target, QStringList args, QStri
return true; return true;
#elif defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) #elif defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD)
destination += ".desktop";
QFile f(destination); QFile f(destination);
f.open(QIODevice::WriteOnly | QIODevice::Text); f.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream stream(&f); QTextStream stream(&f);

View File

@ -2271,9 +2271,24 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered()
return; return;
} }
if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), QString desktopFilePath = FS::PathCombine(desktopPath, m_selectedInstance->name() + ".desktop");
appPath, { "--launch", m_selectedInstance->id() }, QStringList args;
m_selectedInstance->name(), iconPath)) { if (DesktopServices::isFlatpak()) {
QFileDialog fileDialog;
// workaround to make sure the portal file dialog opens in the desktop directory
fileDialog.setDirectoryUrl(desktopPath);
desktopFilePath = fileDialog.getSaveFileName(
this, tr("Create Shortcut"), desktopFilePath,
tr("Desktop Entries (*.desktop)"));
if (desktopFilePath.isEmpty())
return; // file dialog canceled by user
appPath = "flatpak";
QString flatpakAppId = BuildConfig.LAUNCHER_DESKTOPFILENAME;
flatpakAppId.remove(".desktop");
args.append({ "run", flatpakAppId });
}
args.append({ "--launch", m_selectedInstance->id() });
if (FS::createShortcut(desktopFilePath, appPath, args, m_selectedInstance->name(), iconPath)) {
QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!")); QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!"));
} }
else else