File tree Expand file tree Collapse file tree 4 files changed +26
-0
lines changed Expand file tree Collapse file tree 4 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -163,6 +163,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
163163 set (QC_UTIL_SOURCES ${QC_UTIL_SOURCES}
164164 util/mousetap/cocoamousetap.h
165165 util/mousetap/cocoamousetap.mm
166+ util/path .h
167+ util/path .mm
166168 )
167169endif ()
168170source_group (util FILES ${QC_UTIL_SOURCES} )
Original file line number Diff line number Diff line change 44#include < QDebug>
55
66#include " config.h"
7+ #ifdef Q_OS_OSX
8+ #include " path.h"
9+ #endif
710
811#define GROUP_COMMON " common"
912
@@ -125,7 +128,15 @@ const QString &Config::getConfigPath()
125128 QFileInfo fileInfo (s_configPath);
126129 if (s_configPath.isEmpty () || !fileInfo.isDir ()) {
127130 // default application dir
131+ // mac系统当从finder打开app时,默认工作目录不再是可执行程序的目录了,而是"/"
132+ // 而Qt的获取工作目录的api都依赖QCoreApplication的初始化,所以使用mac api获取当前目录
133+ #ifdef Q_OS_OSX
134+ // get */QtScrcpy.app path
135+ s_configPath = Path::GetCurrentPath ();
136+ s_configPath += " /Contents/MacOS/config" ;
137+ #else
128138 s_configPath = " config" ;
139+ #endif
129140 }
130141 }
131142 return s_configPath;
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ class Path {
4+ public:
5+ static const char * GetCurrentPath ();
6+ };
Original file line number Diff line number Diff line change 1+ #include " path.h"
2+
3+ #import < Cocoa/Cocoa.h>
4+
5+ const char * Path::GetCurrentPath () {
6+ return [[[NSBundle mainBundle ] bundlePath ] UTF8String ];
7+ }
You can’t perform that action at this time.
0 commit comments