File tree 4 files changed +26
-0
lines changed
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")
163
163
set (QC_UTIL_SOURCES ${QC_UTIL_SOURCES}
164
164
util/mousetap/cocoamousetap.h
165
165
util/mousetap/cocoamousetap.mm
166
+ util/path .h
167
+ util/path .mm
166
168
)
167
169
endif ()
168
170
source_group (util FILES ${QC_UTIL_SOURCES} )
Original file line number Diff line number Diff line change 4
4
#include < QDebug>
5
5
6
6
#include " config.h"
7
+ #ifdef Q_OS_OSX
8
+ #include " path.h"
9
+ #endif
7
10
8
11
#define GROUP_COMMON " common"
9
12
@@ -125,7 +128,15 @@ const QString &Config::getConfigPath()
125
128
QFileInfo fileInfo (s_configPath);
126
129
if (s_configPath.isEmpty () || !fileInfo.isDir ()) {
127
130
// 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
128
138
s_configPath = " config" ;
139
+ #endif
129
140
}
130
141
}
131
142
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