diff options
author | Ryan Cao <70191398+ryanccn@users.noreply.github.com> | 2022-11-05 22:15:31 +0800 |
---|---|---|
committer | Ryan Cao <70191398+ryanccn@users.noreply.github.com> | 2022-11-05 22:18:05 +0800 |
commit | cf3aad9c414782996b11cb0779a9c3d7252b5420 (patch) | |
tree | 129f0d4bb4d8cb616a89b37042c0ccb6ec97f276 /launcher/ui/MainWindow.cpp | |
parent | 7b1e68bfa8cf9d46e0c810cfa0f077427cfc707a (diff) | |
download | PrismLauncher-cf3aad9c414782996b11cb0779a9c3d7252b5420.tar.gz PrismLauncher-cf3aad9c414782996b11cb0779a9c3d7252b5420.tar.bz2 PrismLauncher-cf3aad9c414782996b11cb0779a9c3d7252b5420.zip |
fix: use `osascript` to get admin privileges
inspired from VSCode's approach
Signed-off-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com>
Diffstat (limited to 'launcher/ui/MainWindow.cpp')
-rw-r--r-- | launcher/ui/MainWindow.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 80d212e9..beb73c81 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -1920,14 +1920,15 @@ void MainWindow::on_actionClearMetadata_triggered() } void MainWindow::on_actionAddToPATH_triggered() { - auto binaryPath = APPLICATION->arguments().first(); + auto binaryPath = APPLICATION->applicationFilePath(); - auto outcome = FS::symlink(binaryPath, "/usr/local/bin/prism"); + qDebug() << "Symlinking" << binaryPath << "to /usr/local/bin/prism"; + auto outcome = QProcess::execute("/usr/bin/osascript", QStringList()<< "-e" << tr("do shell script \"mkdir -p /usr/local/bin && ln -sf '%1' '/usr/local/bin/prismlauncher'\" with administrator privileges").arg(binaryPath)); if (!outcome) { - QMessageBox::critical(this, tr("Failed to add Prism to PATH"), tr("")); + QMessageBox::information(this, tr("Added Prism to PATH"), tr("Prism was successfully added to your PATH. You can now run it with `prismlauncher` in your Terminal. Enjoy!")); } else { - QMessageBox::information(this, tr("Added Prism to PATH"), tr("Prism was successfully added to your PATH.")); + QMessageBox::critical(this, tr("Failed to add Prism to PATH"), tr("Failed to add Prism to PATH :(")); } } |