Merge pull request #112 from ryanccn/macos-add-to-path
This commit is contained in:
commit
f60b09568c
@ -61,6 +61,7 @@
|
|||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
@ -253,6 +254,9 @@ public:
|
|||||||
QMenu * helpMenu = nullptr;
|
QMenu * helpMenu = nullptr;
|
||||||
TranslatedToolButton helpMenuButton;
|
TranslatedToolButton helpMenuButton;
|
||||||
TranslatedAction actionClearMetadata;
|
TranslatedAction actionClearMetadata;
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
TranslatedAction actionAddToPATH;
|
||||||
|
#endif
|
||||||
TranslatedAction actionReportBug;
|
TranslatedAction actionReportBug;
|
||||||
TranslatedAction actionDISCORD;
|
TranslatedAction actionDISCORD;
|
||||||
TranslatedAction actionMATRIX;
|
TranslatedAction actionMATRIX;
|
||||||
@ -350,6 +354,14 @@ public:
|
|||||||
actionClearMetadata.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Clear cached metadata"));
|
actionClearMetadata.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Clear cached metadata"));
|
||||||
all_actions.append(&actionClearMetadata);
|
all_actions.append(&actionClearMetadata);
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
actionAddToPATH = TranslatedAction(MainWindow);
|
||||||
|
actionAddToPATH->setObjectName(QStringLiteral("actionAddToPATH"));
|
||||||
|
actionAddToPATH.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Install to &PATH"));
|
||||||
|
actionAddToPATH.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Install a prismlauncher symlink to /usr/local/bin"));
|
||||||
|
all_actions.append(&actionAddToPATH);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!BuildConfig.BUG_TRACKER_URL.isEmpty()) {
|
if (!BuildConfig.BUG_TRACKER_URL.isEmpty()) {
|
||||||
actionReportBug = TranslatedAction(MainWindow);
|
actionReportBug = TranslatedAction(MainWindow);
|
||||||
actionReportBug->setObjectName(QStringLiteral("actionReportBug"));
|
actionReportBug->setObjectName(QStringLiteral("actionReportBug"));
|
||||||
@ -455,6 +467,10 @@ public:
|
|||||||
|
|
||||||
helpMenu->addAction(actionClearMetadata);
|
helpMenu->addAction(actionClearMetadata);
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
helpMenu->addAction(actionAddToPATH);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!BuildConfig.BUG_TRACKER_URL.isEmpty()) {
|
if (!BuildConfig.BUG_TRACKER_URL.isEmpty()) {
|
||||||
helpMenu->addAction(actionReportBug);
|
helpMenu->addAction(actionReportBug);
|
||||||
}
|
}
|
||||||
@ -542,6 +558,9 @@ public:
|
|||||||
helpMenu = menuBar->addMenu(tr("&Help"));
|
helpMenu = menuBar->addMenu(tr("&Help"));
|
||||||
helpMenu->setSeparatorsCollapsible(false);
|
helpMenu->setSeparatorsCollapsible(false);
|
||||||
helpMenu->addAction(actionClearMetadata);
|
helpMenu->addAction(actionClearMetadata);
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
helpMenu->addAction(actionAddToPATH);
|
||||||
|
#endif
|
||||||
helpMenu->addSeparator();
|
helpMenu->addSeparator();
|
||||||
helpMenu->addAction(actionAbout);
|
helpMenu->addAction(actionAbout);
|
||||||
helpMenu->addAction(actionOpenWiki);
|
helpMenu->addAction(actionOpenWiki);
|
||||||
@ -1929,6 +1948,29 @@ void MainWindow::on_actionClearMetadata_triggered()
|
|||||||
APPLICATION->metacache()->SaveNow();
|
APPLICATION->metacache()->SaveNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
void MainWindow::on_actionAddToPATH_triggered()
|
||||||
|
{
|
||||||
|
auto binaryPath = APPLICATION->applicationFilePath();
|
||||||
|
auto targetPath = QString("/usr/local/bin/%1").arg(BuildConfig.LAUNCHER_APP_BINARY_NAME);
|
||||||
|
qDebug() << "Symlinking" << binaryPath << "to" << targetPath;
|
||||||
|
|
||||||
|
QStringList args;
|
||||||
|
args << "-e";
|
||||||
|
args << QString("do shell script \"mkdir -p /usr/local/bin && ln -sf '%1' '%2'\" with administrator privileges")
|
||||||
|
.arg(binaryPath, targetPath);
|
||||||
|
auto outcome = QProcess::execute("/usr/bin/osascript", args);
|
||||||
|
if (!outcome) {
|
||||||
|
QMessageBox::information(this, tr("Successfully added %1 to PATH").arg(BuildConfig.LAUNCHER_DISPLAYNAME),
|
||||||
|
tr("%1 was successfully added to your PATH. You can now start it by running `%2`.")
|
||||||
|
.arg(BuildConfig.LAUNCHER_DISPLAYNAME, BuildConfig.LAUNCHER_APP_BINARY_NAME));
|
||||||
|
} else {
|
||||||
|
QMessageBox::critical(this, tr("Failed to add %1 to PATH").arg(BuildConfig.LAUNCHER_DISPLAYNAME),
|
||||||
|
tr("An error occurred while trying to add %1 to PATH").arg(BuildConfig.LAUNCHER_DISPLAYNAME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void MainWindow::on_actionOpenWiki_triggered()
|
void MainWindow::on_actionOpenWiki_triggered()
|
||||||
{
|
{
|
||||||
DesktopServices::openUrl(QUrl(BuildConfig.HELP_URL.arg("")));
|
DesktopServices::openUrl(QUrl(BuildConfig.HELP_URL.arg("")));
|
||||||
|
@ -128,6 +128,10 @@ private slots:
|
|||||||
|
|
||||||
void on_actionClearMetadata_triggered();
|
void on_actionClearMetadata_triggered();
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
void on_actionAddToPATH_triggered();
|
||||||
|
#endif
|
||||||
|
|
||||||
void on_actionOpenWiki_triggered();
|
void on_actionOpenWiki_triggered();
|
||||||
|
|
||||||
void on_actionMoreNews_triggered();
|
void on_actionMoreNews_triggered();
|
||||||
|
Loading…
Reference in New Issue
Block a user