mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-05-24 19:02:16 +02:00
added instance shortcut feature
Signed-off-by: sshcrack <34072808+sshcrack@users.noreply.github.com>
This commit is contained in:
parent
79439a0217
commit
a737d5df42
@ -701,6 +701,9 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
|
|||||||
m_settings->registerSetting("InstSortMode", "Name");
|
m_settings->registerSetting("InstSortMode", "Name");
|
||||||
m_settings->registerSetting("SelectedInstance", QString());
|
m_settings->registerSetting("SelectedInstance", QString());
|
||||||
|
|
||||||
|
// Shortcut creation
|
||||||
|
m_settings->registerSetting("ShortcutCreationMode", "Desktop");
|
||||||
|
|
||||||
// Window state and geometry
|
// Window state and geometry
|
||||||
m_settings->registerSetting("MainWindowState", "");
|
m_settings->registerSetting("MainWindowState", "");
|
||||||
m_settings->registerSetting("MainWindowGeometry", "");
|
m_settings->registerSetting("MainWindowGeometry", "");
|
||||||
|
@ -915,6 +915,11 @@ QString getDesktopDir()
|
|||||||
return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString getApplicationsDir()
|
||||||
|
{
|
||||||
|
return QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
|
||||||
|
}
|
||||||
|
|
||||||
// Cross-platform Shortcut creation
|
// Cross-platform Shortcut creation
|
||||||
bool createShortcut(QString destination, QString target, QStringList args, QString name, QString icon)
|
bool createShortcut(QString destination, QString target, QStringList args, QString name, QString icon)
|
||||||
{
|
{
|
||||||
|
@ -353,6 +353,9 @@ bool checkProblemticPathJava(QDir folder);
|
|||||||
// Get the Directory representing the User's Desktop
|
// Get the Directory representing the User's Desktop
|
||||||
QString getDesktopDir();
|
QString getDesktopDir();
|
||||||
|
|
||||||
|
// Get the Directory representing the User's Applications directory
|
||||||
|
QString getApplicationsDir();
|
||||||
|
|
||||||
// Overrides one folder with the contents of another, preserving items exclusive to the first folder
|
// Overrides one folder with the contents of another, preserving items exclusive to the first folder
|
||||||
// Equivalent to doing QDir::rename, but allowing for overrides
|
// Equivalent to doing QDir::rename, but allowing for overrides
|
||||||
bool overrideFolder(QString overwritten_path, QString override_path);
|
bool overrideFolder(QString overwritten_path, QString override_path);
|
||||||
|
@ -1495,14 +1495,27 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered()
|
|||||||
{
|
{
|
||||||
if (!m_selectedInstance)
|
if (!m_selectedInstance)
|
||||||
return;
|
return;
|
||||||
auto desktopPath = FS::getDesktopDir();
|
|
||||||
if (desktopPath.isEmpty()) {
|
std::vector<QString> paths;
|
||||||
|
QString mode = APPLICATION->settings()->get("ShortcutCreationMode").toString();
|
||||||
|
if (mode == "Applications") {
|
||||||
|
paths.push_back(FS::getApplicationsDir());
|
||||||
|
} else if (mode == "Both") {
|
||||||
|
paths.push_back(FS::getDesktopDir());
|
||||||
|
paths.push_back(FS::getApplicationsDir());
|
||||||
|
} else {
|
||||||
|
// Default to desktop
|
||||||
|
paths.push_back(FS::getDesktopDir());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const QString& shortcutDirPath : paths) {
|
||||||
|
if (shortcutDirPath.isEmpty()) {
|
||||||
// TODO come up with an alternative solution (open "save file" dialog)
|
// TODO come up with an alternative solution (open "save file" dialog)
|
||||||
QMessageBox::critical(this, tr("Create instance shortcut"), tr("Couldn't find desktop?!"));
|
QMessageBox::critical(this, tr("Create instance shortcut"), tr("Couldn't find desktop?!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString desktopFilePath;
|
QString shortcutFilePath;
|
||||||
QString appPath = QApplication::applicationFilePath();
|
QString appPath = QApplication::applicationFilePath();
|
||||||
QString iconPath;
|
QString iconPath;
|
||||||
QStringList args;
|
QStringList args;
|
||||||
@ -1571,12 +1584,13 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (DesktopServices::isFlatpak()) {
|
if (DesktopServices::isFlatpak()) {
|
||||||
desktopFilePath = FS::PathCombine(desktopPath, FS::RemoveInvalidFilenameChars(m_selectedInstance->name()) + ".desktop");
|
shortcutFilePath = FS::PathCombine(shortcutDirPath, FS::RemoveInvalidFilenameChars(m_selectedInstance->name()) + ".desktop");
|
||||||
QFileDialog fileDialog;
|
QFileDialog fileDialog;
|
||||||
// workaround to make sure the portal file dialog opens in the desktop directory
|
// workaround to make sure the portal file dialog opens in the desktop directory
|
||||||
fileDialog.setDirectoryUrl(desktopPath);
|
fileDialog.setDirectoryUrl(shortcutDirPath);
|
||||||
desktopFilePath = fileDialog.getSaveFileName(this, tr("Create Shortcut"), desktopFilePath, tr("Desktop Entries") + " (*.desktop)");
|
shortcutFilePath =
|
||||||
if (desktopFilePath.isEmpty())
|
fileDialog.getSaveFileName(this, tr("Create Shortcut"), shortcutFilePath, tr("Desktop Entries") + " (*.desktop)");
|
||||||
|
if (shortcutFilePath.isEmpty())
|
||||||
return; // file dialog canceled by user
|
return; // file dialog canceled by user
|
||||||
appPath = "flatpak";
|
appPath = "flatpak";
|
||||||
QString flatpakAppId = BuildConfig.LAUNCHER_DESKTOPFILENAME;
|
QString flatpakAppId = BuildConfig.LAUNCHER_DESKTOPFILENAME;
|
||||||
@ -1618,19 +1632,22 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered()
|
|||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
args.append({ "--launch", m_selectedInstance->id() });
|
args.append({ "--launch", m_selectedInstance->id() });
|
||||||
if (FS::createShortcut(desktopFilePath, appPath, args, m_selectedInstance->name(), iconPath)) {
|
|
||||||
#if not defined(Q_OS_MACOS)
|
if (shortcutFilePath.isEmpty())
|
||||||
QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!"));
|
shortcutFilePath = FS::PathCombine(shortcutDirPath, FS::RemoveInvalidFilenameChars(m_selectedInstance->name()));
|
||||||
#else
|
if (!FS::createShortcut(shortcutFilePath, appPath, args, m_selectedInstance->name(), iconPath)) {
|
||||||
QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance!"));
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
#if not defined(Q_OS_MACOS)
|
#if not defined(Q_OS_MACOS)
|
||||||
iconFile.remove();
|
iconFile.remove();
|
||||||
#endif
|
#endif
|
||||||
QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!"));
|
QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if not defined(Q_OS_MACOS)
|
||||||
|
QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance!"));
|
||||||
|
#else
|
||||||
|
QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance!"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::taskEnd()
|
void MainWindow::taskEnd()
|
||||||
{
|
{
|
||||||
|
@ -65,6 +65,15 @@ enum InstSortMode {
|
|||||||
Sort_LastLaunch
|
Sort_LastLaunch
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ShortcutCreationMode {
|
||||||
|
// Create a shortcut in the applications
|
||||||
|
Shortcut_OnlyApplications,
|
||||||
|
// Create a shortcut in both locations
|
||||||
|
Shortcut_Both,
|
||||||
|
// Create a shortcut on the desktop
|
||||||
|
Shortcut_OnlyDesktop
|
||||||
|
};
|
||||||
|
|
||||||
LauncherPage::LauncherPage(QWidget* parent) : QWidget(parent), ui(new Ui::LauncherPage)
|
LauncherPage::LauncherPage(QWidget* parent) : QWidget(parent), ui(new Ui::LauncherPage)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
@ -254,6 +263,19 @@ void LauncherPage::applySettings()
|
|||||||
s->set("ModMetadataDisabled", ui->metadataDisableBtn->isChecked());
|
s->set("ModMetadataDisabled", ui->metadataDisableBtn->isChecked());
|
||||||
s->set("ModDependenciesDisabled", ui->dependenciesDisableBtn->isChecked());
|
s->set("ModDependenciesDisabled", ui->dependenciesDisableBtn->isChecked());
|
||||||
s->set("SkipModpackUpdatePrompt", ui->skipModpackUpdatePromptBtn->isChecked());
|
s->set("SkipModpackUpdatePrompt", ui->skipModpackUpdatePromptBtn->isChecked());
|
||||||
|
|
||||||
|
auto shortcutMode = (ShortcutCreationMode) ui->createShortcutActionComboBox->currentIndex();
|
||||||
|
switch (shortcutMode) {
|
||||||
|
case Shortcut_OnlyApplications:
|
||||||
|
s->set("ShortcutCreationMode", "Applications");
|
||||||
|
break;
|
||||||
|
case Shortcut_Both:
|
||||||
|
s->set("ShortcutCreationMode", "Both");
|
||||||
|
break;
|
||||||
|
case Shortcut_OnlyDesktop:
|
||||||
|
s->set("ShortcutCreationMode", "Desktop");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void LauncherPage::loadSettings()
|
void LauncherPage::loadSettings()
|
||||||
{
|
{
|
||||||
@ -319,6 +341,19 @@ void LauncherPage::loadSettings()
|
|||||||
ui->metadataWarningLabel->setHidden(!ui->metadataDisableBtn->isChecked());
|
ui->metadataWarningLabel->setHidden(!ui->metadataDisableBtn->isChecked());
|
||||||
ui->dependenciesDisableBtn->setChecked(s->get("ModDependenciesDisabled").toBool());
|
ui->dependenciesDisableBtn->setChecked(s->get("ModDependenciesDisabled").toBool());
|
||||||
ui->skipModpackUpdatePromptBtn->setChecked(s->get("SkipModpackUpdatePrompt").toBool());
|
ui->skipModpackUpdatePromptBtn->setChecked(s->get("SkipModpackUpdatePrompt").toBool());
|
||||||
|
|
||||||
|
QString shortcutModeStr = s->get("ShortcutCreationMode").toString();
|
||||||
|
ShortcutCreationMode shortcutMode = Shortcut_OnlyDesktop;
|
||||||
|
if(shortcutModeStr == "Applications") {
|
||||||
|
shortcutMode = Shortcut_OnlyApplications;
|
||||||
|
} else if(shortcutModeStr == "Desktop") {
|
||||||
|
// Guess we don't need that, but it's here for completeness
|
||||||
|
shortcutMode = Shortcut_OnlyDesktop;
|
||||||
|
} else if(shortcutModeStr == "Both") {
|
||||||
|
shortcutMode = Shortcut_Both;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->createShortcutActionComboBox->setCurrentIndex(shortcutMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LauncherPage::refreshFontPreview()
|
void LauncherPage::refreshFontPreview()
|
||||||
|
@ -282,41 +282,6 @@
|
|||||||
<string>Miscellaneous</string>
|
<string>Miscellaneous</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QSpinBox" name="numberOfConcurrentDownloadsSpinBox">
|
|
||||||
<property name="minimum">
|
|
||||||
<number>1</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="numberOfConcurrentTasksLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Number of concurrent tasks</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QSpinBox" name="numberOfConcurrentTasksSpinBox">
|
|
||||||
<property name="minimum">
|
|
||||||
<number>1</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="numberOfConcurrentDownloadsLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Number of concurrent downloads</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="numberOfManualRetriesLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Number of manual retries</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QSpinBox" name="numberOfManualRetriesSpinBox">
|
<widget class="QSpinBox" name="numberOfManualRetriesSpinBox">
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
@ -334,6 +299,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QSpinBox" name="numberOfConcurrentDownloadsSpinBox">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="3" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="QSpinBox" name="timeoutSecondsSpinBox">
|
<widget class="QSpinBox" name="timeoutSecondsSpinBox">
|
||||||
<property name="suffix">
|
<property name="suffix">
|
||||||
@ -341,6 +313,60 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="numberOfConcurrentDownloadsLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Number of concurrent downloads</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="numberOfManualRetriesLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Number of manual retries</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="numberOfConcurrentTasksLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Number of concurrent tasks</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QSpinBox" name="numberOfConcurrentTasksSpinBox">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="0">
|
||||||
|
<widget class="QLabel" name="createShortcutActionLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Create shortcut action</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="1">
|
||||||
|
<widget class="QComboBox" name="createShortcutActionComboBox">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Applications only</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Applications & Desktop</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Desktop only</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user