aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui/MainWindow.cpp
diff options
context:
space:
mode:
authorADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com>2022-11-13 17:51:29 +0200
committerADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com>2022-11-13 17:51:29 +0200
commitb0269e6dfc685cd002340e95e80942410f1b1fc5 (patch)
tree60c4b3726472d1b03427bb2152d502b7668ad5a2 /launcher/ui/MainWindow.cpp
parent43b9d9484da280fc209a0c9f195b0ca338eacdb9 (diff)
downloadPrismLauncher-b0269e6dfc685cd002340e95e80942410f1b1fc5.tar.gz
PrismLauncher-b0269e6dfc685cd002340e95e80942410f1b1fc5.tar.bz2
PrismLauncher-b0269e6dfc685cd002340e95e80942410f1b1fc5.zip
Linux: fixes
- Fix shortcut icons - Possibly fix shortcut creation on AppImages - Fix shortcut not working if path to launcher contains spaces Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com>
Diffstat (limited to 'launcher/ui/MainWindow.cpp')
-rw-r--r--launcher/ui/MainWindow.cpp48
1 files changed, 42 insertions, 6 deletions
diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp
index c7de46c7..4dbac967 100644
--- a/launcher/ui/MainWindow.cpp
+++ b/launcher/ui/MainWindow.cpp
@@ -2101,13 +2101,14 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered()
#if defined(Q_OS_MACOS)
QString appPath = QApplication::applicationFilePath();
- if (appPath.startsWith("/private/var")) {
+ if (appPath.startsWith("/private/var/")) {
QMessageBox::critical(this, tr("Create instance shortcut"), tr("The launcher is in the folder it was extracted from, therefore it cannot create shortcuts."));
return;
}
if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()),
- appPath, { "--launch", m_selectedInstance->id() }, m_selectedInstance->name(), "")) {
+ appPath, { "--launch", m_selectedInstance->id() },
+ m_selectedInstance->name(), "")) {
QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!"));
}
else
@@ -2115,14 +2116,48 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered()
QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!"));
}
#elif defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD)
+ QString appPath = QApplication::applicationFilePath();
+ if (appPath.startsWith("/tmp/.mount_")) {
+ // AppImage!
+ appPath = QProcessEnvironment::systemEnvironment().value(QStringLiteral("APPIMAGE"));
+ if (appPath.isEmpty())
+ {
+ QMessageBox::critical(this, tr("Create instance shortcut"), tr("Launcher is running as misconfigured AppImage? ($APPIMAGE environment variable is missing)"));
+ }
+ else if (appPath.endsWith("/"))
+ {
+ appPath.chop(1);
+ }
+ }
+
auto icon = APPLICATION->icons()->icon(m_selectedInstance->iconKey());
+ QString iconPath = FS::PathCombine(m_selectedInstance->instanceRoot(), "icon.png");
+
+ QFile iconFile(iconPath);
+ if (!iconFile.open(QFile::WriteOnly))
+ {
+ QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create icon for shortcut."));
+ return;
+ }
+ bool success = icon->icon().pixmap(64, 64).save(&iconFile, "PNG");
+ iconFile.close();
+
+ if (!success)
+ {
+ iconFile.remove();
+ QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create icon for shortcut."));
+ return;
+ }
+
if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()),
- QApplication::applicationFilePath(), { "--launch", m_selectedInstance->id() }, m_selectedInstance->name(), icon->getFilePath())) {
+ appPath, { "--launch", m_selectedInstance->id() },
+ m_selectedInstance->name(), iconPath)) {
QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!"));
}
else
{
+ iconFile.remove();
QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!"));
}
#elif defined(Q_OS_WIN)
@@ -2137,7 +2172,7 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered()
QFile iconFile(iconPath);
if (!iconFile.open(QFile::WriteOnly))
{
- QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!"));
+ QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create icon for shortcut."));
return;
}
bool success = icon->icon().pixmap(64, 64).save(&iconFile, "ICO");
@@ -2149,12 +2184,13 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered()
if (!success)
{
iconFile.remove();
- QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!"));
+ QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create icon for shortcut."));
return;
}
if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()),
- QApplication::applicationFilePath(), { "--launch", m_selectedInstance->id() }, m_selectedInstance->name(), iconPath)) {
+ QApplication::applicationFilePath(), { "--launch", m_selectedInstance->id() },
+ m_selectedInstance->name(), iconPath)) {
QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!"));
}
else