Skip to content

Commit

Permalink
[macOS] show custom prompt in the permission elevation dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
kambala-decapitator committed Feb 20, 2024
1 parent df4feda commit ca5bb1f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ qt_add_executable(LibreELEC.USB-SD.Creator WIN32 MACOSX_BUNDLE
# TODO: use Qt's template <QTDIR>/lib/cmake/Qt6/macos/Info.plist.app.in
set_target_properties(LibreELEC.USB-SD.Creator PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "dmg_osx/template.app/Contents/Info.plist"
MACOSX_BUNDLE_GUI_IDENTIFIER "tv.libreelec.usb-sd-creator"
MACOSX_BUNDLE_BUNDLE_NAME "LibreELEC USB-SD Creator"
MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_VERSION}"
MACOSX_BUNDLE_GUI_IDENTIFIER "tv.libreelec.usb-sd-creator"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
)

Expand Down
2 changes: 1 addition & 1 deletion dmg_osx/template.app/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>LibreELEC</string>
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
Expand Down
8 changes: 4 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ int main(int argc, char *argv[])
// If not running with root privileges, relaunch executable with sudo.
if (getuid() != 0 && app.arguments().contains("--elevated") == false)
{
const QLatin1String appleScript{"do shell script \"sudo %1\" with administrator privileges"};
const auto sudoPrompt = QLatin1String{"%1 requires admin permissions."}.arg(app.applicationDisplayName());
const QLatin1String appleScript{"do shell script \"sudo %1\" with prompt \"%2\" with administrator privileges"};

QProcess myProcess;
myProcess.setProgram(QLatin1String{"osascript"});
myProcess.setArguments({"-e", appleScript.arg(QCoreApplication::applicationFilePath())});
bool success = myProcess.startDetached();
myProcess.setArguments({"-e", appleScript.arg(QCoreApplication::applicationFilePath(), sudoPrompt)});

if (success)
if (myProcess.startDetached())
{
return 0;
}
Expand Down

0 comments on commit ca5bb1f

Please sign in to comment.