diff --git a/.github/workflows/build-qv2ray-cmake.yml b/.github/workflows/build-qv2ray-cmake.yml index 65e8a6b..acb96fe 100644 --- a/.github/workflows/build-qv2ray-cmake.yml +++ b/.github/workflows/build-qv2ray-cmake.yml @@ -100,7 +100,7 @@ jobs: # ========================================================================================================= Qt Install - name: Install Qt if: matrix.platform != 'windows-2022' - uses: jurplel/install-qt-action@v4.0.0 + uses: jurplel/install-qt-action@v4.1.1 with: version: ${{ matrix.qt_version }} setup-python: true @@ -108,9 +108,8 @@ jobs: cache-key-prefix: QtCache-${{ matrix.platform }}-${{ matrix.arch }} - name: Install Qt Windows if: matrix.platform == 'windows-2022' - uses: jurplel/install-qt-action@v4.0.0 + uses: jurplel/install-qt-action@v4.1.1 with: - arch: win64_msvc2022_64 version: ${{ matrix.qt_version }} cache: true cache-key-prefix: QtCache-${{ matrix.platform }}-${{ matrix.arch }} @@ -209,11 +208,13 @@ jobs: zip -r $version_standalone-windows64.zip nekoray rm -rf nekoray #### - mv macos-arm64/nekoray.dmg $version_standalone-macos-arm64.dmg - rm -rf macos-arm64/nekoray.dmg + mv macos-arm64/nekoray.app nekoray + zip -r $version_standalone-macos-arm64.zip nekoray + rm -rf nekoray #### - mv macos-amd64/nekoray.dmg $version_standalone-macos-amd64.dmg - rm -rf macos-amd64/nekoray.dmg + mv macos-amd64/nekoray.app nekoray + zip -r $version_standalone-macos-amd64.zip nekoray + rm -rf nekoray - name: Clean Up run: | cd deployment diff --git a/CMakeLists.txt b/CMakeLists.txt index 90e313d..8b69e41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -195,6 +195,8 @@ set(PROJECT_SOURCES ui/edit/edit_ssh.h ui/edit/edit_ssh.ui fmt/SSHBean.h + sys/macos/MacOS.cpp + sys/macos/MacOS.h ) # Qt exe diff --git a/cmake/macos/macos.cmake b/cmake/macos/macos.cmake index e69de29..419252c 100644 --- a/cmake/macos/macos.cmake +++ b/cmake/macos/macos.cmake @@ -0,0 +1,3 @@ +find_library(SECURITY_FRAMEWORK Security) +set(PLATFORM_SOURCES sys/macos/MacOS.cpp) +set(PLATFORM_LIBRARIES ${SECURITY_FRAMEWORK}) \ No newline at end of file diff --git a/libs/build_deps_all.sh b/libs/build_deps_all.sh index 1bfd4be..1cb578b 100755 --- a/libs/build_deps_all.sh +++ b/libs/build_deps_all.sh @@ -61,6 +61,8 @@ $cmake .. -GNinja \ -Dprotobuf_MSVC_STATIC_RUNTIME=OFF \ -Dprotobuf_BUILD_TESTS=OFF \ -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \ + -Dprotobuf_BUILD_PROTOBUF_BINARIES=ON \ + -Dprotobuf_BUILD_LIBUPB=OFF \ -DCMAKE_CXX_STANDARD=17 ninja && ninja install diff --git a/libs/deploy_macos.sh b/libs/deploy_macos.sh index ae43de3..af3e86c 100755 --- a/libs/deploy_macos.sh +++ b/libs/deploy_macos.sh @@ -31,6 +31,4 @@ popd codesign --force --deep --sign - $BUILD/nekoray.app -#### pack dmg ### -sudo npm install -g appdmg -appdmg appdmg.json $DEST/nekoray.dmg \ No newline at end of file +mv $BUILD/nekoray.app $DEST \ No newline at end of file diff --git a/main/NekoGui.cpp b/main/NekoGui.cpp index 8dc3ac5..d52eb84 100644 --- a/main/NekoGui.cpp +++ b/main/NekoGui.cpp @@ -407,19 +407,15 @@ namespace NekoGui { short isAdminCache = -1; // IsAdmin 主要判断:有无权限启动 Tun - bool IsAdmin() { - if (isAdminCache >= 0) return isAdminCache; + bool IsAdmin(bool forceRenew) { + if (isAdminCache >= 0 && !forceRenew) return isAdminCache; bool admin = false; #ifdef Q_OS_WIN admin = Windows_IsInAdmin(); -#endif -#ifdef Q_OS_LINUX +#else admin = QFileInfo(FindNekoBoxCoreRealPath()).groupId() == 0; #endif -#ifdef Q_OS_MACOS - admin = geteuid() == 0; -#endif isAdminCache = admin; return admin; diff --git a/main/NekoGui.hpp b/main/NekoGui.hpp index d8e95dd..9fd53be 100644 --- a/main/NekoGui.hpp +++ b/main/NekoGui.hpp @@ -14,7 +14,7 @@ namespace NekoGui { QString FindNekoBoxCoreRealPath(); - bool IsAdmin(); + bool IsAdmin(bool forceRenew=false); QString GetBasePath(); diff --git a/sys/ExternalProcess.cpp b/sys/ExternalProcess.cpp index ca6bcfb..d05065f 100644 --- a/sys/ExternalProcess.cpp +++ b/sys/ExternalProcess.cpp @@ -53,7 +53,6 @@ namespace NekoGui_sys { } QProcess::setEnvironment(env); - QProcess::start(program, arguments); } diff --git a/sys/macos/MacOS.cpp b/sys/macos/MacOS.cpp new file mode 100644 index 0000000..89a4396 --- /dev/null +++ b/sys/macos/MacOS.cpp @@ -0,0 +1,9 @@ +#include +#include +#include +#include
+ +int Mac_Run_Command(QString command) { + auto cmd = QString("osascript -e 'tell application \"Terminal\" to activate' -e 'tell application \"Terminal\" to do script \"%1; exit;\"' with administrator privileges").arg(command); + return system(cmd.toStdString().c_str()); +} diff --git a/sys/macos/MacOS.h b/sys/macos/MacOS.h new file mode 100644 index 0000000..ef322b6 --- /dev/null +++ b/sys/macos/MacOS.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +int Mac_Run_Command(QString command); \ No newline at end of file diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 0707af5..25f11ef 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -46,6 +46,8 @@ #include #include
+#include "sys/macos/MacOS.h" + void UI_InitMainWindow() { mainwindow = new MainWindow; } @@ -764,9 +766,33 @@ bool MainWindow::get_elevated_permissions(int reason) { #endif #ifdef Q_OS_MACOS - MessageBoxWarning("Need administrator privilege", "Enabling TUN mode requires elevated privileges, please run Nekoray as root."); + if (NekoGui::IsAdmin(true)) + { + this->exit_reason = reason; + on_menu_exit_triggered(); + return false; + } + auto n = QMessageBox::warning(GetMessageBoxParent(), software_name, tr("Please give the core root privileges"), QMessageBox::Yes | QMessageBox::No); + if (n == QMessageBox::Yes) + { + auto chmodCommand = QString("chmod u+s " + NekoGui::FindNekoBoxCoreRealPath()); + auto ret = Mac_Run_Command(chmodCommand); + if (ret != 0) + { + MW_show_log(QString("Failed to run %1 with code %2").arg(chmodCommand).arg(ret)); + return false; + } + auto chownCommand = QString("sudo chown root:wheel " + NekoGui::FindNekoBoxCoreRealPath()); + ret = Mac_Run_Command(chownCommand); + if (ret == 0) { + MessageBoxInfo(tr("Requesting permission"), tr("Please Enter your password in the opened terminals, then try again")); + return false; + } else { + MW_show_log(QString("Failed to run %1 with %2").arg(chownCommand).arg(ret)); + return false; + } + } #endif - return false; }