diff --git a/QtScrcpy/CMakeLists.txt b/QtScrcpy/CMakeLists.txt index deeb394..e2fbca4 100755 --- a/QtScrcpy/CMakeLists.txt +++ b/QtScrcpy/CMakeLists.txt @@ -163,6 +163,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(QC_UTIL_SOURCES ${QC_UTIL_SOURCES} util/mousetap/cocoamousetap.h util/mousetap/cocoamousetap.mm + util/path.h + util/path.mm ) endif() source_group(util FILES ${QC_UTIL_SOURCES}) diff --git a/QtScrcpy/util/config.cpp b/QtScrcpy/util/config.cpp index 7f16171..49eeb2a 100644 --- a/QtScrcpy/util/config.cpp +++ b/QtScrcpy/util/config.cpp @@ -4,6 +4,9 @@ #include #include "config.h" +#ifdef Q_OS_OSX +#include "path.h" +#endif #define GROUP_COMMON "common" @@ -125,7 +128,15 @@ const QString &Config::getConfigPath() QFileInfo fileInfo(s_configPath); if (s_configPath.isEmpty() || !fileInfo.isDir()) { // default application dir + // mac系统当从finder打开app时,默认工作目录不再是可执行程序的目录了,而是"/" + // 而Qt的获取工作目录的api都依赖QCoreApplication的初始化,所以使用mac api获取当前目录 +#ifdef Q_OS_OSX + // get */QtScrcpy.app path + s_configPath = Path::GetCurrentPath(); + s_configPath += "/Contents/MacOS/config"; +#else s_configPath = "config"; +#endif } } return s_configPath; diff --git a/QtScrcpy/util/path.h b/QtScrcpy/util/path.h new file mode 100644 index 0000000..f8c9071 --- /dev/null +++ b/QtScrcpy/util/path.h @@ -0,0 +1,6 @@ +#pragma once + +class Path { +public: + static const char* GetCurrentPath(); +}; diff --git a/QtScrcpy/util/path.mm b/QtScrcpy/util/path.mm new file mode 100644 index 0000000..ee7e2b8 --- /dev/null +++ b/QtScrcpy/util/path.mm @@ -0,0 +1,7 @@ +#include "path.h" + +#import + +const char* Path::GetCurrentPath() { + return [[[NSBundle mainBundle] bundlePath] UTF8String]; +}