diff --git a/CMakeLists.txt b/CMakeLists.txt index a7a0da7..36644da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,8 +39,9 @@ qt_add_executable(LibreELEC.USB-SD.Creator WIN32 MACOSX_BUNDLE # TODO: use Qt's template /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}" ) diff --git a/dmg_osx/main.scpt.txt b/dmg_osx/main.scpt.txt deleted file mode 100644 index 9199bf4..0000000 --- a/dmg_osx/main.scpt.txt +++ /dev/null @@ -1,11 +0,0 @@ --- https://discussions.apple.com/message/23355413#23355413 --- https://discussions.apple.com/thread/133512?start=0&tstart=0 - -set myPath to POSIX path of (path to me as text) -- gets it in "/" form -set ASTID to AppleScript's text item delimiters -- save 'em -set AppleScript's text item delimiters to "/" -set theFolder to (text 1 thru text item -2 of myPath) & "/" as Unicode text -set AppleScript's text item delimiters to ASTID -- restore 'em -set execpath to theFolder & "Contents/MacOS/LibreELEC USB-SD Creator" -set quotedexec to quoted form of execpath -do shell script "sudo " & quotedexec with administrator privileges diff --git a/dmg_osx/template.app/Contents/Info.plist b/dmg_osx/template.app/Contents/Info.plist index cb9fb82..52460b1 100644 --- a/dmg_osx/template.app/Contents/Info.plist +++ b/dmg_osx/template.app/Contents/Info.plist @@ -15,7 +15,7 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleName - LibreELEC + ${MACOSX_BUNDLE_BUNDLE_NAME} CFBundlePackageType APPL CFBundleSignature diff --git a/dmg_osx/template.app/Contents/MacOS/askPass.js b/dmg_osx/template.app/Contents/MacOS/askPass.js deleted file mode 100644 index cfe886f..0000000 --- a/dmg_osx/template.app/Contents/MacOS/askPass.js +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env osascript -l JavaScript - -// Setup application for scripting -const app = Application.currentApplication(); -app.includeStandardAdditions = true; - -const dialogOptions = { - buttons: ['Cancel', 'Ok'], - defaultAnswer: '', - defaultButton: 'Ok', - hiddenAnswer: true, - withIcon: 'caution', -}; - -try { - const result = app.displayDialog('LibreELEC USB-SD Creator wants to make changes. Type your password to allow this.', dialogOptions); - - if (result.buttonReturned === 'Ok') { - result.textReturned - } -} -catch (e) { - // Canceled -} diff --git a/main.cpp b/main.cpp index a8b304d..9da947a 100644 --- a/main.cpp +++ b/main.cpp @@ -22,6 +22,9 @@ #ifdef Q_OS_MACOS #include "privileges_unix.h" + +#include +#include #else #include "privileges.h" #endif @@ -29,47 +32,42 @@ #include #include #include -#include #include #include #include +#ifndef ALWAYS_DEBUG_OUTPUT void noMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) { Q_UNUSED(type); Q_UNUSED(context); Q_UNUSED(msg); } +#endif int main(int argc, char *argv[]) { QApplication app(argc, argv); - QString argFile = ""; + + const auto cmdArgs = app.arguments(); #ifndef ALWAYS_DEBUG_OUTPUT - if (app.arguments().contains("--debug") == false) + if (cmdArgs.contains("--debug") == false) qInstallMessageHandler(noMessageOutput); #endif #ifdef Q_OS_MACOS // If not running with root privileges, relaunch executable with sudo. - if (getuid() != 0 && app.arguments().contains("--elevated") == false) + if (getuid() != 0 && cmdArgs.contains("--elevated") == false) { - QString askPassCommand = QCoreApplication::applicationDirPath() + "/askPass.js"; - - QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); - env.insert("SUDO_ASKPASS", askPassCommand); + 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.setProcessEnvironment(env); - myProcess.setProgram("sudo"); - myProcess.setArguments(QStringList() - << "-A" - << QCoreApplication::applicationFilePath() - << "--elevated"); - bool success = myProcess.startDetached(); - - if (success) + myProcess.setProgram(QLatin1String{"osascript"}); + myProcess.setArguments({"-e", appleScript.arg(QCoreApplication::applicationFilePath(), sudoPrompt)}); + + if (myProcess.startDetached()) { return 0; } @@ -82,7 +80,7 @@ int main(int argc, char *argv[]) qDebug() << "App data: Version:" << BUILD_VERSION ", Build date: " BUILD_DATE; - if (app.arguments().contains("--no-proxy") == false) { + if (cmdArgs.contains("--no-proxy") == false) { QNetworkProxyQuery npq(QUrl("http://releases.libreelec.tv/")); QList listOfProxies = QNetworkProxyFactory::systemProxyForQuery(npq); if (listOfProxies.size()) { @@ -94,9 +92,10 @@ int main(int argc, char *argv[]) Privileges privileges = Privileges(); privileges.Whoami(); + QString argFile; // skip program filename - for (int i=1; i